save obfuscated guesses

This commit is contained in:
Ted Unangst 2022-02-12 14:58:57 -05:00
parent f8c862275e
commit bbadb7e5a0
5 changed files with 17 additions and 2 deletions

View File

@ -480,6 +480,8 @@ func donksforhonks(honks []*Honk) {
}
case "wonkles":
h.Wonkles = j
case "guesses":
h.Guesses = template.HTML(j)
case "oldrev":
default:
elog.Printf("unknown meta genus: %s", genus)
@ -896,6 +898,13 @@ func saveextras(tx *sql.Tx, h *Honk) error {
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
}
}
return nil
}

View File

@ -100,6 +100,7 @@ type Honk struct {
Mentions []Mention
Badonks []Badonk
Wonkles string
Guesses template.HTML
}
type Badonk struct {

View File

@ -92,7 +92,8 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
{{ 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 }}

View File

@ -74,7 +74,7 @@ export function makeaguess(btn) {
}
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>"
}

4
web.go
View File

@ -1304,6 +1304,10 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
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)
}