[bugfix] determine mime-type to use during ffprobe evaluation stage, don't bother checking against file extension (#3506)

* determine mime-type to use during ffprobe evaluation stage, don't bother rechecking by file extension

* set mjpeg content-type

* fix up tests expecting differing default values
This commit is contained in:
kim 2024-11-04 13:58:15 +00:00 committed by GitHub
commit 8f288f1689
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 85 additions and 1378 deletions

View file

@ -186,8 +186,8 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
p.media.FileMeta.Original.Duration = util.PtrIf(float32(result.duration))
p.media.FileMeta.Original.Bitrate = util.PtrIf(result.bitrate)
// Set media type from ffprobe format data.
p.media.Type, ext = result.GetFileType()
// Set generic media type and mimetype from ffprobe format data.
p.media.Type, p.media.File.ContentType, ext = result.GetFileType()
// Add file extension to path.
newpath := temppath + "." + ext
@ -236,10 +236,10 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
// Determine if blurhash needs generating.
needBlurhash := (p.media.Blurhash == "")
var newBlurhash string
var newBlurhash, mimeType string
// Generate thumbnail, and new blurhash if need from media.
thumbpath, newBlurhash, err = generateThumb(ctx, temppath,
// Generate thumbnail, and new blurhash if needed from temp media.
thumbpath, mimeType, newBlurhash, err = generateThumb(ctx, temppath,
thumbWidth,
thumbHeight,
result.orientation,
@ -250,6 +250,9 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
return gtserror.Newf("error generating image thumb: %w", err)
}
// Set generated thumbnail's mimetype.
p.media.Thumbnail.ContentType = mimeType
if needBlurhash {
// Set newly determined blurhash.
p.media.Blurhash = newBlurhash
@ -265,10 +268,6 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
ext,
)
// Get mimetype for the file container
// type, falling back to generic data.
p.media.File.ContentType = getMimeType(ext)
// Copy temporary file into storage at path.
filesz, err := p.mgr.state.Storage.PutFile(ctx,
p.media.File.Path,
@ -295,9 +294,6 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
thumbExt,
)
// Determine thumbnail content-type from thumb ext.
p.media.Thumbnail.ContentType = getMimeType(thumbExt)
// Copy thumbnail file into storage at path.
thumbsz, err := p.mgr.state.Storage.PutFile(ctx,
p.media.Thumbnail.Path,