diff options
author | 2022-01-08 17:17:01 +0100 | |
---|---|---|
committer | 2022-01-08 17:17:01 +0100 | |
commit | f61c3ddcf72ff689b9d253546c58d499b6fe6ac8 (patch) | |
tree | b418d5a833f0e3b92b255e73efa98007eb8127ac /internal/media/manager.go | |
parent | further refinements (diff) | |
download | gotosocial-f61c3ddcf72ff689b9d253546c58d499b6fe6ac8.tar.xz |
compiling now
Diffstat (limited to 'internal/media/manager.go')
-rw-r--r-- | internal/media/manager.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/internal/media/manager.go b/internal/media/manager.go index 8032ab42d..9ca450141 100644 --- a/internal/media/manager.go +++ b/internal/media/manager.go @@ -37,7 +37,17 @@ import ( // Manager provides an interface for managing media: parsing, storing, and retrieving media objects like photos, videos, and gifs. type Manager interface { - ProcessMedia(ctx context.Context, data []byte, accountID string) (*Media, error) + // ProcessMedia begins the process of decoding and storing the given data as a piece of media (aka an attachment). + // It will return a pointer to a Media struct upon which further actions can be performed, such as getting + // the finished media, thumbnail, decoded bytes, attachment, and setting additional fields. + // + // accountID should be the account that the media belongs to. + // + // RemoteURL is optional, and can be an empty string. Setting this to a non-empty string indicates that + // the piece of media originated on a remote instance and has been dereferenced to be cached locally. + ProcessMedia(ctx context.Context, data []byte, accountID string, remoteURL string) (*Media, error) + + ProcessEmoji(ctx context.Context, data []byte, accountID string, remoteURL string) (*Media, error) } type manager struct { @@ -70,7 +80,7 @@ func New(database db.DB, storage *kv.KVStore) (Manager, error) { INTERFACE FUNCTIONS */ -func (m *manager) ProcessMedia(ctx context.Context, data []byte, accountID string) (*Media, error) { +func (m *manager) ProcessMedia(ctx context.Context, data []byte, accountID string, remoteURL string) (*Media, error) { contentType, err := parseContentType(data) if err != nil { return nil, err @@ -85,7 +95,7 @@ func (m *manager) ProcessMedia(ctx context.Context, data []byte, accountID strin switch mainType { case mimeImage: - media, err := m.preProcessImage(ctx, data, contentType, accountID) + media, err := m.preProcessImage(ctx, data, contentType, accountID, remoteURL) if err != nil { return nil, err } @@ -97,7 +107,7 @@ func (m *manager) ProcessMedia(ctx context.Context, data []byte, accountID strin return default: // start preloading the media for the caller's convenience - media.PreLoad(innerCtx) + media.preLoad(innerCtx) } }) @@ -107,8 +117,12 @@ func (m *manager) ProcessMedia(ctx context.Context, data []byte, accountID strin } } +func (m *manager) ProcessEmoji(ctx context.Context, data []byte, accountID string, remoteURL string) (*Media, error) { + return nil, nil +} + // preProcessImage initializes processing -func (m *manager) preProcessImage(ctx context.Context, data []byte, contentType string, accountID string) (*Media, error) { +func (m *manager) preProcessImage(ctx context.Context, data []byte, contentType string, accountID string, remoteURL string) (*Media, error) { if !supportedImage(contentType) { return nil, fmt.Errorf("image type %s not supported", contentType) } @@ -128,6 +142,7 @@ func (m *manager) preProcessImage(ctx context.Context, data []byte, contentType ID: id, UpdatedAt: time.Now(), URL: uris.GenerateURIForAttachment(accountID, string(TypeAttachment), string(SizeOriginal), id, extension), + RemoteURL: remoteURL, Type: gtsmodel.FileTypeImage, AccountID: accountID, Processing: 0, |