feat: compress uploads and serve resized image variants via /api/img

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
mahmood
2026-11-14 15:07:11 +03:30
co-authored by Cursor
parent b71fb678be
commit 3fe0a930c7
32 changed files with 976 additions and 52 deletions
+16
View File
@@ -0,0 +1,16 @@
// Uploaded images through the API's resize endpoint (GET /api/img/:file?w=).
// Anything that is not a plain upload path (blob:, data:, bundled assets,
// absolute URLs) is returned untouched.
const UPLOAD_PREFIXES = ['/uploads/', '/api/uploads/']
/** Must match IMAGE_WIDTHS in apps/api image-variants.service.ts. */
export type ImageWidth = 200 | 400 | 600 | 800 | 1200 | 1600
export function imageUrl(url: string | null | undefined, width: ImageWidth): string | undefined {
if (!url) return undefined
const prefix = UPLOAD_PREFIXES.find((p) => url.startsWith(p))
if (!prefix) return url
const name = url.slice(prefix.length)
if (!name || name.includes('/')) return url
return `/api/img/${encodeURIComponent(name)}?w=${width}`
}