handle single attachment not in array

This commit is contained in:
Ted Unangst 2020-05-14 17:42:57 -04:00
parent afcbbd8d75
commit 249105f131
1 changed files with 17 additions and 8 deletions

View File

@ -715,15 +715,11 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if what == "honk" && rid != "" { if what == "honk" && rid != "" {
what = "tonk" what = "tonk"
} }
atts, _ := obj.GetArray("attachment") numatts := 0
for i, atti := range atts { procatt := func(att junk.Junk) {
if rejectxonk(&xonk) { if rejectxonk(&xonk) {
log.Printf("skipping rejected attachment: %s", xid) log.Printf("skipping rejected attachment: %s", xid)
continue return
}
att, ok := atti.(junk.Junk)
if !ok {
continue
} }
at, _ := att.GetString("type") at, _ := att.GetString("type")
mt, _ := att.GetString("mediaType") mt, _ := att.GetString("mediaType")
@ -734,7 +730,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
desc = name desc = name
} }
localize := false localize := false
if i > 4 { if numatts > 4 {
log.Printf("excessive attachment: %s", at) log.Printf("excessive attachment: %s", at)
} else if at == "Document" || at == "Image" { } else if at == "Document" || at == "Image" {
mt = strings.ToLower(mt) mt = strings.ToLower(mt)
@ -753,6 +749,19 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if donk != nil { if donk != nil {
xonk.Donks = append(xonk.Donks, donk) 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") tags, _ := obj.GetArray("tag")
for _, tagi := range tags { for _, tagi := range tags {