Ryan dd2477390c Who he is: live Wikipedia bio (auto-refreshed every 15-min crawl tick) + article link
- lib/bio.js: refreshBio() pulls the article intro via the Wikipedia API
  (exintro, descriptive UA) and upserts the bio cache; getBio() reads it
  with a short accurate static fallback. Page loads NEVER hit Wikipedia.
- crawl route: refreshBio() runs on every 15-min tick (over daily) —
  best-effort, a wiki hiccup can't fail the news crawl.
- /api/bio: read-only route.
- page.js: WhoBox renders the live text + 'Full article on Wikipedia' link
  + SOURCE: WIKIPEDIA · UPDATED <date> line.
- tests/bio-test.mjs: fallback + live-refresh + offline degradation.
2026-09-16 17:47:20 +00:00

34 lines
1.2 KiB
JavaScript

import { NextResponse } from "next/server";
// The crawl tick, fired by the PM2 cron (scripts/cron-digest.cjs) every 15 min.
// Protected by the CRON_SECRET header so a random visitor cannot trigger a
// crawl on demand (it costs feed fetches + og:image rescues + article
// prefetches).
export const maxDuration = 290;
export async function POST(req) {
const secret = req.headers.get("x-bama-cron");
if (secret !== (process.env.CRON_SECRET || "bama-cron")) {
return NextResponse.json({ error: "unauthorized" }, { status: 401 });
}
try {
const { crawlOnce } = await import("../../../lib/crawl");
const crawl = await crawlOnce();
// Refresh the live "Who he is" bio from Wikipedia on the same tick
// (well over "daily"). Best-effort: a Wikipedia hiccup must never
// make the crawl report a failure or lose the news it already gathered.
let bio = null;
try {
const { refreshBio } = await import("../../../lib/bio");
bio = await refreshBio();
} catch (e) {
bio = { ok: false, error: String((e && e.message) || e).slice(0, 120) };
}
return NextResponse.json({ ok: true, crawl, bio });
} catch (e) {
return NextResponse.json({ ok: false, error: String((e && e.message) || e) }, { status: 500 });
}
}