diff options
author | 2024-11-04 13:58:15 +0000 | |
---|---|---|
committer | 2024-11-04 14:58:15 +0100 | |
commit | 8f288f1689376a8cf6ab7f431e862eb870765342 (patch) | |
tree | 42442833af06948eb3ec9f7710ed35b809cd6992 /internal/media/thumbnail.go | |
parent | [chore]: Bump github.com/minio/minio-go/v7 from 7.0.79 to 7.0.80 (#3511) (diff) | |
download | gotosocial-8f288f1689376a8cf6ab7f431e862eb870765342.tar.xz |
[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
Diffstat (limited to 'internal/media/thumbnail.go')
-rw-r--r-- | internal/media/thumbnail.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/internal/media/thumbnail.go b/internal/media/thumbnail.go index 322af8d7e..f1c7c678e 100644 --- a/internal/media/thumbnail.go +++ b/internal/media/thumbnail.go @@ -84,17 +84,21 @@ func generateThumb( needBlurhash bool, ) ( outpath string, + mimeType string, blurhash string, err error, ) { var ext string + // Default type is webp. + mimeType = "image/webp" + // Generate thumb output path REPLACING extension. if i := strings.IndexByte(filepath, '.'); i != -1 { outpath = filepath[:i] + "_thumb.webp" ext = filepath[i+1:] // old extension } else { - return "", "", gtserror.New("input file missing extension") + return "", "", "", gtserror.New("input file missing extension") } // Check for the few media types we @@ -106,6 +110,7 @@ func generateThumb( // Replace the "webp" with "jpeg", as we'll // use our native Go thumbnailing generation. outpath = outpath[:len(outpath)-4] + "jpeg" + mimeType = "image/jpeg" log.Debug(ctx, "generating thumb from jpeg") blurhash, err := generateNativeThumb( @@ -117,7 +122,7 @@ func generateThumb( jpeg.Decode, needBlurhash, ) - return outpath, blurhash, err + return outpath, mimeType, blurhash, err // We specifically only allow generating native // thumbnails from gif IF it doesn't contain an @@ -128,6 +133,7 @@ func generateThumb( // Replace the "webp" with "jpeg", as we'll // use our native Go thumbnailing generation. outpath = outpath[:len(outpath)-4] + "jpeg" + mimeType = "image/jpeg" log.Debug(ctx, "generating thumb from gif") blurhash, err := generateNativeThumb( @@ -139,7 +145,7 @@ func generateThumb( gif.Decode, needBlurhash, ) - return outpath, blurhash, err + return outpath, mimeType, blurhash, err // We specifically only allow generating native // thumbnails from png IF it doesn't contain an @@ -150,6 +156,7 @@ func generateThumb( // Replace the "webp" with "jpeg", as we'll // use our native Go thumbnailing generation. outpath = outpath[:len(outpath)-4] + "jpeg" + mimeType = "image/jpeg" log.Debug(ctx, "generating thumb from png") blurhash, err := generateNativeThumb( @@ -161,7 +168,7 @@ func generateThumb( png.Decode, needBlurhash, ) - return outpath, blurhash, err + return outpath, mimeType, blurhash, err // We specifically only allow generating native // thumbnails from webp IF it doesn't contain an @@ -172,6 +179,7 @@ func generateThumb( // Replace the "webp" with "jpeg", as we'll // use our native Go thumbnailing generation. outpath = outpath[:len(outpath)-4] + "jpeg" + mimeType = "image/jpeg" log.Debug(ctx, "generating thumb from webp") blurhash, err := generateNativeThumb( @@ -183,7 +191,7 @@ func generateThumb( webp.Decode, needBlurhash, ) - return outpath, blurhash, err + return outpath, mimeType, blurhash, err } // The fallback for thumbnail generation, which @@ -196,18 +204,18 @@ func generateThumb( height, pixfmt, ); err != nil { - return outpath, "", err + return outpath, "", "", err } if needBlurhash { // Generate new blurhash from webp output thumb. blurhash, err = generateWebpBlurhash(outpath) if err != nil { - return outpath, "", gtserror.Newf("error generating blurhash: %w", err) + return outpath, "", "", gtserror.Newf("error generating blurhash: %w", err) } } - return outpath, blurhash, err + return outpath, mimeType, blurhash, nil } // generateNativeThumb generates a thumbnail |