for image types, prefer the original over attachments

This commit is contained in:
Ted Unangst 2023-03-25 15:09:53 -04:00
parent b5470175c7
commit 353a3b27f6
1 changed files with 34 additions and 10 deletions

View File

@ -574,6 +574,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
var replies []string var replies []string
var obj junk.Junk var obj junk.Junk
waspage := false waspage := false
preferorig := false
switch what { switch what {
case "Delete": case "Delete":
obj, ok = item.GetMap("object") obj, ok = item.GetMap("object")
@ -688,6 +689,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
case "Audio": case "Audio":
fallthrough fallthrough
case "Image": case "Image":
preferorig = true
fallthrough fallthrough
case "Video": case "Video":
fallthrough fallthrough
@ -836,6 +838,9 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
at, _ := att.GetString("type") at, _ := att.GetString("type")
mt, _ := att.GetString("mediaType") mt, _ := att.GetString("mediaType")
u, ok := att.GetString("url") u, ok := att.GetString("url")
if !ok {
u, ok = att.GetString("href")
}
if !ok { if !ok {
if ua, ok := att.GetArray("url"); ok && len(ua) > 0 { if ua, ok := att.GetArray("url"); ok && len(ua) > 0 {
u, ok = ua[0].(string) u, ok = ua[0].(string)
@ -863,7 +868,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
localize := false localize := false
if numatts > 4 { if numatts > 4 {
ilog.Printf("excessive attachment: %s", at) ilog.Printf("excessive attachment: %s", at)
} else if at == "Document" || at == "Image" { } else if at == "Document" || at == "Image" || (preferorig && at == "Link") {
mt = strings.ToLower(mt) mt = strings.ToLower(mt)
dlog.Printf("attachment: %s %s", mt, u) dlog.Printf("attachment: %s %s", mt, u)
if mt == "text/plain" || mt == "application/pdf" || if mt == "text/plain" || mt == "application/pdf" ||
@ -876,23 +881,42 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if skipMedia(&xonk) { if skipMedia(&xonk) {
localize = false localize = false
} }
if preferorig && !localize {
return
}
donk := savedonk(u, name, desc, mt, localize) 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)
} }
numatts++ numatts++
} }
atts, _ := obj.GetArray("attachment") if preferorig {
for _, atti := range atts { atts, _ := obj.GetArray("url")
att, ok := atti.(junk.Junk) for _, atti := range atts {
if !ok { att, ok := atti.(junk.Junk)
ilog.Printf("attachment that wasn't map?") if !ok {
continue ilog.Printf("attachment that wasn't map?")
continue
}
procatt(att)
}
if numatts == 0 {
preferorig = false
} }
procatt(att)
} }
if att, ok := obj.GetMap("attachment"); ok { if !preferorig {
procatt(att) atts, _ := obj.GetArray("attachment")
for _, atti := range atts {
att, ok := atti.(junk.Junk)
if !ok {
ilog.Printf("attachment that wasn't map?")
continue
}
procatt(att)
}
if att, ok := obj.GetMap("attachment"); ok {
procatt(att)
}
} }
tags, _ := obj.GetArray("tag") tags, _ := obj.GetArray("tag")
for _, tagi := range tags { for _, tagi := range tags {