Prepping for v3.0 release
Fetch album assets from timeline endpoint is the major change
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { getShareByKey } from '../src/immich'
|
||||
import { KeyType } from '../src/types'
|
||||
|
||||
// 3.0-shaped responses: album `/shared-links/me` returns an empty assets[],
|
||||
// and the album's assets are enumerated from the timeline API. This exercises
|
||||
// the regression fix end-to-end through getShareByKey -> fetchShareByKey.
|
||||
|
||||
interface MockResponse {
|
||||
ok: boolean
|
||||
status: number
|
||||
headers: { get: (h: string) => string | null }
|
||||
json: () => Promise<unknown>
|
||||
}
|
||||
|
||||
function jsonResponse (body: unknown, status = 200): MockResponse {
|
||||
return {
|
||||
ok: status >= 200 && status < 300,
|
||||
status,
|
||||
headers: { get: (h: string) => (h.toLowerCase() === 'content-type' ? 'application/json' : null) },
|
||||
json: async () => body
|
||||
}
|
||||
}
|
||||
|
||||
const ALBUM_ID = '0aab733a-3cb4-416f-b4b9-f94906533aaa'
|
||||
|
||||
const sharedLinkResponse = (order?: string) => ({
|
||||
type: 'ALBUM',
|
||||
assets: [],
|
||||
allowDownload: true,
|
||||
expiresAt: null,
|
||||
showMetadata: true,
|
||||
key: 'real-key',
|
||||
album: {
|
||||
id: ALBUM_ID,
|
||||
albumName: 'Test album',
|
||||
albumThumbnailAssetId: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
order
|
||||
}
|
||||
})
|
||||
|
||||
const bucketsResponse = [{ timeBucket: '2026-06-01', count: 3 }]
|
||||
|
||||
// Columnar (struct-of-arrays). Index 1 is trashed and must be filtered out.
|
||||
const bucketResponse = {
|
||||
id: [
|
||||
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'cccccccc-cccc-cccc-cccc-cccccccccccc'
|
||||
],
|
||||
isImage: [true, true, false],
|
||||
ratio: [1.5, 0.5, 1],
|
||||
thumbhash: ['hashA', null, 'hashC'],
|
||||
isTrashed: [false, true, false],
|
||||
fileCreatedAt: ['2026-06-03T00:00:00.000Z', '2026-06-02T00:00:00.000Z', '2026-06-01T00:00:00.000Z']
|
||||
}
|
||||
|
||||
function routeFetch (sharedLink: unknown) {
|
||||
return vi.fn(async (url: string) => {
|
||||
if (url.includes('/shared-links/me')) return jsonResponse(sharedLink)
|
||||
if (url.includes('/timeline/buckets')) return jsonResponse(bucketsResponse)
|
||||
if (url.includes('/timeline/bucket')) return jsonResponse(bucketResponse)
|
||||
throw new Error('Unexpected fetch to ' + url)
|
||||
})
|
||||
}
|
||||
|
||||
let keyCounter = 0
|
||||
function uniqueKey () {
|
||||
// getShareByKey caches by key; a fresh key per test avoids cross-test reuse.
|
||||
return 'album-key-' + (keyCounter++)
|
||||
}
|
||||
|
||||
describe('album timeline enumeration (Immich 3.0)', () => {
|
||||
beforeEach(() => {
|
||||
process.env.IMMICH_URL = 'http://immich.test'
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('populates grid assets from the timeline and filters trashed', async () => {
|
||||
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse()))
|
||||
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
|
||||
|
||||
expect(result.valid).toBe(true)
|
||||
const assets = result.link!.assets
|
||||
// 3 assets, 1 trashed -> 2 survive
|
||||
expect(assets.map(a => a.id)).toEqual([
|
||||
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
'cccccccc-cccc-cccc-cccc-cccccccccccc'
|
||||
])
|
||||
// grid assets are flagged for lazy detail loading
|
||||
expect(assets.every(a => a.needsDetail)).toBe(true)
|
||||
// type derived from isImage
|
||||
expect(assets[0].type).toBe('IMAGE')
|
||||
expect(assets[1].type).toBe('VIDEO')
|
||||
// thumbhash carried through; null becomes undefined
|
||||
expect(assets[0].thumbhash).toBe('hashA')
|
||||
// dimensions derived from ratio (landscape 1.5 -> wider than tall)
|
||||
expect(assets[0].width!).toBeGreaterThan(assets[0].height!)
|
||||
})
|
||||
|
||||
it('stamps the share key/keyType onto every asset', async () => {
|
||||
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse()))
|
||||
const key = uniqueKey()
|
||||
const result = await getShareByKey(key, undefined, KeyType.key)
|
||||
expect(result.link!.assets.every(a => a.key === key && a.keyType === KeyType.key)).toBe(true)
|
||||
})
|
||||
|
||||
it('respects album sort order asc', async () => {
|
||||
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse('asc')))
|
||||
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
|
||||
const dates = result.link!.assets.map(a => a.fileCreatedAt)
|
||||
expect(dates).toEqual([...dates].sort())
|
||||
})
|
||||
|
||||
it('respects album sort order desc', async () => {
|
||||
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse('desc')))
|
||||
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
|
||||
const dates = result.link!.assets.map(a => a.fileCreatedAt)
|
||||
expect(dates).toEqual([...dates].sort().reverse())
|
||||
})
|
||||
|
||||
it('keeps the album cover id from /shared-links/me (no extra album fetch)', async () => {
|
||||
vi.stubGlobal('fetch', routeFetch(sharedLinkResponse()))
|
||||
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
|
||||
expect(result.link!.album!.albumThumbnailAssetId).toBe('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
|
||||
})
|
||||
|
||||
it('is invalid when the album share has no album id', async () => {
|
||||
const noId = { ...sharedLinkResponse(), album: undefined }
|
||||
vi.stubGlobal('fetch', routeFetch(noId))
|
||||
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
|
||||
expect(result.valid).toBe(false)
|
||||
})
|
||||
|
||||
it('is invalid (not cached empty) when timeline enumeration fails upstream', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn(async (url: string) => {
|
||||
if (url.includes('/shared-links/me')) return jsonResponse(sharedLinkResponse())
|
||||
if (url.includes('/timeline/buckets')) return jsonResponse({ message: 'boom' }, 500)
|
||||
throw new Error('Unexpected fetch to ' + url)
|
||||
}))
|
||||
const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)
|
||||
expect(result.valid).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,80 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { buildAssetMetadata } from '../src/gallery/metadata'
|
||||
import { loadConfig } from '../src/config/loader'
|
||||
import { Asset, AssetType, KeyType, SharedLink } from '../src/types'
|
||||
|
||||
// buildAssetMetadata is the lazy-flow counterpart to the gallery builder's
|
||||
// per-item baking; it must apply the same showMetadata kill-switch and
|
||||
// ipp.showMetadata.* gating so nothing leaks that the operator didn't opt into.
|
||||
|
||||
function setConfig (config: unknown) {
|
||||
process.env.CONFIG = JSON.stringify(config)
|
||||
loadConfig()
|
||||
}
|
||||
|
||||
const asset = (): Asset => ({
|
||||
id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
key: 'k',
|
||||
keyType: KeyType.key,
|
||||
type: AssetType.image,
|
||||
isTrashed: false,
|
||||
originalFileName: 'IMG_1234.HEIC',
|
||||
originalMimeType: 'image/heic',
|
||||
exifInfo: {
|
||||
description: 'A nice photo',
|
||||
make: 'Canon',
|
||||
model: 'EOS R5',
|
||||
city: 'Paris',
|
||||
country: 'France',
|
||||
latitude: 48.8,
|
||||
longitude: 2.3
|
||||
}
|
||||
})
|
||||
|
||||
const share = (showMetadata?: boolean): SharedLink => ({
|
||||
key: 'k',
|
||||
keyType: KeyType.key,
|
||||
type: 'ALBUM',
|
||||
assets: [],
|
||||
showMetadata,
|
||||
expiresAt: null
|
||||
})
|
||||
|
||||
describe('buildAssetMetadata', () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.CONFIG
|
||||
loadConfig()
|
||||
})
|
||||
|
||||
it('returns exif when the matching per-field flags are enabled', () => {
|
||||
setConfig({ ipp: { showMetadata: { exif: { make: true, model: true } } } })
|
||||
const meta = buildAssetMetadata(asset(), share())
|
||||
expect(meta.exif?.make).toBe('Canon')
|
||||
expect(meta.exif?.model).toBe('EOS R5')
|
||||
// location not enabled -> absent
|
||||
expect(meta.exif?.city).toBeUndefined()
|
||||
})
|
||||
|
||||
it('returns description when a description surface is enabled', () => {
|
||||
setConfig({ ipp: { showMetadata: { description: { sidebar: true } } } })
|
||||
const meta = buildAssetMetadata(asset(), share())
|
||||
expect(meta.description).toBe('A nice photo')
|
||||
})
|
||||
|
||||
it('suppresses everything when the share showMetadata is false', () => {
|
||||
setConfig({ ipp: { showMetadata: { exif: { make: true }, description: { sidebar: true } } } })
|
||||
const meta = buildAssetMetadata(asset(), share(false))
|
||||
expect(meta.exif).toBeUndefined()
|
||||
expect(meta.description).toBeUndefined()
|
||||
// filename is still returned (not gated by showMetadata - it's a download
|
||||
// affordance, mirroring the eager builder's downloadFilename)
|
||||
expect(meta.downloadFilename).toBeTruthy()
|
||||
})
|
||||
|
||||
it('always returns a download filename', () => {
|
||||
setConfig({})
|
||||
const meta = buildAssetMetadata(asset(), share())
|
||||
// HEIC original served as preview JPEG when downloadOriginalPhoto defaults on
|
||||
expect(meta.downloadFilename).toMatch(/IMG_1234/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { filenameFromContentDisposition } from '../src/stream/download'
|
||||
|
||||
// Used by the zip download path to recover the real filename for album grid
|
||||
// assets (which arrive without originalFileName) from the /original response.
|
||||
|
||||
describe('filenameFromContentDisposition', () => {
|
||||
it('prefers the RFC 5987 filename* form and percent-decodes it', () => {
|
||||
const header = "attachment; filename=\"IMG.jpg\"; filename*=UTF-8''Photo%20%C3%A9t%C3%A9.jpg"
|
||||
expect(filenameFromContentDisposition(header)).toBe('Photo été.jpg')
|
||||
})
|
||||
|
||||
it('falls back to the plain quoted filename', () => {
|
||||
expect(filenameFromContentDisposition('attachment; filename="IMG_1234.HEIC"')).toBe('IMG_1234.HEIC')
|
||||
})
|
||||
|
||||
it('handles an unquoted plain filename', () => {
|
||||
expect(filenameFromContentDisposition('attachment; filename=clip.mp4')).toBe('clip.mp4')
|
||||
})
|
||||
|
||||
it('returns undefined when no filename is present', () => {
|
||||
expect(filenameFromContentDisposition('attachment')).toBeUndefined()
|
||||
expect(filenameFromContentDisposition(null)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user