15 lines
595 B
TypeScript
15 lines
595 B
TypeScript
import { NextRequest } from "next/server";
|
|
import { serveImage } from "@/lib/api/serveAssets";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
export async function GET(req: NextRequest, ctx: { params: Promise<{ file: string }> }) {
|
|
const { file } = await ctx.params;
|
|
const url = new URL(req.url);
|
|
const id = url.searchParams.get("id");
|
|
const codeFromPath = decodeURIComponent(file).replace(/\.[^.]+$/, "");
|
|
// Don't try to look up by code when the path is the "image-<id>" fallback.
|
|
const code = codeFromPath.startsWith("image-") ? null : codeFromPath;
|
|
return serveImage(req, { id, code });
|
|
}
|