From a02f6cdcd7ed1c038aa9afca915eea2518e1f1c9 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 23 Apr 2026 22:19:35 +0200 Subject: [PATCH] refactor(thumbnails): drop frontend URL-builder now that backend owns the convention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The helper had a single consumer (DocumentThumbnail) and its only job was to compose what the backend's Document.getThumbnailUrl() now produces. Deleting it locks the single-source-of-truth invariant — there is no longer a way to build a thumbnail URL on the client (#309). Co-Authored-By: Claude Opus 4.7 --- frontend/src/lib/thumbnails.test.ts | 37 ----------------------------- frontend/src/lib/thumbnails.ts | 18 -------------- 2 files changed, 55 deletions(-) delete mode 100644 frontend/src/lib/thumbnails.test.ts delete mode 100644 frontend/src/lib/thumbnails.ts diff --git a/frontend/src/lib/thumbnails.test.ts b/frontend/src/lib/thumbnails.test.ts deleted file mode 100644 index aad48268..00000000 --- a/frontend/src/lib/thumbnails.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { thumbnailUrl } from './thumbnails'; - -describe('thumbnailUrl', () => { - it('returns null when thumbnailKey is undefined', () => { - expect(thumbnailUrl({ id: 'abc' })).toBeNull(); - }); - - it('returns url without version param when thumbnailKey present but generatedAt missing', () => { - expect(thumbnailUrl({ id: 'abc', thumbnailKey: 'thumbnails/abc.jpg' })).toBe( - '/api/documents/abc/thumbnail' - ); - }); - - it('appends encoded cache-bust param when generatedAt present', () => { - const url = thumbnailUrl({ - id: 'abc', - thumbnailKey: 'thumbnails/abc.jpg', - thumbnailGeneratedAt: '2026-04-22T20:41:15.123456' - }); - expect(url).toBe('/api/documents/abc/thumbnail?v=2026-04-22T20%3A41%3A15.123456'); - }); - - it('different generatedAt produces different URL — enables cache-bust on file replace', () => { - const a = thumbnailUrl({ - id: 'x', - thumbnailKey: 'thumbnails/x.jpg', - thumbnailGeneratedAt: '2026-01-01T10:00:00' - }); - const b = thumbnailUrl({ - id: 'x', - thumbnailKey: 'thumbnails/x.jpg', - thumbnailGeneratedAt: '2026-01-01T11:00:00' - }); - expect(a).not.toBe(b); - }); -}); diff --git a/frontend/src/lib/thumbnails.ts b/frontend/src/lib/thumbnails.ts deleted file mode 100644 index 47a0a606..00000000 --- a/frontend/src/lib/thumbnails.ts +++ /dev/null @@ -1,18 +0,0 @@ -type ThumbnailDoc = { - id: string; - thumbnailKey?: string; - thumbnailGeneratedAt?: string; -}; - -/** - * Builds the URL for a document thumbnail image, or returns null when the document - * has no thumbnail yet. When `thumbnailGeneratedAt` is present it is appended as a - * `?v=…` query param so the browser / proxy cache is invalidated whenever the file - * is replaced (the backend regenerates thumbnails at the same S3 key on replace). - */ -export function thumbnailUrl(doc: ThumbnailDoc): string | null { - if (!doc.thumbnailKey) return null; - const base = `/api/documents/${doc.id}/thumbnail`; - if (!doc.thumbnailGeneratedAt) return base; - return `${base}?v=${encodeURIComponent(doc.thumbnailGeneratedAt)}`; -}