m
Ted Unangst tedu@tedunangst.com
Tue, 03 May 2022 15:20:34 -0400
6 files changed,
121 insertions(+),
45 deletions(-)
M
database.go
→
database.go
@@ -972,6 +972,52 @@ func savexonker(what, value, flav, when string) {
stmtSaveXonker.Exec(what, value, flav, when) } +func savehonker(user *WhatAbout, url, name, flavor, combos, mj string) error { + var owner string + if url[0] == '#' { + flavor = "peep" + if name == "" { + name = url[1:] + } + owner = url + } else { + info, err := investigate(url) + if err != nil { + ilog.Printf("failed to investigate honker: %s", err) + return err + } + url = info.XID + if name == "" { + name = info.Name + } + owner = info.Owner + } + + var x string + db := opendatabase() + row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, user.ID) + err := row.Scan(&x) + if err != sql.ErrNoRows { + if err != nil { + elog.Printf("honker scan err: %s", err) + } else { + err = fmt.Errorf("it seems you are already subscribed to them") + } + return err + } + + res, err := stmtSaveHonker.Exec(user.ID, name, url, flavor, combos, owner, mj) + if err != nil { + elog.Print(err) + return err + } + honkerid, _ := res.LastInsertId() + if flavor == "presub" { + followyou(user, honkerid) + } + return nil +} + func cleanupdb(arg string) { db := opendatabase() days, err := strconv.Atoi(arg)
M
docs/changelog.txt
→
docs/changelog.txt
@@ -1,5 +1,19 @@
changelog +=== next + ++ Add atme class to mentions + ++ Improvements to the mastodon importer. + ++ More hydration capable pages. + ++ Support for local.js. + ++ Better error messages for timeouts. + ++ Some improved html and markdown. + === 0.9.7 Witless Weekender +++ Word guessing game. Wonk wonk!
M
import.go
→
import.go
@@ -16,6 +16,7 @@
package main import ( + "encoding/csv" "encoding/json" "fmt" "html"@@ -69,6 +70,20 @@ user, err := butwhatabout(username)
if err != nil { elog.Fatal(err) } + + if _, err := os.Stat(source + "/outbox.json"); err == nil { + importMastotoots(user, source) + } else { + ilog.Printf("skipping outbox.json!") + } + if _, err := os.Stat(source + "/following_accounts.csv"); err == nil { + importMastotooters(user, source) + } else { + ilog.Printf("skipping following_accounts.csv!") + } +} + +func importMastotoots(user *WhatAbout, source string) { type Toot struct { Id string Type string@@ -79,6 +94,7 @@ }
var outbox struct { OrderedItems []Toot } + ilog.Println("Importing honks...") fd, err := os.Open(source + "/outbox.json") if err != nil { elog.Fatal(err)@@ -166,6 +182,37 @@ honk.Onts = append(honk.Onts, t.Name)
} } savehonk(&honk) + } +} + +func importMastotooters(user *WhatAbout, source string) { + ilog.Println("Importing honkers...") + fd, err := os.Open(source + "/following_accounts.csv") + if err != nil { + elog.Fatal(err) + } + r := csv.NewReader(fd) + data, err := r.ReadAll() + if err != nil { + elog.Fatal(err) + } + fd.Close() + + var meta HonkerMeta + mj, _ := jsonify(&meta) + + for i, d := range data { + if i == 0 { + continue + } + url := "@" + d[0] + name := "" + flavor := "peep" + combos := "" + err := savehonker(user, url, name, flavor, combos, mj) + if err != nil { + elog.Printf("trouble with a honker: %s", err) + } } }
M
views/honkpage.js
→
views/honkpage.js
@@ -148,6 +148,8 @@ } else if (name == "combo") {
args["c"] = arg } else if (name == "honker") { args["xid"] = arg + } else if (name == "user") { + args["uname"] = arg } return args }
M
web.go
→
web.go
@@ -712,6 +712,8 @@ }
u := login.GetUserInfo(r) honks := gethonksbyuser(name, u != nil && u.Username == name, 0) templinfo := getInfo(r) + templinfo["PageName"] = "user" + templinfo["PageArg"] = name templinfo["Name"] = user.Name templinfo["WhatAbout"] = user.HTAbout templinfo["ServerMessage"] = ""@@ -1921,53 +1923,12 @@ if peep == "peep" {
flavor = "peep" } - if url[0] == '#' { - flavor = "peep" - if name == "" { - name = url[1:] - } - _, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, url, mj) - if err != nil { - elog.Print(err) - return - } - http.Redirect(w, r, "/honkers", http.StatusSeeOther) - return - } - - info, err := investigate(url) + err := savehonker(user, url, name, flavor, combos, mj) if err != nil { - http.Error(w, "error investigating: "+err.Error(), http.StatusInternalServerError) - ilog.Printf("failed to investigate honker: %s", err) + http.Error(w, "had some trouble with that: "+err.Error(), http.StatusInternalServerError) return } - url = info.XID - if name == "" { - name = info.Name - } - - var x string - db := opendatabase() - row := db.QueryRow("select xid from honkers where xid = ? and userid = ? and flavor in ('sub', 'unsub', 'peep')", url, u.UserID) - err = row.Scan(&x) - if err != sql.ErrNoRows { - http.Error(w, "it seems you are already subscribed to them", http.StatusInternalServerError) - if err != nil { - elog.Printf("honker scan err: %s", err) - } - return - } - - res, err := stmtSaveHonker.Exec(u.UserID, name, url, flavor, combos, info.Owner, mj) - if err != nil { - elog.Print(err) - return - } - honkerid, _ = res.LastInsertId() - if flavor == "presub" { - followyou(user, honkerid) - } http.Redirect(w, r, "/honkers", http.StatusSeeOther) }@@ -2272,6 +2233,10 @@ <button tabindex=1 name="add honker" value="add honker">add honker</button>
</form>`, login.GetCSRF("submithonker", r), xid) msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>%s`, xid, xid, miniform) hydra.Srvmsg = msg + case "user": + uname := r.FormValue("uname") + honks = gethonksbyuser(uname, u != nil && u.Username == uname, wanted) + hydra.Srvmsg = templates.Sprintf("honks by user: %s", uname) default: http.NotFound(w, r) }@@ -2395,8 +2360,7 @@ var workinprogress = 0
func enditall() { sig := make(chan os.Signal) - signal.Notify(sig, os.Interrupt) - signal.Notify(sig, syscall.SIGTERM) + signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) <-sig ilog.Printf("stopping...") for i := 0; i < workinprogress; i++ {