import { NextResponse } from "next/server"; import { z } from "zod"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { addFilesToModel, ModelError, removeFilesFromModel } from "@/lib/models"; const Body = z.object({ add: z.array(z.string().min(1).max(1024)).min(1).max(10_000) }); /** Add files to a model's selection and queue their download. */ export const POST = withAuth>(async (req, { params }) => { const { id } = await params; try { const { add } = Body.parse(await req.json()); return NextResponse.json(await addFilesToModel(id, add), { status: 201 }); } catch (err) { if (err instanceof ModelError) return apiError(err.status, err.code, err.message); return handleApiError(err); } }); const RemoveBody = z.object({ remove: z.array(z.string().min(1).max(1024)).min(1).max(10_000) }); /** Remove files from a model's selection and queue deleting them from disk. */ export const DELETE = withAuth>(async (req, { params }) => { const { id } = await params; try { const { remove } = RemoveBody.parse(await req.json()); return NextResponse.json(await removeFilesFromModel(id, remove), { status: 202 }); } catch (err) { if (err instanceof ModelError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });