diff options
Diffstat (limited to 'internal/processing/media')
-rw-r--r-- | internal/processing/media/delete.go | 8 | ||||
-rw-r--r-- | internal/processing/media/getemoji.go | 2 | ||||
-rw-r--r-- | internal/processing/media/getfile.go | 12 | ||||
-rw-r--r-- | internal/processing/media/getmedia.go | 2 | ||||
-rw-r--r-- | internal/processing/media/media.go | 11 | ||||
-rw-r--r-- | internal/processing/media/media_test.go | 16 | ||||
-rw-r--r-- | internal/processing/media/unattach.go | 4 | ||||
-rw-r--r-- | internal/processing/media/update.go | 4 |
8 files changed, 30 insertions, 29 deletions
diff --git a/internal/processing/media/delete.go b/internal/processing/media/delete.go index 6507fcae4..02bd6cd0d 100644 --- a/internal/processing/media/delete.go +++ b/internal/processing/media/delete.go @@ -13,7 +13,7 @@ import ( // Delete deletes the media attachment with the given ID, including all files pertaining to that attachment. func (p *Processor) Delete(ctx context.Context, mediaAttachmentID string) gtserror.WithCode { - attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID) + attachment, err := p.state.DB.GetAttachmentByID(ctx, mediaAttachmentID) if err != nil { if err == db.ErrNoEntries { // attachment already gone @@ -27,20 +27,20 @@ func (p *Processor) Delete(ctx context.Context, mediaAttachmentID string) gtserr // delete the thumbnail from storage if attachment.Thumbnail.Path != "" { - if err := p.storage.Delete(ctx, attachment.Thumbnail.Path); err != nil && !errors.Is(err, storage.ErrNotFound) { + if err := p.state.Storage.Delete(ctx, attachment.Thumbnail.Path); err != nil && !errors.Is(err, storage.ErrNotFound) { errs = append(errs, fmt.Sprintf("remove thumbnail at path %s: %s", attachment.Thumbnail.Path, err)) } } // delete the file from storage if attachment.File.Path != "" { - if err := p.storage.Delete(ctx, attachment.File.Path); err != nil && !errors.Is(err, storage.ErrNotFound) { + if err := p.state.Storage.Delete(ctx, attachment.File.Path); err != nil && !errors.Is(err, storage.ErrNotFound) { errs = append(errs, fmt.Sprintf("remove file at path %s: %s", attachment.File.Path, err)) } } // delete the attachment - if err := p.db.DeleteByID(ctx, mediaAttachmentID, attachment); err != nil && !errors.Is(err, db.ErrNoEntries) { + if err := p.state.DB.DeleteByID(ctx, mediaAttachmentID, attachment); err != nil && !errors.Is(err, db.ErrNoEntries) { errs = append(errs, fmt.Sprintf("remove attachment: %s", err)) } diff --git a/internal/processing/media/getemoji.go b/internal/processing/media/getemoji.go index 4c0ce9930..fba059f60 100644 --- a/internal/processing/media/getemoji.go +++ b/internal/processing/media/getemoji.go @@ -31,7 +31,7 @@ import ( // GetCustomEmojis returns a list of all useable local custom emojis stored on this instance. // 'useable' in this context means visible and picker, and not disabled. func (p *Processor) GetCustomEmojis(ctx context.Context) ([]*apimodel.Emoji, gtserror.WithCode) { - emojis, err := p.db.GetUseableEmojis(ctx) + emojis, err := p.state.DB.GetUseableEmojis(ctx) if err != nil { if err != db.ErrNoEntries { return nil, gtserror.NewErrorNotFound(fmt.Errorf("db error retrieving custom emojis: %s", err)) diff --git a/internal/processing/media/getfile.go b/internal/processing/media/getfile.go index 2a4ef2097..f9c6c23c2 100644 --- a/internal/processing/media/getfile.go +++ b/internal/processing/media/getfile.go @@ -54,7 +54,7 @@ func (p *Processor) GetFile(ctx context.Context, requestingAccount *gtsmodel.Acc owningAccountID := form.AccountID // get the account that owns the media and make sure it's not suspended - owningAccount, err := p.db.GetAccountByID(ctx, owningAccountID) + owningAccount, err := p.state.DB.GetAccountByID(ctx, owningAccountID) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("account with id %s could not be selected from the db: %s", owningAccountID, err)) } @@ -64,7 +64,7 @@ func (p *Processor) GetFile(ctx context.Context, requestingAccount *gtsmodel.Acc // make sure the requesting account and the media account don't block each other if requestingAccount != nil { - blocked, err := p.db.IsBlocked(ctx, requestingAccount.ID, owningAccountID, true) + blocked, err := p.state.DB.IsBlocked(ctx, requestingAccount.ID, owningAccountID, true) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("block status could not be established between accounts %s and %s: %s", owningAccountID, requestingAccount.ID, err)) } @@ -117,7 +117,7 @@ func parseSize(s string) (media.Size, error) { func (p *Processor) getAttachmentContent(ctx context.Context, requestingAccount *gtsmodel.Account, wantedMediaID string, owningAccountID string, mediaSize media.Size) (*apimodel.Content, gtserror.WithCode) { // retrieve attachment from the database and do basic checks on it - a, err := p.db.GetAttachmentByID(ctx, wantedMediaID) + a, err := p.state.DB.GetAttachmentByID(ctx, wantedMediaID) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("attachment %s could not be taken from the db: %s", wantedMediaID, err)) } @@ -209,7 +209,7 @@ func (p *Processor) getEmojiContent(ctx context.Context, fileName string, owning // so this is more reliable than using full size url imageStaticURL := uris.GenerateURIForAttachment(owningAccountID, string(media.TypeEmoji), string(media.SizeStatic), fileName, "png") - e, err := p.db.GetEmojiByStaticURL(ctx, imageStaticURL) + e, err := p.state.DB.GetEmojiByStaticURL(ctx, imageStaticURL) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji %s could not be taken from the db: %s", fileName, err)) } @@ -237,12 +237,12 @@ func (p *Processor) getEmojiContent(ctx context.Context, fileName string, owning func (p *Processor) retrieveFromStorage(ctx context.Context, storagePath string, content *apimodel.Content) (*apimodel.Content, gtserror.WithCode) { // If running on S3 storage with proxying disabled then // just fetch a pre-signed URL instead of serving the content. - if url := p.storage.URL(ctx, storagePath); url != nil { + if url := p.state.Storage.URL(ctx, storagePath); url != nil { content.URL = url return content, nil } - reader, err := p.storage.GetStream(ctx, storagePath) + reader, err := p.state.Storage.GetStream(ctx, storagePath) if err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("error retrieving from storage: %s", err)) } diff --git a/internal/processing/media/getmedia.go b/internal/processing/media/getmedia.go index 03d5ba770..dad6ac538 100644 --- a/internal/processing/media/getmedia.go +++ b/internal/processing/media/getmedia.go @@ -30,7 +30,7 @@ import ( ) func (p *Processor) Get(ctx context.Context, account *gtsmodel.Account, mediaAttachmentID string) (*apimodel.Attachment, gtserror.WithCode) { - attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID) + attachment, err := p.state.DB.GetAttachmentByID(ctx, mediaAttachmentID) if err != nil { if err == db.ErrNoEntries { // attachment doesn't exist diff --git a/internal/processing/media/media.go b/internal/processing/media/media.go index ca95e276f..51585102a 100644 --- a/internal/processing/media/media.go +++ b/internal/processing/media/media.go @@ -19,28 +19,25 @@ package media import ( - "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/media" - "github.com/superseriousbusiness/gotosocial/internal/storage" + "github.com/superseriousbusiness/gotosocial/internal/state" "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) type Processor struct { + state *state.State tc typeutils.TypeConverter mediaManager media.Manager transportController transport.Controller - storage *storage.Driver - db db.DB } // New returns a new media processor. -func New(db db.DB, tc typeutils.TypeConverter, mediaManager media.Manager, transportController transport.Controller, storage *storage.Driver) Processor { +func New(state *state.State, tc typeutils.TypeConverter, mediaManager media.Manager, transportController transport.Controller) Processor { return Processor{ + state: state, tc: tc, mediaManager: mediaManager, transportController: transportController, - storage: storage, - db: db, } } diff --git a/internal/processing/media/media_test.go b/internal/processing/media/media_test.go index 1d223a66c..e706dbd7a 100644 --- a/internal/processing/media/media_test.go +++ b/internal/processing/media/media_test.go @@ -20,12 +20,11 @@ package media_test import ( "github.com/stretchr/testify/suite" - "github.com/superseriousbusiness/gotosocial/internal/concurrency" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/media" - "github.com/superseriousbusiness/gotosocial/internal/messages" mediaprocessing "github.com/superseriousbusiness/gotosocial/internal/processing/media" + "github.com/superseriousbusiness/gotosocial/internal/state" "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" @@ -38,6 +37,7 @@ type MediaStandardTestSuite struct { db db.DB tc typeutils.TypeConverter storage *storage.Driver + state state.State mediaManager media.Manager transportController transport.Controller @@ -67,15 +67,19 @@ func (suite *MediaStandardTestSuite) SetupSuite() { } func (suite *MediaStandardTestSuite) SetupTest() { + suite.state.Caches.Init() + testrig.InitTestConfig() testrig.InitTestLog() - suite.db = testrig.NewTestDB() + suite.db = testrig.NewTestDB(&suite.state) + suite.state.DB = suite.db suite.tc = testrig.NewTestTypeConverter(suite.db) suite.storage = testrig.NewInMemoryStorage() - suite.mediaManager = testrig.NewTestMediaManager(suite.db, suite.storage) - suite.transportController = testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../testrig/media"), suite.db, concurrency.NewWorkerPool[messages.FromFederator](-1, -1)) - suite.mediaProcessor = mediaprocessing.New(suite.db, suite.tc, suite.mediaManager, suite.transportController, suite.storage) + suite.state.Storage = suite.storage + suite.mediaManager = testrig.NewTestMediaManager(&suite.state) + suite.transportController = testrig.NewTestTransportController(&suite.state, testrig.NewMockHTTPClient(nil, "../../../testrig/media")) + suite.mediaProcessor = mediaprocessing.New(&suite.state, suite.tc, suite.mediaManager, suite.transportController) testrig.StandardDBSetup(suite.db, nil) testrig.StandardStorageSetup(suite.storage, "../../../testrig/media") } diff --git a/internal/processing/media/unattach.go b/internal/processing/media/unattach.go index 816b5134e..7c6f7dbac 100644 --- a/internal/processing/media/unattach.go +++ b/internal/processing/media/unattach.go @@ -33,7 +33,7 @@ import ( // Unattach unattaches the media attachment with the given ID from any statuses it was attached to, making it available // for reattachment again. func (p *Processor) Unattach(ctx context.Context, account *gtsmodel.Account, mediaAttachmentID string) (*apimodel.Attachment, gtserror.WithCode) { - attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID) + attachment, err := p.state.DB.GetAttachmentByID(ctx, mediaAttachmentID) if err != nil { if err == db.ErrNoEntries { return nil, gtserror.NewErrorNotFound(errors.New("attachment doesn't exist in the db")) @@ -49,7 +49,7 @@ func (p *Processor) Unattach(ctx context.Context, account *gtsmodel.Account, med attachment.UpdatedAt = time.Now() attachment.StatusID = "" - if err := p.db.UpdateByID(ctx, attachment, attachment.ID, updatingColumns...); err != nil { + if err := p.state.DB.UpdateByID(ctx, attachment, attachment.ID, updatingColumns...); err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("db error updating attachment: %s", err)) } diff --git a/internal/processing/media/update.go b/internal/processing/media/update.go index c03df705b..cf49168f0 100644 --- a/internal/processing/media/update.go +++ b/internal/processing/media/update.go @@ -32,7 +32,7 @@ import ( // Update updates a media attachment with the given id, using the provided form parameters. func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, mediaAttachmentID string, form *apimodel.AttachmentUpdateRequest) (*apimodel.Attachment, gtserror.WithCode) { - attachment, err := p.db.GetAttachmentByID(ctx, mediaAttachmentID) + attachment, err := p.state.DB.GetAttachmentByID(ctx, mediaAttachmentID) if err != nil { if err == db.ErrNoEntries { // attachment doesn't exist @@ -62,7 +62,7 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, media updatingColumns = append(updatingColumns, "focus_x", "focus_y") } - if err := p.db.UpdateByID(ctx, attachment, attachment.ID, updatingColumns...); err != nil { + if err := p.state.DB.UpdateByID(ctx, attachment, attachment.ID, updatingColumns...); err != nil { return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error updating media: %s", err)) } |