From 249105f131f399b7af4281e336a6e24ed774260d Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 14 May 2020 17:42:57 -0400 Subject: [PATCH] handle single attachment not in array --- activity.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/activity.go b/activity.go index d94f304..bfbb415 100644 --- a/activity.go +++ b/activity.go @@ -715,15 +715,11 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { 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 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { 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 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk { 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 {