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:
@@ -24,6 +24,18 @@ function videoAsset (originalFileName: string, originalMimeType = 'video/x-msvid
|
||||
}
|
||||
}
|
||||
|
||||
function imageAsset (originalFileName: string, originalMimeType = 'image/heic'): Asset {
|
||||
return {
|
||||
id: 'asset-id',
|
||||
key: 'k',
|
||||
keyType: KeyType.key,
|
||||
type: AssetType.image,
|
||||
isTrashed: false,
|
||||
originalFileName,
|
||||
originalMimeType
|
||||
}
|
||||
}
|
||||
|
||||
describe('getFilename servedMime override (playback-fallback downloads)', () => {
|
||||
it('swaps the extension to match the transcoded bytes', () => {
|
||||
expect(getFilename(videoAsset('clip.avi'), ImageSize.original, 'video/mp4')).toBe('clip.mp4')
|
||||
@@ -43,3 +55,17 @@ describe('getFilename servedMime override (playback-fallback downloads)', () =>
|
||||
expect(getFilename(videoAsset('clip.avi'), ImageSize.original)).toBe('clip.avi')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getFilename converted-byte previews (e.g. WebP preview generation)', () => {
|
||||
it('swaps the extension to match the served preview bytes', () => {
|
||||
expect(getFilename(imageAsset('holiday.heic'), ImageSize.preview, 'image/webp')).toBe('holiday.webp')
|
||||
})
|
||||
|
||||
it('keeps a JPEG extension when the preview is JPEG', () => {
|
||||
expect(getFilename(imageAsset('holiday.heic'), ImageSize.preview, 'image/jpeg')).toBe('holiday.jpg')
|
||||
})
|
||||
|
||||
it('falls back to the hardcoded tier mime without an override', () => {
|
||||
expect(getFilename(imageAsset('holiday.heic'), ImageSize.preview)).toBe('holiday.jpg')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user