import type { Action } from 'remix/router' import { readMediaFile } from '../../src/store/site-store.ts' import { getStorage } from '../data/site.ts' import type { routes } from '../routes.ts' /** * Serve one stored photo file. Photo ids are random and files never change * once written, so responses are immutable and cache for a year. */ export default { async handler(context) { const file = await readMediaFile( getStorage(context), context.params.photoId ?? '', `${context.params.width}.${context.params.ext}`, ) if (!file) return new Response('Not found', { status: 404 }) return new Response(file.bytes as Uint8Array, { headers: { 'Content-Type': file.contentType, 'Content-Length': String(file.bytes.length), 'Cache-Control': 'public, max-age=31536000, immutable', }, }) }, } satisfies Action