handle single attachment not in array
Ted Unangst tedu@tedunangst.com
Thu, 14 May 2020 17:42:57 -0400
1 files changed,
17 insertions(+),
8 deletions(-)
jump to
M
activity.go
→
activity.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 {