all repos — honk @ 9c41d372a392c2d6195ef4a32c7c244869282e90

my fork of honk

i think this is enough for image descriptions
Ted Unangst tedu@tedunangst.com
Mon, 09 Sep 2019 09:55:04 -0400
commit

9c41d372a392c2d6195ef4a32c7c244869282e90

parent

d849697b9bc210110bc9d293960bfb374e44d2a5

8 files changed, 43 insertions(+), 21 deletions(-)

jump to
M activity.goactivity.go

@@ -123,7 +123,7 @@ Timeout: timeout,

}) } -func savedonk(url string, name, media string, localize bool) *Donk { +func savedonk(url string, name, desc, media string, localize bool) *Donk { if url == "" { return nil }

@@ -173,7 +173,7 @@ data = []byte{}

} } saveit: - res, err := stmtSaveFile.Exec(xid, name, url, media, localize, data) + res, err := stmtSaveFile.Exec(xid, name, desc, url, media, localize, data) if err != nil { log.Printf("error saving file %s: %s", url, err) return nil

@@ -641,6 +641,11 @@ at, _ := att.GetString("type")

mt, _ := att.GetString("mediaType") u, _ := att.GetString("url") name, _ := att.GetString("name") + desc, _ := att.GetString("summary") + log.Printf("att: %s %s %s", name, desc, u) + if desc == "" { + desc = name + } localize := false if i > 4 { log.Printf("excessive attachment: %s", at)

@@ -653,7 +658,8 @@ }

} else { log.Printf("unknown attachment: %s", at) } - donk := savedonk(u, name, mt, localize) + log.Printf("saving a donk: %s is %s", name, desc) + donk := savedonk(u, name, desc, mt, localize) if donk != nil { xonk.Donks = append(xonk.Donks, donk) }

@@ -666,6 +672,10 @@ continue

} tt, _ := tag.GetString("type") name, _ := tag.GetString("name") + desc, _ := tag.GetString("summary") + if desc == "" { + desc = name + } if tt == "Emoji" { icon, _ := tag.GetMap("icon") mt, _ := icon.GetString("mediaType")

@@ -673,7 +683,7 @@ if mt == "" {

mt = "image/png" } u, _ := icon.GetString("url") - donk := savedonk(u, name, mt, true) + donk := savedonk(u, name, desc, mt, true) if donk != nil { xonk.Donks = append(xonk.Donks, donk) }

@@ -890,6 +900,7 @@ }

jd := junk.New() jd["mediaType"] = d.Media jd["name"] = d.Name + jd["summary"] = d.Desc jd["type"] = "Document" jd["url"] = d.URL atts = append(atts, jd)
M docs/changelog.txtdocs/changelog.txt

@@ -2,6 +2,8 @@ changelog

-- next ++ Image descriptions. + ++ Search. I hate it already. + Unbonking.
M honk.gohonk.go

@@ -99,6 +99,7 @@ type Donk struct {

FileID int64 XID string Name string + Desc string URL string Media string Local bool

@@ -979,7 +980,7 @@ for _, h := range honks {

ids = append(ids, fmt.Sprintf("%d", h.ID)) hmap[h.ID] = h } - q := fmt.Sprintf("select honkid, donks.fileid, xid, name, url, media, local from donks join files on donks.fileid = files.fileid where honkid in (%s)", strings.Join(ids, ",")) + q := fmt.Sprintf("select honkid, donks.fileid, xid, name, description, url, media, local from donks join files on donks.fileid = files.fileid where honkid in (%s)", strings.Join(ids, ",")) rows, err := db.Query(q) if err != nil { log.Printf("error querying donks: %s", err)

@@ -989,7 +990,7 @@ defer rows.Close()

for rows.Next() { var hid int64 var d Donk - err = rows.Scan(&hid, &d.FileID, &d.XID, &d.Name, &d.URL, &d.Media, &d.Local) + err = rows.Scan(&hid, &d.FileID, &d.XID, &d.Name, &d.Desc, &d.URL, &d.Media, &d.Local) if err != nil { log.Printf("error scanning donk: %s", err) continue

@@ -1273,19 +1274,15 @@ name = xid + ".txt"

} xid += ".txt" } + desc := r.FormValue("donkdesc") url := fmt.Sprintf("https://%s/d/%s", serverName, xid) - res, err := stmtSaveFile.Exec(xid, name, url, media, 1, data) + res, err := stmtSaveFile.Exec(xid, name, desc, url, media, 1, data) if err != nil { log.Printf("unable to save image: %s", err) return } var d Donk d.FileID, _ = res.LastInsertId() - d.XID = name - d.Name = name - d.Media = media - d.URL = url - d.Local = true honk.Donks = append(honk.Donks, &d) donkxid = d.XID }

@@ -1296,9 +1293,6 @@ var donk Donk

row := stmtFindFile.QueryRow(url) err := row.Scan(&donk.FileID) if err == nil { - donk.XID = xid - donk.Local = true - donk.URL = url honk.Donks = append(honk.Donks, &donk) } else { log.Printf("can't find file: %s", xid)

@@ -1306,7 +1300,7 @@ }

} herd := herdofemus(honk.Noise) for _, e := range herd { - donk := savedonk(e.ID, e.Name, "image/png", true) + donk := savedonk(e.ID, e.Name, e.Name, "image/png", true) if donk != nil { donk.Name = e.Name honk.Donks = append(honk.Donks, donk)

@@ -1359,6 +1353,8 @@ if err != nil {

log.Printf("error saving ont: %s", err) } } + honk.Donks = nil + donksforhonks([]*Honk{&honk}) go honkworldwide(user, &honk)

@@ -1847,7 +1843,7 @@ stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")

stmtZonkIt = preparetodie(db, "delete from honks where honkid = ?") stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?") stmtFindFile = preparetodie(db, "select fileid from files where url = ? and local = 1") - stmtSaveFile = preparetodie(db, "insert into files (xid, name, url, media, local, content) values (?, ?, ?, ?, ?, ?)") + stmtSaveFile = preparetodie(db, "insert into files (xid, name, description, url, media, local, content) values (?, ?, ?, ?, ?, ?, ?)") stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey, options from users where username = ?") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)") stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)")
M schema.sqlschema.sql

@@ -1,7 +1,7 @@

create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer, format text, precis text, oonker text, flags integer, onts text); create table donks (honkid integer, fileid integer); -create table files(fileid integer primary key, xid text, name text, url text, media text, local integer, content blob); +create table files(fileid integer primary key, xid text, name text, description text, url text, media text, local integer, content blob); create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text); create table xonkers (xonkerid integer primary key, name text, info text, flavor text); create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text);
M upgradedb.goupgradedb.go

@@ -184,6 +184,11 @@ }

doordie(db, "update config set value = 16 where key = 'dbversion'") fallthrough case 16: + doordie(db, "alter table files add column description text") + doordie(db, "update files set description = name") + doordie(db, "update config set value = 17 where key = 'dbversion'") + fallthrough + case 17: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -72,7 +72,7 @@

var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 16 +var myVersion = 17 func initdb() { schema, err := ioutil.ReadFile("schema.sql")
M views/honk.htmlviews/honk.html

@@ -47,7 +47,7 @@ {{ if .Local }}

{{ if eq .Media "text/plain" }} <p><a href="/d/{{ .XID }}">Attachment: {{ .Name }}</a> {{ else }} -<p><a href="/d/{{ .XID }}"><img src="/d/{{ .XID }}" title="{{ .URL }}"></a> +<p><a href="/d/{{ .XID }}"><img src="/d/{{ .XID }}" title="{{ .Desc }}"></a> {{ end }} {{ else }} {{ if .XID }}

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

{{ if eq .Media "video/mp4" }} <p><a href="{{ .URL }}"><video controls src="{{ .URL }}">{{ .Name }}</video></a> {{ else }} -<p><a href="{{ .URL }}"><img src="{{ .URL }}" title="{{ .Name }}"></a> +<p><a href="{{ .URL }}"><img src="{{ .URL }}" title="{{ .Desc }}"></a> {{ end }} {{ end }} {{ end }}
M views/honkform.htmlviews/honkform.html

@@ -7,6 +7,8 @@ <input type="hidden" name="CSRF" value="{{ .HonkCSRF }}">

<p> <label id="donker">attach: {{ if .SavedFile }} {{ .SavedFile }} {{ else }} <input onchange="updatedonker();" type="file" name="donk"><span></span> {{ end }}</label> <input type="hidden" name="donkxid" value="{{ .SavedFile }}"> +<p id="donkdescriptor"> +description: <input type="text" name="donkdesc" value="{{ .DonkDesc }}" autocomplete=off> <p> <textarea name="noise" id="honknoise">{{ .Noise }}</textarea> <p>

@@ -14,6 +16,10 @@ <input type="submit" value="it's gonna be honked">

<input type="submit" name="preview" value="preview"> </form> <script> +(function() { + var el = document.getElementById("donkdescriptor") + el.style.display = "none" +})(); function showhonkform(elem, rid, hname) { var form = document.getElementById("honkform") form.style = "display: block"

@@ -35,5 +41,7 @@ }

function updatedonker() { var el = document.getElementById("donker") el.children[1].textContent = el.children[0].value.slice(-20) + var el = document.getElementById("donkdescriptor") + el.style.display = "" } </script>