all repos — honk @ 46cb0e3df57390ded1bbf712fe30a38fa03be43e

my fork of honk

make the api a touch more useful
Ted Unangst tedu@tedunangst.com
Sun, 10 Nov 2019 19:33:40 -0500
commit

46cb0e3df57390ded1bbf712fe30a38fa03be43e

parent

27d30bc3be853d9ac806b4a9c640ded2096d3d16

1 files changed, 12 insertions(+), 4 deletions(-)

jump to
M web.goweb.go

@@ -1317,8 +1317,12 @@ }

return true } +func submitwebhonk(w http.ResponseWriter, r *http.Request) { + submithonk(w, r, false) +} + // what a hot mess this function is -func submithonk(w http.ResponseWriter, r *http.Request) { +func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) { rid := r.FormValue("rid") noise := r.FormValue("noise")

@@ -1583,7 +1587,11 @@ donksforhonks([]*Honk{honk})

go honkworldwide(user, honk) - http.Redirect(w, r, honk.XID[len(serverName)+8:], http.StatusSeeOther) + if isAPI { + w.Write([]byte(honk.XID)) + } else { + http.Redirect(w, r, honk.XID[len(serverName)+8:], http.StatusSeeOther) + } } func showhonkers(w http.ResponseWriter, r *http.Request) {

@@ -2034,7 +2042,7 @@ action := r.FormValue("action")

log.Printf("api request '%s' on behalf of %s", action, u.Username) switch action { case "honk": - submithonk(w, r) + submithonk(w, r, true) default: http.Error(w, "unknown action", http.StatusNotFound) }

@@ -2159,7 +2167,7 @@ loggedin.HandleFunc("/hfcs", hfcspage)

loggedin.HandleFunc("/xzone", xzone) loggedin.HandleFunc("/newhonk", newhonkpage) loggedin.HandleFunc("/edit", edithonkpage) - loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submithonk))) + loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitwebhonk))) loggedin.Handle("/bonk", login.CSRFWrap("honkhonk", http.HandlerFunc(submitbonk))) loggedin.Handle("/zonkit", login.CSRFWrap("honkhonk", http.HandlerFunc(zonkit))) loggedin.Handle("/savehfcs", login.CSRFWrap("filter", http.HandlerFunc(savehfcs)))