File size: 1,309 Bytes
9580dce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 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 });
});
|