From 68e442fff5aa06b1207902a321d5b0ce5da363b6 Mon Sep 17 00:00:00 2001 From: ralksta Date: Sat, 7 Mar 2026 09:37:48 +0100 Subject: [PATCH] fix: revert experimental ImmichClient refactoring and restore absolute baseline for image loading --- lib/__tests__/immich.test.ts | 8 +++----- lib/immich.ts | 36 ++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/__tests__/immich.test.ts b/lib/__tests__/immich.test.ts index e0051b3..2f25fb9 100644 --- a/lib/__tests__/immich.test.ts +++ b/lib/__tests__/immich.test.ts @@ -39,11 +39,10 @@ describe('ImmichClient', () => { // Access private method via any casting for testing const result = await (immich as any).request('/test'); - expect(result.data).toEqual({ foo: 'bar' }); - expect(result.error).toBeNull(); + expect(result).toEqual({ foo: 'bar' }); }); - it('returns error on non-ok response', async () => { + it('returns null on non-ok response', async () => { mockFetch.mockResolvedValueOnce({ ok: false, status: 404, @@ -51,8 +50,7 @@ describe('ImmichClient', () => { }); const result = await (immich as any).request('/test'); - expect(result.data).toBeNull(); - expect(result.error).toContain('404 Not Found'); + expect(result).toBeNull(); }); }); diff --git a/lib/immich.ts b/lib/immich.ts index b25d7d3..f8c2c04 100644 --- a/lib/immich.ts +++ b/lib/immich.ts @@ -77,8 +77,6 @@ export interface SubpageSummary { coverAssetId: string | null; } -export type ImmichResult = { data: T | null; error: string | null }; - // ── API Client ───────────────────────────────────────────────── class ImmichClient { @@ -91,7 +89,7 @@ class ImmichClient { /** * Make an authenticated request to the Immich API. */ - private async request(endpoint: string): Promise> { + private async request(endpoint: string): Promise { const url = `${this.config.immich.apiUrl}${endpoint}`; try { const res = await fetch(url, { @@ -102,20 +100,18 @@ class ImmichClient { }); if (!res.ok) { - const error = `[Immich] ${res.status} ${res.statusText} for ${endpoint}`; - console.error(error); - return { data: null, error }; + console.error(`[Immich] ${res.status} ${res.statusText} for ${endpoint}`); + return null; } const contentType = res.headers.get('Content-Type') || ''; if (contentType.includes('application/json')) { - return { data: (await res.json()) as T, error: null }; + return (await res.json()) as T; } - return { data: null, error: 'Invalid response format (expected JSON)' }; - } catch (err) { - const error = `[Immich] Failed to reach ${url}: ${err instanceof Error ? err.message : 'Unknown error'}`; - console.error(error); - return { data: null, error }; + return null; + } catch (error) { + console.error(`[Immich] Failed to reach ${url}:`, error); + return null; } } @@ -164,8 +160,8 @@ class ImmichClient { const cached = cache.get(cacheKey); if (cached) return cached; - const { data: all, error } = await this.request('/albums?shared=true'); - if (error || !all) return []; + const all = await this.request('/albums?shared=true'); + if (!all) return []; const allowedIds = new Set(this.config.albums); const filtered = all @@ -280,8 +276,8 @@ class ImmichClient { const cached = cache.get(cacheKey); if (cached) return cached; - const { data: album, error } = await this.request(`/albums/${encodeURIComponent(albumId)}`); - if (error || !album) return null; + const album = await this.request(`/albums/${encodeURIComponent(albumId)}`); + if (!album) return null; // Filter out trashed assets album.assets = (album.assets || []).filter((a) => !a.isTrashed); @@ -329,8 +325,8 @@ class ImmichClient { const cached = cache.get(cacheKey); if (cached) return cached; - const { data: asset, error } = await this.request(`/assets/${encodeURIComponent(assetId)}`); - if (error || !asset) return null; + const asset = await this.request(`/assets/${encodeURIComponent(assetId)}`); + if (!asset) return null; cache.set(cacheKey, asset, this.config.cacheTtl); return asset; @@ -410,8 +406,8 @@ class ImmichClient { * Check if the Immich server is reachable. */ async ping(): Promise { - const { data } = await this.request<{ res: string }>('/server/ping'); - return !!data; + const res = await this.request<{ res: string }>('/server/ping'); + return !!res; } }