summaryrefslogtreecommitdiff
path: root/internal/federation
diff options
context:
space:
mode:
Diffstat (limited to 'internal/federation')
-rw-r--r--internal/federation/dereferencing/account.go15
-rw-r--r--internal/federation/dereferencing/dereferencer.go2
-rw-r--r--internal/federation/dereferencing/media.go17
-rw-r--r--internal/federation/dereferencing/media_test.go20
-rw-r--r--internal/federation/dereferencing/status.go4
5 files changed, 29 insertions, 29 deletions
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go
index 27d9f39ce..b9efbfa45 100644
--- a/internal/federation/dereferencing/account.go
+++ b/internal/federation/dereferencing/account.go
@@ -119,7 +119,6 @@ func (d *deref) GetRemoteAccount(ctx context.Context, username string, remoteAcc
} else {
// take the id we already have and do an update
gtsAccount.ID = maybeAccount.ID
-aaaaaaaaaaaaaaaaaa
if err := d.PopulateAccountFields(ctx, gtsAccount, username, refresh); err != nil {
return nil, new, fmt.Errorf("FullyDereferenceAccount: error populating further account fields: %s", err)
}
@@ -252,13 +251,12 @@ func (d *deref) fetchHeaderAndAviForAccount(ctx context.Context, targetAccount *
return err
}
- data, err := t.DereferenceMedia(ctx, avatarIRI)
- if err != nil {
- return err
+ data := func(innerCtx context.Context) ([]byte, error) {
+ return t.DereferenceMedia(innerCtx, avatarIRI)
}
avatar := true
- processingMedia, err := d.mediaManager.ProcessMedia(ctx, data, targetAccount.ID, &media.AdditionalInfo{
+ processingMedia, err := d.mediaManager.ProcessMedia(ctx, data, targetAccount.ID, &media.AdditionalMediaInfo{
RemoteURL: &targetAccount.AvatarRemoteURL,
Avatar: &avatar,
})
@@ -275,13 +273,12 @@ func (d *deref) fetchHeaderAndAviForAccount(ctx context.Context, targetAccount *
return err
}
- data, err := t.DereferenceMedia(ctx, headerIRI)
- if err != nil {
- return err
+ data := func(innerCtx context.Context) ([]byte, error) {
+ return t.DereferenceMedia(innerCtx, headerIRI)
}
header := true
- processingMedia, err := d.mediaManager.ProcessMedia(ctx, data, targetAccount.ID, &media.AdditionalInfo{
+ processingMedia, err := d.mediaManager.ProcessMedia(ctx, data, targetAccount.ID, &media.AdditionalMediaInfo{
RemoteURL: &targetAccount.HeaderRemoteURL,
Header: &header,
})
diff --git a/internal/federation/dereferencing/dereferencer.go b/internal/federation/dereferencing/dereferencer.go
index 1e6f781b8..800da6c04 100644
--- a/internal/federation/dereferencing/dereferencer.go
+++ b/internal/federation/dereferencing/dereferencer.go
@@ -41,7 +41,7 @@ type Dereferencer interface {
GetRemoteInstance(ctx context.Context, username string, remoteInstanceURI *url.URL) (*gtsmodel.Instance, error)
- GetRemoteMedia(ctx context.Context, requestingUsername string, accountID string, remoteURL string, ai *media.AdditionalInfo) (*media.Processing, error)
+ GetRemoteMedia(ctx context.Context, requestingUsername string, accountID string, remoteURL string, ai *media.AdditionalMediaInfo) (*media.ProcessingMedia, error)
DereferenceAnnounce(ctx context.Context, announce *gtsmodel.Status, requestingUsername string) error
DereferenceThread(ctx context.Context, username string, statusIRI *url.URL) error
diff --git a/internal/federation/dereferencing/media.go b/internal/federation/dereferencing/media.go
index f02303aa1..46cb4a5f4 100644
--- a/internal/federation/dereferencing/media.go
+++ b/internal/federation/dereferencing/media.go
@@ -26,29 +26,28 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/media"
)
-func (d *deref) GetRemoteMedia(ctx context.Context, requestingUsername string, accountID string, remoteURL string, ai *media.AdditionalInfo) (*media.Processing, error) {
+func (d *deref) GetRemoteMedia(ctx context.Context, requestingUsername string, accountID string, remoteURL string, ai *media.AdditionalMediaInfo) (*media.ProcessingMedia, error) {
if accountID == "" {
- return nil, fmt.Errorf("RefreshAttachment: minAttachment account ID was empty")
+ return nil, fmt.Errorf("GetRemoteMedia: account ID was empty")
}
t, err := d.transportController.NewTransportForUsername(ctx, requestingUsername)
if err != nil {
- return nil, fmt.Errorf("RefreshAttachment: error creating transport: %s", err)
+ return nil, fmt.Errorf("GetRemoteMedia: error creating transport: %s", err)
}
derefURI, err := url.Parse(remoteURL)
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("GetRemoteMedia: error parsing url: %s", err)
}
- data, err := t.DereferenceMedia(ctx, derefURI)
- if err != nil {
- return nil, fmt.Errorf("RefreshAttachment: error dereferencing media: %s", err)
+ dataFunc := func(innerCtx context.Context) ([]byte, error) {
+ return t.DereferenceMedia(innerCtx, derefURI)
}
- processingMedia, err := d.mediaManager.ProcessMedia(ctx, data, accountID, ai)
+ processingMedia, err := d.mediaManager.ProcessMedia(ctx, dataFunc, accountID, ai)
if err != nil {
- return nil, fmt.Errorf("RefreshAttachment: error processing attachment: %s", err)
+ return nil, fmt.Errorf("GetRemoteMedia: error processing attachment: %s", err)
}
return processingMedia, nil
diff --git a/internal/federation/dereferencing/media_test.go b/internal/federation/dereferencing/media_test.go
index 61ee6edb6..26d5c0c49 100644
--- a/internal/federation/dereferencing/media_test.go
+++ b/internal/federation/dereferencing/media_test.go
@@ -20,6 +20,7 @@ package dereferencing_test
import (
"context"
+ "fmt"
"testing"
"time"
@@ -44,7 +45,7 @@ func (suite *AttachmentTestSuite) TestDereferenceAttachmentBlocking() {
attachmentDescription := "It's a cute plushie."
attachmentBlurhash := "LwP?p=aK_4%N%MRjWXt7%hozM_a}"
- media, err := suite.dereferencer.GetRemoteMedia(ctx, fetchingAccount.Username, attachmentOwner, attachmentURL, &media.AdditionalInfo{
+ media, err := suite.dereferencer.GetRemoteMedia(ctx, fetchingAccount.Username, attachmentOwner, attachmentURL, &media.AdditionalMediaInfo{
StatusID: &attachmentStatus,
RemoteURL: &attachmentURL,
Description: &attachmentDescription,
@@ -53,7 +54,7 @@ func (suite *AttachmentTestSuite) TestDereferenceAttachmentBlocking() {
suite.NoError(err)
// make a blocking call to load the attachment from the in-process media
- attachment, err := media.Load(ctx)
+ attachment, err := media.LoadAttachment(ctx)
suite.NoError(err)
suite.NotNil(attachment)
@@ -118,18 +119,21 @@ func (suite *AttachmentTestSuite) TestDereferenceAttachmentAsync() {
attachmentDescription := "It's a cute plushie."
attachmentBlurhash := "LwP?p=aK_4%N%MRjWXt7%hozM_a}"
- media, err := suite.dereferencer.GetRemoteMedia(ctx, fetchingAccount.Username, attachmentOwner, attachmentURL, &media.AdditionalInfo{
+ processingMedia, err := suite.dereferencer.GetRemoteMedia(ctx, fetchingAccount.Username, attachmentOwner, attachmentURL, &media.AdditionalMediaInfo{
StatusID: &attachmentStatus,
RemoteURL: &attachmentURL,
Description: &attachmentDescription,
Blurhash: &attachmentBlurhash,
})
suite.NoError(err)
- attachmentID := media.AttachmentID()
-
- // wait 5 seconds to let the image process in the background
- // it probably won't really take this long but hey let's be sure
- time.Sleep(5 * time.Second)
+ attachmentID := processingMedia.AttachmentID()
+
+ // wait for the media to finish processing
+ for finished := processingMedia.Finished(); !finished; finished = processingMedia.Finished() {
+ time.Sleep(10 * time.Millisecond)
+ fmt.Printf("\n\nnot finished yet...\n\n")
+ }
+ fmt.Printf("\n\nfinished!\n\n")
// now get the attachment from the database
attachment, err := suite.db.GetAttachmentByID(ctx, attachmentID)
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index 041cfa6b4..004d648b5 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -394,7 +394,7 @@ func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel.
a.AccountID = status.AccountID
a.StatusID = status.ID
- media, err := d.GetRemoteMedia(ctx, requestingUsername, a.AccountID, a.RemoteURL, &media.AdditionalInfo{
+ media, err := d.GetRemoteMedia(ctx, requestingUsername, a.AccountID, a.RemoteURL, &media.AdditionalMediaInfo{
CreatedAt: &a.CreatedAt,
StatusID: &a.StatusID,
RemoteURL: &a.RemoteURL,
@@ -406,7 +406,7 @@ func (d *deref) populateStatusAttachments(ctx context.Context, status *gtsmodel.
continue
}
- attachment, err := media.Load(ctx)
+ attachment, err := media.LoadAttachment(ctx)
if err != nil {
logrus.Errorf("populateStatusAttachments: couldn't load remote attachment %s: %s", a.RemoteURL, err)
continue