diff --git a/app/src/immich.ts b/app/src/immich.ts index 89d5a22..4b8c9f4 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -419,6 +419,19 @@ function timelineBucketToAssets (bucket: TimelineBucketAssets): Asset[] { return assets } +/** + * Normalise a `/timeline/buckets` key for the `/timeline/bucket` lookup. + * + * Immich lists buckets as bare UTC dates (`2026-06-01`) but matches the + * lookup by casting the string back to a timestamp in Postgres's session + * timezone. On a non-UTC database that lands in the previous month and the + * bucket comes back empty - every album shows zero photos #260. The explicit + * `T00:00:00.000Z` form is what Immich's web client sends: (immich-app/immich#22672). + */ +export function utcBucketKey (timeBucket: string): string { + return /^\d{4}-\d{2}-\d{2}$/.test(timeBucket) ? timeBucket + 'T00:00:00.000Z' : timeBucket +} + /** * Enumerate an album's assets via Immich's timeline API, scoped by album id + * shared-link key. `GET /timeline/buckets` lists the time buckets (months), @@ -446,7 +459,7 @@ async function fetchAlbumAssets (albumId: string, keyType: KeyType, key: string, const perBucket = await Promise.all((buckets || []).map(async (bucket) => { const res = await fetch(buildUrl(apiUrl() + '/timeline/bucket', { albumId, - timeBucket: bucket.timeBucket, + timeBucket: utcBucketKey(bucket.timeBucket), [keyType]: key }), { headers }) if (!res.ok) { diff --git a/app/tests/albumTimeline.test.ts b/app/tests/albumTimeline.test.ts index f75fb12..1910c1f 100644 --- a/app/tests/albumTimeline.test.ts +++ b/app/tests/albumTimeline.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest' -import { getShareByKey } from '../src/immich' +import { getShareByKey, utcBucketKey } from '../src/immich' import { KeyType } from '../src/types' // 3.0-shaped responses: album `/shared-links/me` returns an empty assets[], @@ -101,6 +101,22 @@ describe('album timeline enumeration (Immich 3.0)', () => { expect(assets[0].width!).toBeGreaterThan(assets[0].height!) }) + it('requests each bucket with an explicit UTC key so non-UTC databases match (#260)', async () => { + const fetchMock = routeFetch(sharedLinkResponse()) + vi.stubGlobal('fetch', fetchMock) + await getShareByKey(uniqueKey(), undefined, KeyType.key) + + const bucketCalls = fetchMock.mock.calls.map(c => String(c[0])).filter(u => u.includes('/timeline/bucket?')) + expect(bucketCalls).toHaveLength(1) + expect(new URL(bucketCalls[0]).searchParams.get('timeBucket')).toBe('2026-06-01T00:00:00.000Z') + }) + + it('utcBucketKey pads bare dates and leaves anything else alone', () => { + expect(utcBucketKey('2026-06-01')).toBe('2026-06-01T00:00:00.000Z') + expect(utcBucketKey('2026-06-01T00:00:00.000Z')).toBe('2026-06-01T00:00:00.000Z') + expect(utcBucketKey('')).toBe('') + }) + it('synthesises localDateTime from fileCreatedAt + localOffsetHours', async () => { vi.stubGlobal('fetch', routeFetch(sharedLinkResponse())) const result = await getShareByKey(uniqueKey(), undefined, KeyType.key)