i think this is enough for image descriptions

This commit is contained in:
Ted Unangst 2019-09-09 09:55:04 -04:00
parent c597677905
commit ead0b2995e
8 changed files with 43 additions and 21 deletions

View File

@ -123,7 +123,7 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
}) })
} }
func savedonk(url string, name, media string, localize bool) *Donk { func savedonk(url string, name, desc, media string, localize bool) *Donk {
if url == "" { if url == "" {
return nil return nil
} }
@ -173,7 +173,7 @@ func savedonk(url string, name, media string, localize bool) *Donk {
} }
} }
saveit: 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 { if err != nil {
log.Printf("error saving file %s: %s", url, err) log.Printf("error saving file %s: %s", url, err)
return nil return nil
@ -641,6 +641,11 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
mt, _ := att.GetString("mediaType") mt, _ := att.GetString("mediaType")
u, _ := att.GetString("url") u, _ := att.GetString("url")
name, _ := att.GetString("name") name, _ := att.GetString("name")
desc, _ := att.GetString("summary")
log.Printf("att: %s %s %s", name, desc, u)
if desc == "" {
desc = name
}
localize := false localize := false
if i > 4 { if i > 4 {
log.Printf("excessive attachment: %s", at) log.Printf("excessive attachment: %s", at)
@ -653,7 +658,8 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
} else { } else {
log.Printf("unknown attachment: %s", at) 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 { if donk != nil {
xonk.Donks = append(xonk.Donks, donk) xonk.Donks = append(xonk.Donks, donk)
} }
@ -666,6 +672,10 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
} }
tt, _ := tag.GetString("type") tt, _ := tag.GetString("type")
name, _ := tag.GetString("name") name, _ := tag.GetString("name")
desc, _ := tag.GetString("summary")
if desc == "" {
desc = name
}
if tt == "Emoji" { if tt == "Emoji" {
icon, _ := tag.GetMap("icon") icon, _ := tag.GetMap("icon")
mt, _ := icon.GetString("mediaType") mt, _ := icon.GetString("mediaType")
@ -673,7 +683,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
mt = "image/png" mt = "image/png"
} }
u, _ := icon.GetString("url") u, _ := icon.GetString("url")
donk := savedonk(u, name, mt, true) donk := savedonk(u, name, desc, mt, true)
if donk != nil { if donk != nil {
xonk.Donks = append(xonk.Donks, donk) xonk.Donks = append(xonk.Donks, donk)
} }
@ -890,6 +900,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
jd := junk.New() jd := junk.New()
jd["mediaType"] = d.Media jd["mediaType"] = d.Media
jd["name"] = d.Name jd["name"] = d.Name
jd["summary"] = d.Desc
jd["type"] = "Document" jd["type"] = "Document"
jd["url"] = d.URL jd["url"] = d.URL
atts = append(atts, jd) atts = append(atts, jd)

View File

@ -2,6 +2,8 @@ changelog
-- next -- next
+ Image descriptions.
++ Search. I hate it already. ++ Search. I hate it already.
+ Unbonking. + Unbonking.

22
honk.go
View File

@ -99,6 +99,7 @@ type Donk struct {
FileID int64 FileID int64
XID string XID string
Name string Name string
Desc string
URL string URL string
Media string Media string
Local bool Local bool
@ -979,7 +980,7 @@ func donksforhonks(honks []*Honk) {
ids = append(ids, fmt.Sprintf("%d", h.ID)) ids = append(ids, fmt.Sprintf("%d", h.ID))
hmap[h.ID] = h 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) rows, err := db.Query(q)
if err != nil { if err != nil {
log.Printf("error querying donks: %s", err) log.Printf("error querying donks: %s", err)
@ -989,7 +990,7 @@ func donksforhonks(honks []*Honk) {
for rows.Next() { for rows.Next() {
var hid int64 var hid int64
var d Donk 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 { if err != nil {
log.Printf("error scanning donk: %s", err) log.Printf("error scanning donk: %s", err)
continue continue
@ -1273,19 +1274,15 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
} }
xid += ".txt" xid += ".txt"
} }
desc := r.FormValue("donkdesc")
url := fmt.Sprintf("https://%s/d/%s", serverName, xid) 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 { if err != nil {
log.Printf("unable to save image: %s", err) log.Printf("unable to save image: %s", err)
return return
} }
var d Donk var d Donk
d.FileID, _ = res.LastInsertId() 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) honk.Donks = append(honk.Donks, &d)
donkxid = d.XID donkxid = d.XID
} }
@ -1296,9 +1293,6 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
row := stmtFindFile.QueryRow(url) row := stmtFindFile.QueryRow(url)
err := row.Scan(&donk.FileID) err := row.Scan(&donk.FileID)
if err == nil { if err == nil {
donk.XID = xid
donk.Local = true
donk.URL = url
honk.Donks = append(honk.Donks, &donk) honk.Donks = append(honk.Donks, &donk)
} else { } else {
log.Printf("can't find file: %s", xid) log.Printf("can't find file: %s", xid)
@ -1306,7 +1300,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
} }
herd := herdofemus(honk.Noise) herd := herdofemus(honk.Noise)
for _, e := range herd { 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 { if donk != nil {
donk.Name = e.Name donk.Name = e.Name
honk.Donks = append(honk.Donks, donk) honk.Donks = append(honk.Donks, donk)
@ -1359,6 +1353,8 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
log.Printf("error saving ont: %s", err) log.Printf("error saving ont: %s", err)
} }
} }
honk.Donks = nil
donksforhonks([]*Honk{&honk})
go honkworldwide(user, &honk) go honkworldwide(user, &honk)
@ -1847,7 +1843,7 @@ func prepareStatements(db *sql.DB) {
stmtZonkIt = preparetodie(db, "delete from honks where honkid = ?") stmtZonkIt = preparetodie(db, "delete from honks where honkid = ?")
stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?") stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?")
stmtFindFile = preparetodie(db, "select fileid from files where url = ? and local = 1") 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 = ?") 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 (?, ?, ?, ?)") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)")
stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)") stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)")

View File

@ -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 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 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 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 xonkers (xonkerid integer primary key, name text, info text, flavor text);
create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text); create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text);

View File

@ -184,6 +184,11 @@ func upgradedb() {
doordie(db, "update config set value = 16 where key = 'dbversion'") doordie(db, "update config set value = 16 where key = 'dbversion'")
fallthrough fallthrough
case 16: 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: default:
log.Fatalf("can't upgrade unknown version %d", dbversion) log.Fatalf("can't upgrade unknown version %d", dbversion)
} }

View File

@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05"
var alreadyopendb *sql.DB var alreadyopendb *sql.DB
var dbname = "honk.db" var dbname = "honk.db"
var stmtConfig *sql.Stmt var stmtConfig *sql.Stmt
var myVersion = 16 var myVersion = 17
func initdb() { func initdb() {
schema, err := ioutil.ReadFile("schema.sql") schema, err := ioutil.ReadFile("schema.sql")

View File

@ -47,7 +47,7 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
{{ if eq .Media "text/plain" }} {{ if eq .Media "text/plain" }}
<p><a href="/d/{{ .XID }}">Attachment: {{ .Name }}</a> <p><a href="/d/{{ .XID }}">Attachment: {{ .Name }}</a>
{{ else }} {{ 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 }} {{ end }}
{{ else }} {{ else }}
{{ if .XID }} {{ if .XID }}
@ -56,7 +56,7 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
{{ if eq .Media "video/mp4" }} {{ if eq .Media "video/mp4" }}
<p><a href="{{ .URL }}"><video controls src="{{ .URL }}">{{ .Name }}</video></a> <p><a href="{{ .URL }}"><video controls src="{{ .URL }}">{{ .Name }}</video></a>
{{ else }} {{ else }}
<p><a href="{{ .URL }}"><img src="{{ .URL }}" title="{{ .Name }}"></a> <p><a href="{{ .URL }}"><img src="{{ .URL }}" title="{{ .Desc }}"></a>
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -7,6 +7,8 @@ in reply to: <input type="text" name="rid" id="ridinput" value="{{ .InReplyTo }}
<p> <p>
<label id="donker">attach: {{ if .SavedFile }} {{ .SavedFile }} {{ else }} <input onchange="updatedonker();" type="file" name="donk"><span></span> {{ end }}</label> <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 }}"> <input type="hidden" name="donkxid" value="{{ .SavedFile }}">
<p id="donkdescriptor">
description: <input type="text" name="donkdesc" value="{{ .DonkDesc }}" autocomplete=off>
<p> <p>
<textarea name="noise" id="honknoise">{{ .Noise }}</textarea> <textarea name="noise" id="honknoise">{{ .Noise }}</textarea>
<p> <p>
@ -14,6 +16,10 @@ in reply to: <input type="text" name="rid" id="ridinput" value="{{ .InReplyTo }}
<input type="submit" name="preview" value="preview"> <input type="submit" name="preview" value="preview">
</form> </form>
<script> <script>
(function() {
var el = document.getElementById("donkdescriptor")
el.style.display = "none"
})();
function showhonkform(elem, rid, hname) { function showhonkform(elem, rid, hname) {
var form = document.getElementById("honkform") var form = document.getElementById("honkform")
form.style = "display: block" form.style = "display: block"
@ -35,5 +41,7 @@ function showhonkform(elem, rid, hname) {
function updatedonker() { function updatedonker() {
var el = document.getElementById("donker") var el = document.getElementById("donker")
el.children[1].textContent = el.children[0].value.slice(-20) el.children[1].textContent = el.children[0].value.slice(-20)
var el = document.getElementById("donkdescriptor")
el.style.display = ""
} }
</script> </script>