RotNot / src /app /api /feynman /verify /route.ts
deploy
Deploy RotNot
9580dce
Raw History Blame Contribute Delete
1.31 kB
import { NextRequest, NextResponse } from "next/server";
import { runVerification, getSourceHealthSummary } from "@/lib/sources/verify";
import { withApiError } from "@/lib/api-error";
/**
* POST /api/feynman/verify
*
* Run source verification — checks stale/unverified source URLs,
* removes dead sources, and invalidates teaching caches that fall
* below the minimum source threshold.
*
* Body (optional): { limit?: number } — max sources to check (default 50)
*
* Returns verification results and updated health summary.
*/
export const POST = withApiError(async (request: NextRequest) => {
let limit: number | undefined;
try {
const body = await request.json();
if (body.limit && typeof body.limit === "number" && body.limit > 0) {
limit = Math.min(body.limit, 200); // cap at 200 per run
}
} catch {
// Empty body is fine — use defaults
}
const result = await runVerification(limit);
const health = await getSourceHealthSummary();
return NextResponse.json({
verification: result,
health,
});
});
/**
* GET /api/feynman/verify
*
* Returns source health summary without running verification.
*/
export const GET = withApiError(async () => {
const health = await getSourceHealthSummary();
return NextResponse.json({ health });
});