diff --git a/src/components/LibraryApp.tsx b/src/components/LibraryApp.tsx index 3fdf788..6412511 100644 --- a/src/components/LibraryApp.tsx +++ b/src/components/LibraryApp.tsx @@ -66,7 +66,7 @@ export default function LibraryApp() { {items.map((v) => (
toggle(v.id)}> - + {sel.has(v.id) ? '✓' : ''}
rename(v.id, e.target.value)} /> diff --git a/src/pages/api/items/[id]/file.ts b/src/pages/api/items/[id]/file.ts index 13515e9..2ada5e3 100644 --- a/src/pages/api/items/[id]/file.ts +++ b/src/pages/api/items/[id]/file.ts @@ -7,15 +7,23 @@ export const prerender = false; // Streamt das Ergebnis- (oder Quell-)Bild aus dem Objektspeicher. export const GET: APIRoute = async ({ params, url, locals }) => { if (!locals.user) return new Response('Unauthorized', { status: 401 }); - const which = url.searchParams.get('src') === '1' ? 'source_path' : 'result_path'; - const item = await one(`SELECT ${which} AS path, filename, has_alpha FROM items WHERE id=$1`, [params.id]); - if (!item?.path) return new Response('Nicht gefunden', { status: 404 }); + const q = url.searchParams; + const wantThumb = q.get('thumb') === '1'; + const wantSrc = q.get('src') === '1'; + const item = await one( + `SELECT source_path, result_path, thumb_path, filename, has_alpha FROM items WHERE id=$1`, [params.id]); + // Vorschau: Thumbnail bevorzugen, sonst Ergebnis. Quelle nur explizit. + const path = wantSrc ? item?.source_path + : wantThumb ? (item?.thumb_path || item?.result_path) + : item?.result_path; + if (!path) return new Response('Nicht gefunden', { status: 404 }); try { - const buf = await getObject(item.path); - const download = url.searchParams.get('download') === '1'; + const buf = await getObject(path); + const download = q.get('download') === '1'; + const isWebp = path.endsWith('.webp'); return new Response(buf, { headers: { - 'Content-Type': item.has_alpha ? 'image/png' : 'image/png', + 'Content-Type': isWebp ? 'image/webp' : 'image/png', 'Cache-Control': 'private, max-age=300', ...(download ? { 'Content-Disposition': `attachment; filename="${item.filename || 'klarbild.png'}"` } : {}), },