feat: serve width-bounded thumbnail variants for image grids
Add /files/{key}?w=<px>: the endpoint decodes JPEG/PNG sources, downscales to
a width snapped to a small allow-list (aspect-preserving, never upscaling),
caches the result under a thumbs/ prefix, and serves it — so cover grids
download ~KB instead of the 1–5 MB original. Cover handlers purge cached
variants when a cover (whose key is reused) is replaced or deleted. Frontend
grids use new thumbUrl/thumbSrcset helpers (MangaCard with responsive srcset).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,25 @@ export function fileUrl(key: string): string {
|
||||
return `${BASE}/v1/files/${encoded}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL to a width-bounded thumbnail variant of a stored image (the backend
|
||||
* `/files/{key}?w=` endpoint). Grids use this so a cover downloads ~KB instead
|
||||
* of the 1–5 MB original; the backend snaps `width` to a small allow-list and
|
||||
* caches the result.
|
||||
*/
|
||||
export function thumbUrl(key: string, width: number): string {
|
||||
return `${fileUrl(key)}?w=${width}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A `srcset` string over the candidate `widths` for `key`, e.g.
|
||||
* `.../files/k?w=320 320w, .../files/k?w=480 480w`. Pair with a `sizes`
|
||||
* attribute so the browser picks the right variant for the rendered size.
|
||||
*/
|
||||
export function thumbSrcset(key: string, widths: number[]): string {
|
||||
return widths.map((w) => `${thumbUrl(key, w)} ${w}w`).join(', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an API URL for non-`fetch` consumers (e.g. `EventSource` for SSE),
|
||||
* applying the same `VITE_API_BASE` prefix as `request()`. `path` is the
|
||||
|
||||
Reference in New Issue
Block a user