import { z } from "zod"; import { getDb } from "@tline/db"; export const runtime = "nodejs"; const bodySchema = z .object({ type: z.enum(["upload", "minio_scan"]).default("upload"), }) .strict(); export async function POST(request: Request): Promise { const bodyJson = await request.json().catch(() => ({})); const body = bodySchema.parse(bodyJson); const db = getDb(); const rows = await db< { id: string; type: "upload" | "minio_scan"; status: string; created_at: string; }[] >` insert into imports (type, status) values (${body.type}, 'new') returning id, type, status, created_at `; const created = rows[0]; if (!created) { return Response.json({ error: "insert_failed" }, { status: 500 }); } return Response.json(created); }