make the api a touch more useful

This commit is contained in:
Ted Unangst 2019-11-10 19:33:40 -05:00
parent e165a7877c
commit 3ed61ab9bf
1 changed files with 12 additions and 4 deletions

14
web.go
View File

@ -1317,8 +1317,12 @@ func canedithonk(user *WhatAbout, honk *Honk) bool {
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,8 +1587,12 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
go honkworldwide(user, honk)
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) {
userinfo := login.GetUserInfo(r)
@ -2034,7 +2042,7 @@ func apihandler(w http.ResponseWriter, r *http.Request) {
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 @@ func serve() {
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)))