import { readFile } from "node:fs/promises"; import { photoFilePath, validPhotoDir, validPhotoFile } from "../../../../../_lib/photos"; export const dynamic = "force-dynamic"; export async function GET(_request: Request, { params }: { params: Promise<{ dir: string; file: string }> }) { const { dir, file } = await params; if (!validPhotoDir(dir) || !validPhotoFile(file)) return new Response("Not found", { status: 404 }); try { const data = await readFile(photoFilePath(dir, file)); return new Response(new Uint8Array(data), { headers: { "Content-Type": "image/jpeg", "Cache-Control": "public, max-age=31536000, immutable", "Content-Length": String(data.byteLength) }, }); } catch { return new Response("Not found", { status: 404 }); } }