i think this is enough for image descriptions
This commit is contained in:
parent
c597677905
commit
ead0b2995e
19
activity.go
19
activity.go
|
@ -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 == "" {
|
||||
return nil
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func savedonk(url string, name, media string, localize bool) *Donk {
|
|||
}
|
||||
}
|
||||
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 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
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 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
} 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 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
}
|
||||
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 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
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 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
|
|||
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)
|
||||
|
|
|
@ -2,6 +2,8 @@ changelog
|
|||
|
||||
-- next
|
||||
|
||||
+ Image descriptions.
|
||||
|
||||
++ Search. I hate it already.
|
||||
|
||||
+ Unbonking.
|
||||
|
|
22
honk.go
22
honk.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 @@ func donksforhonks(honks []*Honk) {
|
|||
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 @@ func donksforhonks(honks []*Honk) {
|
|||
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
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 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
|||
log.Printf("error saving ont: %s", err)
|
||||
}
|
||||
}
|
||||
honk.Donks = nil
|
||||
donksforhonks([]*Honk{&honk})
|
||||
|
||||
go honkworldwide(user, &honk)
|
||||
|
||||
|
@ -1847,7 +1843,7 @@ func prepareStatements(db *sql.DB) {
|
|||
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 (?, ?, ?, ?, ?)")
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -184,6 +184,11 @@ func upgradedb() {
|
|||
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)
|
||||
}
|
||||
|
|
2
util.go
2
util.go
|
@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05"
|
|||
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")
|
||||
|
|
|
@ -47,7 +47,7 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
|||
{{ 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 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
|||
{{ 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 }}
|
||||
|
|
|
@ -7,6 +7,8 @@ in reply to: <input type="text" name="rid" id="ridinput" value="{{ .InReplyTo }}
|
|||
<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 @@ in reply to: <input type="text" name="rid" id="ridinput" value="{{ .InReplyTo }}
|
|||
<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 showhonkform(elem, rid, hname) {
|
|||
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>
|
||||
|
|
Loading…
Reference in New Issue