mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-07 19:28:07 -06:00
pass a function into the manager, start work on emoji
This commit is contained in:
parent
e0f9323b9a
commit
113f9d9ab4
20 changed files with 936 additions and 299 deletions
|
|
@ -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,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
attachmentID := processingMedia.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)
|
||||
// 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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue