don't drop the donk! sometimes preview would find the wrong one on resubmit.

This commit is contained in:
Ted Unangst 2023-03-09 01:57:20 -05:00
parent b261f73c49
commit dab8de6670
3 changed files with 28 additions and 4 deletions

View File

@ -574,6 +574,20 @@ func savefileandxid(name string, desc string, url string, media string, local bo
return fileid, xid, nil return fileid, xid, nil
} }
func finddonkid(fileid int64, url string) *Donk {
donk := new(Donk)
row := stmtFindFileId.QueryRow(fileid, url)
err := row.Scan(&donk.XID, &donk.Local, &donk.Desc)
if err == nil {
donk.FileID = fileid
return donk
}
if err != sql.ErrNoRows {
elog.Printf("error finding file: %s", err)
}
return nil
}
func finddonk(url string) *Donk { func finddonk(url string) *Donk {
donk := new(Donk) donk := new(Donk)
row := stmtFindFile.QueryRow(url) row := stmtFindFile.QueryRow(url)
@ -1079,7 +1093,7 @@ var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonk
var stmtHonksFromLongAgo *sql.Stmt var stmtHonksFromLongAgo *sql.Stmt
var stmtHonksByHonker, stmtSaveHonk, stmtUserByName, stmtUserByNumber *sql.Stmt var stmtHonksByHonker, stmtSaveHonk, stmtUserByName, stmtUserByNumber *sql.Stmt
var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt
var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt var stmtFindFile, stmtFindFileId, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt
var stmtCheckFileData *sql.Stmt var stmtCheckFileData *sql.Stmt
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt
var stmtUntagged, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt var stmtUntagged, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt
@ -1149,6 +1163,7 @@ func prepareStatements(db *sql.DB) {
stmtGetFileData = preparetodie(blobdb, "select media, content from filedata where xid = ?") stmtGetFileData = preparetodie(blobdb, "select media, content from filedata where xid = ?")
stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?") stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
stmtFindFile = preparetodie(db, "select fileid, xid from filemeta where url = ? and local = 1") stmtFindFile = preparetodie(db, "select fileid, xid from filemeta where url = ? and local = 1")
stmtFindFileId = preparetodie(db, "select xid, local, description from filemeta where fileid = ? and url = ? and local = 1")
stmtUserByName = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where username = ? and userid > 0") stmtUserByName = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where username = ? and userid > 0")
stmtUserByNumber = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where userid = ?") stmtUserByNumber = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where userid = ?")
stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, '', '', '', ?)") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, '', '', '', ?)")

View File

@ -2,6 +2,8 @@ changelog
=== next === next
+ Some fixes for image descriptions.
+ Fix double htmlization of subject lines. + Fix double htmlization of subject lines.
+ Remove the wonk support. Fun's over, back to work. + Remove the wonk support. Fun's over, back to work.

13
web.go
View File

@ -1678,12 +1678,19 @@ func submithonk(w http.ResponseWriter, r *http.Request) *Honk {
} }
if d != nil { if d != nil {
honk.Donks = append(honk.Donks, d) honk.Donks = append(honk.Donks, d)
donkxid = d.XID donkxid = fmt.Sprintf("%s:%d", d.XID, d.FileID)
} }
} else { } else {
xid := donkxid p := strings.Split(donkxid, ":")
xid := p[0]
url := fmt.Sprintf("https://%s/d/%s", serverName, xid) url := fmt.Sprintf("https://%s/d/%s", serverName, xid)
donk := finddonk(url) var donk *Donk
if len(p) > 1 {
fileid, _ := strconv.ParseInt(p[1], 10, 0)
donk = finddonkid(fileid, url)
} else {
donk = finddonk(url)
}
if donk != nil { if donk != nil {
honk.Donks = append(honk.Donks, donk) honk.Donks = append(honk.Donks, donk)
} else { } else {