From fc908fb04da88ba8a40afb9fd7d421d96d8c536d Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 13 Mar 2016 22:00:22 -0400 Subject: [PATCH] Added self-destructing messages https://github.com/schollz/awwkoala/issues/30 Former-commit-id: 85c1bb9080d38319a177c5a3280bf787646cdbb6 [formerly 031b62247892aeb88767ace1da5c46fdc956ff55] [formerly 33bfd5df1c8da72cb068ace2bdb6cae78b4410aa [formerly 0b8a2737fc0034de6cc9c6ec8a16e5f724aa25c0 [formerly 7fb8834284dfb150f582277a76ee9f280068dc5b]]] Former-commit-id: 90290f5a2f51a52ec71491baba14d4211462be0a [formerly 032a61675ff8bf3c6b61b26021ab71ac62ca6e3e] Former-commit-id: 6897a2246cee59b67abf36999c300763341d2ae2 Former-commit-id: e0ec6ba8102c196d855302c2367549566f9493f8 --- routes.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/routes.go b/routes.go index dc9f875..c6bce93 100644 --- a/routes.go +++ b/routes.go @@ -39,6 +39,9 @@ func editNote(c *gin.Context) { version := c.DefaultQuery("version", "-1") versionNum, _ := strconv.Atoi(version) currentText, versions, currentVersion, totalTime := getCurrentText(title, versionNum) + if strings.Contains(currentText, "self-destruct\n") || strings.Contains(currentText, "\nself-destruct") { + c.Redirect(302, "/"+title+"/view") + } numRows := len(strings.Split(currentText, "\n")) + 10 if currentVersion { c.HTML(http.StatusOK, "index.tmpl", gin.H{ @@ -79,6 +82,12 @@ func everythingElse(c *gin.Context) { versionNum = -1 } currentText, versions, _, totalTime := getCurrentText(title, versionNum) + if (strings.Contains(currentText, "self-destruct\n") || strings.Contains(currentText, "\nself-destruct")) && strings.ToLower(title) != "about" { + currentText = strings.Replace(currentText, "self-destruct\n", `> *This page has been deleted, you cannot return after closing.*`+"\n", 1) + currentText = strings.Replace(currentText, "\nself-destruct", "\n"+`> *This page has been deleted, you cannot return after closing.*`, 1) + p := WikiData{strings.ToLower(title), "", []string{}, []string{}} + p.save("") + } renderMarkdown(c, currentText, title, versions, "", totalTime) } else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 { renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now())) @@ -201,7 +210,11 @@ func renderList(c *gin.Context, title string) { panic(err) } - fmt.Println(p.CurrentText) + currentText := p.CurrentText + if strings.Contains(currentText, "self-destruct\n") || strings.Contains(currentText, "\nself-destruct") { + c.Redirect(302, "/"+title+"/view") + } + pClean := bluemonday.UGCPolicy() pClean.AllowElements("img") pClean.AllowAttrs("alt").OnElements("img")