Fix download file extensions when Immich serves WebP previews
With maxDownloadQuality=preview and Immich generating WebP previews, the zip entries and per-asset downloads were named .jpg while carrying WebP bytes. Previews, converted fullsize images and transcodes follow the server's image settings, so derive the extension from the upstream content-type for every non-/original endpoint, via a shared servedMimeFrom() in gallery/sizing.ts.
This commit is contained in:
@@ -53,10 +53,9 @@ function withMimeExtension (filename: string, mime: string | undefined): string
|
||||
/**
|
||||
* Generate a filename for the downloaded asset based on the configuration option chosen.
|
||||
*
|
||||
* The extension reflects what bytes the user will receive, not what the
|
||||
* original was - when Immich downgrades an image-original to preview (see
|
||||
* resolveImageEndpoint), the served bytes are JPEG even if the original is
|
||||
* HEIC/DNG/RAW, and the filename must match the bytes.
|
||||
* The extension reflects the served bytes, not the original: converted
|
||||
* bytes follow Immich's image settings, so pass the upstream content-type
|
||||
* as `servedMimeOverride`.
|
||||
*
|
||||
* @param asset
|
||||
* @param [servedSize] - what size Immich will actually serve. Defaults to
|
||||
|
||||
@@ -165,3 +165,13 @@ function endpointFor (size: ImageSize, asset: Asset, attachment: boolean): Image
|
||||
return { subpath: '/thumbnail', sizeQueryParam: 'preview', attachment, servedSize: ImageSize.preview }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Served content-type for filename derivation: everything but /original is
|
||||
* Immich-generated (previews can be WebP), so the response headers are the
|
||||
* only reliable extension signal.
|
||||
*/
|
||||
export function servedMimeFrom (subpath: string, response: globalThis.Response): string | undefined {
|
||||
if (subpath === '/original') return undefined
|
||||
return (response.headers.get('content-type') || '').split(';')[0].trim() || undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user