diff options
author | 2024-07-17 15:26:33 +0000 | |
---|---|---|
committer | 2024-07-17 15:26:33 +0000 | |
commit | 72ba5666a6ffd06ccdfd2db8dacc47de7f777a4c (patch) | |
tree | ac8c71af4f9a57c0233ffd30f8867d02616c46cc /internal/media/processingemoji.go | |
parent | [feature] Allow users to set default interaction policies per status visibili... (diff) | |
download | gotosocial-72ba5666a6ffd06ccdfd2db8dacc47de7f777a4c.tar.xz |
[chore] media pipeline improvements (#3110)
* don't set emoji / media image paths on failed download, migrate FileType from string to integer
* fix incorrect uses of util.PtrOr, fix returned frontend media
* fix migration not setting arguments correctly in where clause
* fix not providing default with not null column
* whoops
* ensure a default gets set for media attachment file type
* remove the exclusive flag from writing files in disk storage
* rename PtrOr -> PtrOrZero, and rename PtrValueOr -> PtrOrValue to match
* slight wording changes
* use singular / plural word forms (no parentheses), is better for screen readers
* update testmodels with unknown media type to have unset file details, update attachment focus handling converting to frontend, update tests
* store first instance in ffmpeg wasm pool, fill remaining with closed instances
Diffstat (limited to 'internal/media/processingemoji.go')
-rw-r--r-- | internal/media/processingemoji.go | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go index 996a3aa03..f4265759b 100644 --- a/internal/media/processingemoji.go +++ b/internal/media/processingemoji.go @@ -26,7 +26,6 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" - "github.com/superseriousbusiness/gotosocial/internal/regexes" "github.com/superseriousbusiness/gotosocial/internal/storage" "github.com/superseriousbusiness/gotosocial/internal/uris" "github.com/superseriousbusiness/gotosocial/internal/util" @@ -36,6 +35,7 @@ import ( // various functions for retrieving data from the process. type ProcessingEmoji struct { emoji *gtsmodel.Emoji // processing emoji details + instAccID string // instance account ID newPathID string // new emoji path ID to use when being refreshed dataFn DataFunc // load-data function, returns media stream done bool // done is set when process finishes with non ctx canceled type error @@ -191,21 +191,24 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { pathID = p.emoji.ID } - // Determine instance account ID from generated image static path. - instanceAccID, ok := getInstanceAccountID(p.emoji.ImageStaticPath) - if !ok { - return gtserror.Newf("invalid emoji static path; no instance account id: %s", p.emoji.ImageStaticPath) - } - - // Calculate final media attachment file path. + // Calculate final emoji media file path. p.emoji.ImagePath = uris.StoragePathForAttachment( - instanceAccID, + p.instAccID, string(TypeEmoji), string(SizeOriginal), pathID, ext, ) + // Calculate final emoji static media file path. + p.emoji.ImageStaticPath = uris.StoragePathForAttachment( + p.instAccID, + string(TypeEmoji), + string(SizeStatic), + pathID, + "png", + ) + // Copy temporary file into storage at path. filesz, err := p.mgr.state.Storage.PutFile(ctx, p.emoji.ImagePath, @@ -228,19 +231,31 @@ func (p *ProcessingEmoji) store(ctx context.Context) error { p.emoji.ImageFileSize = int(filesz) p.emoji.ImageStaticFileSize = int(staticsz) - // Fill in remaining emoji data now it's stored. + // Generate an emoji media static URL. p.emoji.ImageURL = uris.URIForAttachment( - instanceAccID, + p.instAccID, string(TypeEmoji), string(SizeOriginal), pathID, ext, ) + // Generate an emoji image static URL. + p.emoji.ImageStaticURL = uris.URIForAttachment( + p.instAccID, + string(TypeEmoji), + string(SizeStatic), + pathID, + "png", + ) + // Get mimetype for the file container // type, falling back to generic data. p.emoji.ImageContentType = getMimeType(ext) + // Set the known emoji static content type. + p.emoji.ImageStaticContentType = "image/png" + // We can now consider this cached. p.emoji.Cached = util.Ptr(true) @@ -268,16 +283,16 @@ func (p *ProcessingEmoji) cleanup(ctx context.Context) { } } + // Unset processor-calculated fields. + p.emoji.ImageStaticContentType = "" + p.emoji.ImageStaticFileSize = 0 + p.emoji.ImageStaticPath = "" + p.emoji.ImageStaticURL = "" + p.emoji.ImageContentType = "" + p.emoji.ImageFileSize = 0 + p.emoji.ImagePath = "" + p.emoji.ImageURL = "" + // Ensure marked as not cached. p.emoji.Cached = util.Ptr(false) } - -// getInstanceAccountID determines the instance account ID from -// emoji static image storage path. returns false on failure. -func getInstanceAccountID(staticPath string) (string, bool) { - matches := regexes.FilePath.FindStringSubmatch(staticPath) - if len(matches) < 2 { - return "", false - } - return matches[1], true -} |