rework activity injesting to reject attachments sooner

This commit is contained in:
Ted Unangst 2020-01-23 20:41:30 -05:00
parent 3c3f81e548
commit 5a318202a0
1 changed files with 21 additions and 8 deletions

View File

@ -610,7 +610,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if c, ok := obj.GetString("source", "content"); ok { if c, ok := obj.GetString("source", "content"); ok {
re_link := regexp.MustCompile(`link='([^']*)'`) re_link := regexp.MustCompile(`link='([^']*)'`)
if m := re_link.FindStringSubmatch(c); len(m) > 1 { if m := re_link.FindStringSubmatch(c); len(m) > 1 {
xid := m[1] xid = m[1]
log.Printf("getting friendica flavored bonk: %s", xid) log.Printf("getting friendica flavored bonk: %s", xid)
if !needxonkid(user, xid) { if !needxonkid(user, xid) {
return nil return nil
@ -627,8 +627,20 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
} }
} }
if xid == "" {
log.Printf("don't know what xid is")
item.Write(os.Stdout)
return nil
}
if originate(xid) != origin {
log.Printf("original sin: %s <> %s", xid, origin)
item.Write(os.Stdout)
return nil
}
var xonk Honk var xonk Honk
// early init // early init
xonk.XID = xid
xonk.UserID = user.ID xonk.UserID = user.ID
xonk.Honker, _ = item.GetString("actor") xonk.Honker, _ = item.GetString("actor")
if xonk.Honker == "" { if xonk.Honker == "" {
@ -654,7 +666,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
if dt2, ok := obj.GetString("published"); ok { if dt2, ok := obj.GetString("published"); ok {
dt = dt2 dt = dt2
} }
xid, _ = obj.GetString("id")
content, _ = obj.GetString("content") content, _ = obj.GetString("content")
if !strings.HasPrefix(content, "<p>") { if !strings.HasPrefix(content, "<p>") {
content = "<p>" + content content = "<p>" + content
@ -713,6 +724,10 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
} }
atts, _ := obj.GetArray("attachment") atts, _ := obj.GetArray("attachment")
for i, atti := range atts { for i, atti := range atts {
if rejectxonk(&xonk) {
log.Printf("skipping rejected attachment: %s", xid)
continue
}
att, ok := atti.(junk.Junk) att, ok := atti.(junk.Junk)
if !ok { if !ok {
continue continue
@ -748,6 +763,10 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
} }
tags, _ := obj.GetArray("tag") tags, _ := obj.GetArray("tag")
for _, tagi := range tags { for _, tagi := range tags {
if rejectxonk(&xonk) {
log.Printf("skipping rejected attachment: %s", xid)
continue
}
tag, ok := tagi.(junk.Junk) tag, ok := tagi.(junk.Junk)
if !ok { if !ok {
continue continue
@ -840,11 +859,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
} }
} }
if originate(xid) != origin {
log.Printf("original sin: %s <> %s", xid, origin)
item.Write(os.Stdout)
return nil
}
if currenttid == "" { if currenttid == "" {
currenttid = convoy currenttid = convoy
@ -857,7 +871,6 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
// init xonk // init xonk
xonk.What = what xonk.What = what
xonk.XID = xid
xonk.RID = rid xonk.RID = rid
xonk.Date, _ = time.Parse(time.RFC3339, dt) xonk.Date, _ = time.Parse(time.RFC3339, dt)
xonk.URL = url xonk.URL = url