This commit is contained in:
commit
64329252e9
46
database.go
46
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)
|
||||
|
|
|
@ -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!
|
||||
|
|
3
fun.go
3
fun.go
|
@ -73,6 +73,9 @@ func reverbolate(userid int64, honks []*Honk) {
|
|||
if !h.Public {
|
||||
h.Style += " limited"
|
||||
}
|
||||
if h.Whofore == 1 {
|
||||
h.Style += " atme"
|
||||
}
|
||||
translate(h)
|
||||
local := false
|
||||
if h.Whofore == 2 || h.Whofore == 3 {
|
||||
|
|
47
import.go
47
import.go
|
@ -16,6 +16,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
|
@ -69,6 +70,20 @@ func importMastodon(username, source string) {
|
|||
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 @@ func importMastodon(username, source string) {
|
|||
var outbox struct {
|
||||
OrderedItems []Toot
|
||||
}
|
||||
ilog.Println("Importing honks...")
|
||||
fd, err := os.Open(source + "/outbox.json")
|
||||
if err != nil {
|
||||
elog.Fatal(err)
|
||||
|
@ -169,6 +185,37 @@ func importMastodon(username, source string) {
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func importTwitter(username, source string) {
|
||||
user, err := butwhatabout(username)
|
||||
if err != nil {
|
||||
|
|
|
@ -148,6 +148,8 @@ function hydrargs() {
|
|||
args["c"] = arg
|
||||
} else if (name == "honker") {
|
||||
args["xid"] = arg
|
||||
} else if (name == "user") {
|
||||
args["uname"] = arg
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
|
54
web.go
54
web.go
|
@ -712,6 +712,8 @@ func showuser(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
|
|||
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)
|
||||
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)
|
||||
}
|
||||
http.Error(w, "had some trouble with that: "+err.Error(), http.StatusInternalServerError)
|
||||
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 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
|
|||
</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++ {
|
||||
|
|
Loading…
Reference in New Issue