import { readInbox } from "@/lib/inbox"; import { listPieces } from "@/lib/pieces"; import { readLifecycle } from "@/lib/lifecycle"; export const dynamic = "force-dynamic"; // Every piece (lib/pieces.ts): an article with its linked video projects, or a // project no article claims. Each with its kind, title, site, stage, lifecycle, // linked projects, and how many decisions wait on it -- per inbox group, the // visible ones, plus how many are hidden (a parked or done piece's). // // GET { pieces: [...], lifecycleError? } export async function GET() { const life = await readLifecycle(); const [pieces, inbox] = await Promise.all([listPieces(life), readInbox()]); const counts = new Map }>(); for (const d of inbox.items) { if (!d.piece) continue; let c = counts.get(d.piece); if (!c) counts.set(d.piece, (c = { total: 0, hidden: 0, byGroup: {} })); c.total += 1; if (d.hidden) c.hidden += 1; else if (d.group) c.byGroup[d.group] = (c.byGroup[d.group] ?? 0) + 1; } return Response.json( { pieces: pieces.map((p) => ({ ...p, decisions: counts.get(p.id) ?? { total: 0, hidden: 0, byGroup: {} } })), ...(life.error ? { lifecycleError: life.error } : {}), }, { headers: { "cache-control": "no-store" } }, ); }