import { phraseFinderState, startPhraseScan } from "@/lib/phrase-finder/server"; export const dynamic = "force-dynamic"; // The phrase finder (release 34, /tools/phrases). GET: what the page opens // with -- the channels, the last search's settings, the suggestions, the // running search and the recent ones. POST {rows: [{id, text, mode}], // channels, prefer, exclude}: start a search, a job (lib/phrase-finder/server.ts); // a bad phrase or channel is refused here with its sentence, a second search // while one runs with 409 and the running one's id. export async function GET() { return Response.json(await phraseFinderState(), { headers: { "cache-control": "no-store" } }); } export async function POST(request: Request) { let body: unknown; try { body = await request.json(); } catch { return Response.json({ error: "bad json" }, { status: 400 }); } try { return Response.json(await startPhraseScan(body), { headers: { "cache-control": "no-store" } }); } catch (e) { const err = e as Error & { status?: number; running?: string }; return Response.json({ error: err.message, ...(err.running ? { running: err.running } : {}) }, { status: err.status ?? 400 }); } }