mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 18:02:25 -05:00
restore function signature of ExtractAttachments
This commit is contained in:
parent
c7fc66abae
commit
b2f244aa96
3 changed files with 23 additions and 9 deletions
|
|
@ -32,7 +32,6 @@ import (
|
|||
"code.superseriousbusiness.org/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
)
|
||||
|
|
@ -637,35 +636,40 @@ func ExtractContent(i WithContent) gtsmodel.Content {
|
|||
|
||||
// ExtractAttachments attempts to extract barebones
|
||||
// MediaAttachment objects from given AS interface type.
|
||||
func ExtractAttachments(i WithAttachment) []*gtsmodel.MediaAttachment {
|
||||
func ExtractAttachments(i WithAttachment) ([]*gtsmodel.MediaAttachment, error) {
|
||||
attachmentProp := i.GetActivityStreamsAttachment()
|
||||
if attachmentProp == nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
attachments := make([]*gtsmodel.MediaAttachment, 0, attachmentProp.Len())
|
||||
var (
|
||||
attachments = make([]*gtsmodel.MediaAttachment, 0, attachmentProp.Len())
|
||||
errs gtserror.MultiError
|
||||
)
|
||||
|
||||
for iter := attachmentProp.Begin(); iter != attachmentProp.End(); iter = iter.Next() {
|
||||
t := iter.GetType()
|
||||
if t == nil {
|
||||
errs.Appendf("nil attachment type")
|
||||
continue
|
||||
}
|
||||
|
||||
attachmentable, ok := ToAttachmentable(t)
|
||||
if !ok {
|
||||
log.Debugf(nil, "could not cast %T to Attachmentable", t)
|
||||
errs.Appendf("could not cast %T to Attachmentable", t)
|
||||
continue
|
||||
}
|
||||
|
||||
attachment, err := ExtractAttachment(attachmentable)
|
||||
if err != nil {
|
||||
log.Debugf(nil, "error extracting attachment: %v", err)
|
||||
errs.Appendf("error extracting attachment: %w", err)
|
||||
continue
|
||||
}
|
||||
|
||||
attachments = append(attachments, attachment)
|
||||
}
|
||||
|
||||
return attachments
|
||||
return attachments, errs.Combine()
|
||||
}
|
||||
|
||||
// ExtractAttachment extracts a minimal gtsmodel.Attachment
|
||||
|
|
|
|||
|
|
@ -142,7 +142,14 @@ func (f *Filter) StatusableOK(
|
|||
}
|
||||
|
||||
// HEURISTIC 6: Are there any media attachments?
|
||||
attachments := ap.ExtractAttachments(statusable)
|
||||
attachments, err := ap.ExtractAttachments(statusable)
|
||||
if err != nil {
|
||||
log.Warnf(ctx,
|
||||
"error(s) extracting attachments for %s: %v",
|
||||
ap.GetJSONLDId(statusable), err,
|
||||
)
|
||||
}
|
||||
|
||||
hasAttachments := len(attachments) != 0
|
||||
if hasAttachments {
|
||||
err := errors.New("status has attachment(s)")
|
||||
|
|
|
|||
|
|
@ -288,7 +288,10 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
|
|||
// status.Attachments
|
||||
//
|
||||
// Media attachments for later dereferencing.
|
||||
status.Attachments = ap.ExtractAttachments(statusable)
|
||||
status.Attachments, err = ap.ExtractAttachments(statusable)
|
||||
if err != nil {
|
||||
log.Warnf(ctx, "error(s) extracting attachments for %s: %v", uri, err)
|
||||
}
|
||||
|
||||
// status.Poll
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue