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:
@@ -3,6 +3,7 @@ import { Writable } from 'stream'
|
||||
import { once } from 'events'
|
||||
import type { Response } from 'express-serve-static-core'
|
||||
import { downloadAssets } from '../src/stream/download'
|
||||
import { loadConfig } from '../src/config/loader'
|
||||
import { Asset, AssetType, KeyType, SharedLink } from '../src/types'
|
||||
|
||||
/*
|
||||
@@ -16,8 +17,15 @@ dies mid-stream).
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
vi.restoreAllMocks()
|
||||
delete process.env.CONFIG
|
||||
loadConfig()
|
||||
})
|
||||
|
||||
function setConfig (config: unknown) {
|
||||
process.env.CONFIG = JSON.stringify(config)
|
||||
loadConfig()
|
||||
}
|
||||
|
||||
function makeAsset (id: string): Asset {
|
||||
return {
|
||||
id,
|
||||
@@ -276,4 +284,19 @@ describe('downloadAssets', () => {
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1)
|
||||
expect(signals.every(s => s.aborted)).toBe(true)
|
||||
}, 10_000)
|
||||
|
||||
it('names a preview-clamped entry after the served bytes, not .jpg (WebP preview generation)', async () => {
|
||||
// Immich generates previews in an operator-chosen format; with WebP
|
||||
// selected and maxDownloadQuality=preview, the zip entry must be .webp.
|
||||
setConfig({ ipp: { maxDownloadQuality: 'preview' } })
|
||||
const fetchMock = vi.fn(async () => new globalThis.Response(new Uint8Array(2048), {
|
||||
status: 200,
|
||||
headers: { 'content-type': 'image/webp' }
|
||||
}))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const res = new FakeRes()
|
||||
await downloadAssets(asResponse(res), share, [makeAsset('a1')])
|
||||
expect(String(fetchMock.mock.calls[0][0])).toContain('size=preview')
|
||||
expect(centralDirectory(res.output)).toEqual([{ name: 'a1.webp', size: 2048 }])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user