Files
porthole/apps/web/app/api/assets/[id]/variants/route.ts
2026-02-01 16:47:50 -08:00

44 lines
963 B
TypeScript

import { z } from "zod";
import { getDb } from "@tline/db";
import { shapeVariants } from "./shape";
export const runtime = "nodejs";
const paramsSchema = z.object({
id: z.string().uuid(),
});
export async function GET(
_request: Request,
context: { params: Promise<{ id: string }> },
): Promise<Response> {
const rawParams = await context.params;
const paramsParsed = paramsSchema.safeParse(rawParams);
if (!paramsParsed.success) {
return Response.json(
{ error: "invalid_params", issues: paramsParsed.error.issues },
{ status: 400 },
);
}
const db = getDb();
const rows = await db<
{
kind: string;
size: number;
key: string;
mime_type: string;
width: number | null;
height: number | null;
}[]
>`
select kind, size, key, mime_type, width, height
from asset_variants
where asset_id = ${paramsParsed.data.id}
`;
return Response.json(shapeVariants(rows));
}