support inline images in received posts
This commit is contained in:
parent
81812030a8
commit
99f0e73394
21
activity.go
21
activity.go
|
@ -30,6 +30,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"humungus.tedunangst.com/r/webs/htfilter"
|
||||
"humungus.tedunangst.com/r/webs/httpsig"
|
||||
"humungus.tedunangst.com/r/webs/image"
|
||||
"humungus.tedunangst.com/r/webs/junk"
|
||||
|
@ -127,16 +128,12 @@ func savedonk(url string, name, desc, media string, localize bool) *Donk {
|
|||
if url == "" {
|
||||
return nil
|
||||
}
|
||||
var donk Donk
|
||||
row := stmtFindFile.QueryRow(url)
|
||||
err := row.Scan(&donk.FileID)
|
||||
if err == nil {
|
||||
return &donk
|
||||
donk := finddonk(url)
|
||||
if donk != nil {
|
||||
return donk
|
||||
}
|
||||
donk = new(Donk)
|
||||
log.Printf("saving donk: %s", url)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
log.Printf("error querying: %s", err)
|
||||
}
|
||||
xid := xfiltrate()
|
||||
data := []byte{}
|
||||
if localize {
|
||||
|
@ -184,7 +181,8 @@ saveit:
|
|||
return nil
|
||||
}
|
||||
donk.FileID = fileid
|
||||
return &donk
|
||||
donk.XID = xid
|
||||
return donk
|
||||
}
|
||||
|
||||
func iszonked(userid int64, xid string) bool {
|
||||
|
@ -765,6 +763,11 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
currenttid = convoy
|
||||
}
|
||||
|
||||
// grab any inline imgs
|
||||
imgfilt := htfilter.New()
|
||||
imgfilt.Imager = inlineimgs
|
||||
imgfilt.String(content)
|
||||
|
||||
// init xonk
|
||||
xonk.What = what
|
||||
xonk.XID = xid
|
||||
|
|
15
database.go
15
database.go
|
@ -309,6 +309,19 @@ func savefile(xid string, name string, desc string, url string, media string, lo
|
|||
return fileid, nil
|
||||
}
|
||||
|
||||
func finddonk(url string) *Donk {
|
||||
donk := new(Donk)
|
||||
row := stmtFindFile.QueryRow(url)
|
||||
err := row.Scan(&donk.FileID, &donk.XID)
|
||||
if err == nil {
|
||||
return donk
|
||||
}
|
||||
if err != sql.ErrNoRows {
|
||||
log.Printf("error finding file: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func savehonk(h *Honk) error {
|
||||
dt := h.Date.UTC().Format(dbtimeformat)
|
||||
aud := strings.Join(h.Audience, " ")
|
||||
|
@ -550,7 +563,7 @@ func prepareStatements(db *sql.DB) {
|
|||
stmtSaveFileData = preparetodie(blobdb, "insert into filedata (xid, media, content) values (?, ?, ?)")
|
||||
stmtGetFileData = preparetodie(blobdb, "select media, content from filedata where xid = ?")
|
||||
stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
|
||||
stmtFindFile = preparetodie(db, "select fileid from filemeta where url = ? and local = 1")
|
||||
stmtFindFile = preparetodie(db, "select fileid, xid from filemeta where url = ? and local = 1")
|
||||
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 (?, ?, ?, ?, ?)")
|
||||
|
|
|
@ -2,6 +2,8 @@ changelog
|
|||
|
||||
-- next
|
||||
|
||||
+ Inline images in received posts.
|
||||
|
||||
+ Times for events.
|
||||
|
||||
+ Split media database into separate blob.db.
|
||||
|
|
24
fun.go
24
fun.go
|
@ -120,9 +120,33 @@ func replaceimg(node *html.Node) string {
|
|||
}
|
||||
alt = html.EscapeString(alt)
|
||||
src = html.EscapeString(src)
|
||||
d := finddonk(src)
|
||||
if d != nil {
|
||||
src = fmt.Sprintf("https://%s/d/%s", serverName, d.XID)
|
||||
return fmt.Sprintf(`<img alt="%s" title="%s" src="%s">`, alt, alt, src)
|
||||
}
|
||||
return fmt.Sprintf(`<img alt="%s" src="<a href="%s">%s<a>">`, alt, src, src)
|
||||
}
|
||||
|
||||
func inlineimgs(node *html.Node) string {
|
||||
src := htfilter.GetAttr(node, "src")
|
||||
alt := htfilter.GetAttr(node, "alt")
|
||||
//title := GetAttr(node, "title")
|
||||
if htfilter.HasClass(node, "Emoji") && alt != "" {
|
||||
return alt
|
||||
}
|
||||
alt = html.EscapeString(alt)
|
||||
src = html.EscapeString(src)
|
||||
if !strings.HasPrefix(src, "https://"+serverName+"/") {
|
||||
d := savedonk(src, "image", alt, "image", true)
|
||||
if d != nil {
|
||||
src = fmt.Sprintf("https://%s/d/%s", serverName, d.XID)
|
||||
}
|
||||
}
|
||||
log.Printf("inline img with src: %s", src)
|
||||
return fmt.Sprintf(`<img alt="%s" title="%s" src="%s>`, alt, alt, src)
|
||||
}
|
||||
|
||||
func translate(honk *Honk) {
|
||||
if honk.Format == "html" {
|
||||
return
|
||||
|
|
8
web.go
8
web.go
|
@ -1022,11 +1022,9 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
xid := donkxid
|
||||
url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
|
||||
var donk Donk
|
||||
row := stmtFindFile.QueryRow(url)
|
||||
err := row.Scan(&donk.FileID)
|
||||
if err == nil {
|
||||
honk.Donks = append(honk.Donks, &donk)
|
||||
donk := finddonk(url)
|
||||
if donk != nil {
|
||||
honk.Donks = append(honk.Donks, donk)
|
||||
} else {
|
||||
log.Printf("can't find file: %s", xid)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue