import { NextRequest, NextResponse } from "next/server"; import { addComfyModel } from "@/lib/docker"; export const dynamic = "force-dynamic"; export const runtime = "nodejs"; /** * POST /api/comfy/models/add * Body: { url: string, type: string } * * Queues a ComfyUI model download via model-worker. CivitAI URLs are * automatically transformed (model page → API download URL) and the saved * CivitAI token is appended. * * Returns: * { ok, output, error?, originalUrl?, transformedUrl?, urlNote? } * * The originalUrl/transformedUrl/urlNote fields are only present when we * actually modified the URL (e.g. user pasted a civitai.com/models/12345 * page URL and we converted it to /api/download/models/12345?token=...). */ export async function POST(req: NextRequest) { const body = (await req.json()) as { url?: string; type?: string }; if (!body.url || !body.type) { return NextResponse.json( { ok: false, error: "url and type required" }, { status: 400 } ); } const result = await addComfyModel(body.url, body.type); return NextResponse.json( { ok: result.ok, output: result.output, error: result.error, originalUrl: result.originalUrl, transformedUrl: result.transformedUrl, urlNote: result.urlNote, }, { status: result.ok ? 200 : 500 } ); }