save obfuscated guesses
Ted Unangst tedu@tedunangst.com
Sat, 12 Feb 2022 14:58:57 -0500
5 files changed,
17 insertions(+),
2 deletions(-)
M
database.go
→
database.go
@@ -480,6 +480,8 @@ continue
} case "wonkles": h.Wonkles = j + case "guesses": + h.Guesses = template.HTML(j) case "oldrev": default: elog.Printf("unknown meta genus: %s", genus)@@ -893,6 +895,13 @@ if w := h.Wonkles; w != "" {
_, err := tx.Stmt(stmtSaveMeta).Exec(h.ID, "wonkles", w) if err != nil { elog.Printf("error saving wonkles: %s", err) + return err + } + } + if g := h.Guesses; g != "" { + _, err := tx.Stmt(stmtSaveMeta).Exec(h.ID, "guesses", g) + if err != nil { + elog.Printf("error saving guesses: %s", err) return err } }
M
views/honk.html
→
views/honk.html
@@ -92,7 +92,8 @@ {{ end }}
{{ if eq .Honk.What "wonked" }} <p> {{ if and $bonkcsrf .Honk.IsWonked }} -{{ .Honk.Noise }} +{{ .Honk.Guesses }} +<p>{{ .Honk.Noise }} {{ else }} <button onclick="return playit(this, '{{ .Honk.Noise }}', '{{ .Honk.Wonkles }}', '{{ .Honk.XID }}')">it's play time!</button> {{ end }}
M
views/wonk.js
→
views/wonk.js
@@ -74,7 +74,7 @@ mess += "<p>" + host.guesses[i]
} div.innerHTML = mess if (typeof(csrftoken) != "undefined") - post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "wonk", "what": host.xid})) + post("/zonkit", encode({"CSRF": csrftoken, "wherefore": "wonk", "guesses": host.guesses.join("<p>"), "what": host.xid})) } else { div.innerHTML = "<p><input> <button onclick='return makeaguess(this)'>guess</button>" }
M
web.go
→
web.go
@@ -1304,6 +1304,10 @@ if wherefore == "wonk" {
xonk := getxonk(userinfo.UserID, what) if xonk != nil { _, err := stmtUpdateFlags.Exec(flagIsWonked, xonk.ID) + if err == nil { + guesses := r.FormValue("guesses") + _, err = stmtSaveMeta.Exec(xonk.ID, "guesses", guesses) + } if err != nil { elog.Printf("error saving: %s", err) }