← back to Trademarks Copyright
src/app/api/drops/compose/route.ts
28 lines
import { NextRequest, NextResponse } from "next/server";
import { composeDropForDate } from "@/lib/drops";
import { qwenIsUp } from "@/lib/qwen";
export const runtime = "nodejs";
export const maxDuration = 300;
export async function POST(req: NextRequest) {
const body = await req.json().catch(() => ({}));
if (!body || typeof body !== "object" || Array.isArray(body)) {
return NextResponse.json({ error: "json object body required" }, { status: 400 });
}
const date = body.date ? new Date(String(body.date)) : undefined;
const itemsPerDrop = Number.isFinite(body.itemsPerDrop) ? body.itemsPerDrop : 10;
const force = !!body.force;
if (!(await qwenIsUp())) {
return NextResponse.json({ error: "Ollama not reachable at :11434" }, { status: 500 });
}
try {
const drop = await composeDropForDate({ date, itemsPerDrop, force });
return NextResponse.json({ ok: true, ...drop });
} catch (e) {
return NextResponse.json({ error: (e as Error).message }, { status: 500 });
}
}