summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing/attachment.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-09-04 14:02:01 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-04 14:02:01 +0200
commit2b14b208025e5f7e57f71dcaba6d396081bdc54b (patch)
tree0ace50114ac9ac441b361a92216a57bdc6ae40d7 /internal/federation/dereferencing/attachment.go
parenttests + announce notification fix (#193) (diff)
downloadgotosocial-2b14b208025e5f7e57f71dcaba6d396081bdc54b.tar.xz
rework media processing a little bit (#191)
* rework media processing a little bit * review changes
Diffstat (limited to 'internal/federation/dereferencing/attachment.go')
-rw-r--r--internal/federation/dereferencing/attachment.go34
1 files changed, 26 insertions, 8 deletions
diff --git a/internal/federation/dereferencing/attachment.go b/internal/federation/dereferencing/attachment.go
index fd2e3cb8f..fd0cfba18 100644
--- a/internal/federation/dereferencing/attachment.go
+++ b/internal/federation/dereferencing/attachment.go
@@ -28,17 +28,23 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-func (d *deref) GetRemoteAttachment(ctx context.Context, requestingUsername string, remoteAttachmentURI *url.URL, ownerAccountID string, statusID string, expectedContentType string) (*gtsmodel.MediaAttachment, error) {
+func (d *deref) GetRemoteAttachment(ctx context.Context, requestingUsername string, minAttachment *gtsmodel.MediaAttachment) (*gtsmodel.MediaAttachment, error) {
+ if minAttachment.RemoteURL == "" {
+ return nil, fmt.Errorf("GetRemoteAttachment: minAttachment remote URL was empty")
+ }
+ remoteAttachmentURL := minAttachment.RemoteURL
+
l := d.log.WithFields(logrus.Fields{
"username": requestingUsername,
- "remoteAttachmentURI": remoteAttachmentURI,
+ "remoteAttachmentURL": remoteAttachmentURL,
})
+ // return early if we already have the attachment somewhere
maybeAttachment := &gtsmodel.MediaAttachment{}
where := []db.Where{
{
Key: "remote_url",
- Value: remoteAttachmentURI.String(),
+ Value: remoteAttachmentURL,
},
}
@@ -48,12 +54,11 @@ func (d *deref) GetRemoteAttachment(ctx context.Context, requestingUsername stri
return maybeAttachment, nil
}
- a, err := d.RefreshAttachment(ctx, requestingUsername, remoteAttachmentURI, ownerAccountID, expectedContentType)
+ a, err := d.RefreshAttachment(ctx, requestingUsername, minAttachment)
if err != nil {
return nil, fmt.Errorf("GetRemoteAttachment: error refreshing attachment: %s", err)
}
- a.StatusID = statusID
if err := d.db.Put(ctx, a); err != nil {
if err != db.ErrAlreadyExists {
return nil, fmt.Errorf("GetRemoteAttachment: error inserting attachment: %s", err)
@@ -63,19 +68,32 @@ func (d *deref) GetRemoteAttachment(ctx context.Context, requestingUsername stri
return a, nil
}
-func (d *deref) RefreshAttachment(ctx context.Context, requestingUsername string, remoteAttachmentURI *url.URL, ownerAccountID string, expectedContentType string) (*gtsmodel.MediaAttachment, error) {
+func (d *deref) RefreshAttachment(ctx context.Context, requestingUsername string, minAttachment *gtsmodel.MediaAttachment) (*gtsmodel.MediaAttachment, error) {
// it just doesn't exist or we have to refresh
+ if minAttachment.AccountID == "" {
+ return nil, fmt.Errorf("RefreshAttachment: minAttachment account ID was empty")
+ }
+
+ if minAttachment.File.ContentType == "" {
+ return nil, fmt.Errorf("RefreshAttachment: minAttachment.file.contentType was empty")
+ }
+
t, err := d.transportController.NewTransportForUsername(ctx, requestingUsername)
if err != nil {
return nil, fmt.Errorf("RefreshAttachment: error creating transport: %s", err)
}
- attachmentBytes, err := t.DereferenceMedia(ctx, remoteAttachmentURI, expectedContentType)
+ derefURI, err := url.Parse(minAttachment.RemoteURL)
+ if err != nil {
+ return nil, err
+ }
+
+ attachmentBytes, err := t.DereferenceMedia(ctx, derefURI, minAttachment.File.ContentType)
if err != nil {
return nil, fmt.Errorf("RefreshAttachment: error dereferencing media: %s", err)
}
- a, err := d.mediaHandler.ProcessAttachment(ctx, attachmentBytes, ownerAccountID, remoteAttachmentURI.String())
+ a, err := d.mediaHandler.ProcessAttachment(ctx, attachmentBytes, minAttachment)
if err != nil {
return nil, fmt.Errorf("RefreshAttachment: error processing attachment: %s", err)
}