all repos — honk @ 03280d3bf4b7bf6fa09f5a681d2e30b56fde8cd0

my fork of honk

API access for honkers.
Ted Unangst tedu@tedunangst.com
Sun, 19 Feb 2023 17:46:59 -0500
commit

03280d3bf4b7bf6fa09f5a681d2e30b56fde8cd0

parent

3c8909e9f0a2a3e46852effcbc3a3bebb2a10ef0

4 files changed, 64 insertions(+), 22 deletions(-)

jump to
M database.godatabase.go

@@ -962,7 +962,7 @@ func savexonker(what, value, flav, when string) {

stmtSaveXonker.Exec(what, value, flav, when) } -func savehonker(user *WhatAbout, url, name, flavor, combos, mj string) error { +func savehonker(user *WhatAbout, url, name, flavor, combos, mj string) (int64, error) { var owner string if url[0] == '#' { flavor = "peep"

@@ -974,7 +974,7 @@ } else {

info, err := investigate(url) if err != nil { ilog.Printf("failed to investigate honker: %s", err) - return err + return 0, err } url = info.XID if name == "" {

@@ -993,19 +993,19 @@ elog.Printf("honker scan err: %s", err)

} else { err = fmt.Errorf("it seems you are already subscribed to them") } - return err + return 0, err } res, err := stmtSaveHonker.Exec(user.ID, name, url, flavor, combos, owner, mj) if err != nil { elog.Print(err) - return err + return 0, err } honkerid, _ := res.LastInsertId() if flavor == "presub" { followyou(user, honkerid) } - return nil + return honkerid, nil } func cleanupdb(arg string) {
M docs/honk.3docs/honk.3

@@ -158,6 +158,27 @@ .It zonvoy

Mute this thread. What should identify a convoy. .El +.Ss gethonkers +Returns a list of current honkers in json format. +.Ss savehonker +Save a new honker, or update an existing one. +The following fields are used. +.Bl -tag -width honkerid +.It Fa honkerid +The numeric ID of an existing honker to update. +.It Fa name +The preferred short name. +.It Fa url +The ActivityPub actor url. +.It Fa combos +Space separated list of combos. +.It Fa notes +Some notes. +.El +.Pp +The honker numeric ID will be returned for success. +To delete, unsub, or sub, include a form value with name and value equal. +As in, a form value named delete with the value delete, or unsub=unsub, etc. .Ss sendactivity Send anything. No limits, no error checking.
M import.goimport.go

@@ -210,7 +210,7 @@ url := "@" + d[0]

name := "" flavor := "peep" combos := "" - err := savehonker(user, url, name, flavor, combos, mj) + _, err := savehonker(user, url, name, flavor, combos, mj) if err != nil { elog.Printf("trouble with a honker: %s", err) }
M web.goweb.go

@@ -1563,7 +1563,7 @@ }

return d, nil } -func submitwebhonk(w http.ResponseWriter, r *http.Request) { +func websubmithonk(w http.ResponseWriter, r *http.Request) { h := submithonk(w, r) if h == nil { return

@@ -1884,7 +1884,15 @@ elog.Print(err)

} } -func submithonker(w http.ResponseWriter, r *http.Request) { +func websubmithonker(w http.ResponseWriter, r *http.Request) { + h := submithonker(w, r) + if h == nil { + return + } + http.Redirect(w, r, "/honkers", http.StatusSeeOther) +} + +func submithonker(w http.ResponseWriter, r *http.Request) *Honker { u := login.GetUserInfo(r) user, _ := butwhatabout(u.Username) name := strings.TrimSpace(r.FormValue("name"))

@@ -1897,7 +1905,7 @@

re_namecheck := regexp.MustCompile("[\\pL[:digit:]_.-]+") if name != "" && !re_namecheck.MatchString(name) { http.Error(w, "please use a plainer name", http.StatusInternalServerError) - return + return nil } var meta HonkerMeta

@@ -1906,12 +1914,16 @@ mj, _ := jsonify(&meta)

defer honkerinvalidator.Clear(u.UserID) + // mostly dummy, fill in later... + h := &Honker{ + ID: honkerid, + } + if honkerid > 0 { if r.FormValue("delete") == "delete" { unfollowyou(user, honkerid) stmtDeleteHonker.Exec(honkerid) - http.Redirect(w, r, "/honkers", http.StatusSeeOther) - return + return h } if r.FormValue("unsub") == "unsub" { unfollowyou(user, honkerid)

@@ -1922,15 +1934,14 @@ }

_, err := stmtUpdateHonker.Exec(name, combos, mj, honkerid, u.UserID) if err != nil { elog.Printf("update honker err: %s", err) - return + return nil } - http.Redirect(w, r, "/honkers", http.StatusSeeOther) - return + return h } if url == "" { http.Error(w, "subscribing to nothing?", http.StatusInternalServerError) - return + return nil } flavor := "presub"

@@ -1938,13 +1949,13 @@ if peep == "peep" {

flavor = "peep" } - err := savehonker(user, url, name, flavor, combos, mj) + id, err := savehonker(user, url, name, flavor, combos, mj) if err != nil { http.Error(w, "had some trouble with that: "+err.Error(), http.StatusInternalServerError) - return + return nil } - - http.Redirect(w, r, "/honkers", http.StatusSeeOther) + h.ID = id + return h } func hfcspage(w http.ResponseWriter, r *http.Request) {

@@ -2311,7 +2322,7 @@ h := submithonk(w, r)

if h == nil { return } - w.Write([]byte(h.XID)) + fmt.Fprintf(w, "%s", h.XID) case "donk": d, err := submitdonk(w, r) if err != nil {

@@ -2371,6 +2382,16 @@ msg := []byte(r.FormValue("msg"))

for rcpt := range rcpts { go deliverate(0, userid, rcpt, msg, true) } + case "gethonkers": + j := junk.New() + j["honkers"] = gethonkers(u.UserID) + j.Write(w) + case "savehonker": + h := submithonker(w, r) + if h == nil { + return + } + fmt.Fprintf(w, "%d", h.ID) default: http.Error(w, "unknown action", http.StatusNotFound) return

@@ -2560,7 +2581,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(submitwebhonk))) + loggedin.Handle("/honk", login.CSRFWrap("honkhonk", http.HandlerFunc(websubmithonk))) 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)))

@@ -2575,7 +2596,7 @@ loggedin.HandleFunc("/t", showconvoy)

loggedin.HandleFunc("/q", showsearch) loggedin.HandleFunc("/hydra", webhydra) loggedin.HandleFunc("/emus", showemus) - loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(submithonker))) + loggedin.Handle("/submithonker", login.CSRFWrap("submithonker", http.HandlerFunc(websubmithonker))) err = http.Serve(listener, mux) if err != nil {