all repos — honk @ f3e53adeeffca9d736b1a52fa057bd2b897eae21

my fork of honk

handle single attachment not in array
Ted Unangst tedu@tedunangst.com
Thu, 14 May 2020 17:42:57 -0400
commit

f3e53adeeffca9d736b1a52fa057bd2b897eae21

parent

28fa2b6f3e08eeb5c90d4256141a8bbecd4f2b09

1 files changed, 17 insertions(+), 8 deletions(-)

jump to
M activity.goactivity.go

@@ -715,15 +715,11 @@ }

if what == "honk" && rid != "" { what = "tonk" } - atts, _ := obj.GetArray("attachment") - for i, atti := range atts { + numatts := 0 + procatt := func(att junk.Junk) { if rejectxonk(&xonk) { log.Printf("skipping rejected attachment: %s", xid) - continue - } - att, ok := atti.(junk.Junk) - if !ok { - continue + return } at, _ := att.GetString("type") mt, _ := att.GetString("mediaType")

@@ -734,7 +730,7 @@ if desc == "" {

desc = name } localize := false - if i > 4 { + if numatts > 4 { log.Printf("excessive attachment: %s", at) } else if at == "Document" || at == "Image" { mt = strings.ToLower(mt)

@@ -753,6 +749,19 @@ donk := savedonk(u, name, desc, mt, localize)

if donk != nil { xonk.Donks = append(xonk.Donks, donk) } + numatts++ + } + atts, _ := obj.GetArray("attachment") + for _, atti := range atts { + att, ok := atti.(junk.Junk) + if !ok { + log.Printf("attachment that wasn't map?") + continue + } + procatt(att) + } + if att, ok := obj.GetMap("attachment"); ok { + procatt(att) } tags, _ := obj.GetArray("tag") for _, tagi := range tags {