import { errorResponse, listEditorChannels, type EditorChannel } from "@/lib/articles/generation"; import { SourceError, openSource } from "@/lib/research/sources"; export const dynamic = "force-dynamic"; // The channels /articles/new's picker offers (GET /api/ops/channels): the // editor's own, or — `?source=remote:` (demo epic D1 item 2) — that // published archive's, from its corpus.json. Only an offered source opens // (lib/research/sources.ts openSource refuses any other handle). A remote-only // channel is not offered as the editor's own: it holds no transcripts. export async function GET(request: Request) { try { const source = new URL(request.url).searchParams.get("source")?.trim(); if (!source) { const channels = (await listEditorChannels()).filter((c) => c.kind !== "remote-only"); return Response.json({ channels }, { headers: { "cache-control": "no-store" } }); } const opened = await openSource(source); const refs = await opened.source.listChannels(); const channels: EditorChannel[] = refs .map((c) => ({ slug: c.slug, name: c.name ?? c.slug, kind: "video", platform: c.platform ?? null, sites: [] })) .sort((a, b) => a.name.localeCompare(b.name)); return Response.json({ channels, source: opened.option.handle }, { headers: { "cache-control": "no-store" } }); } catch (err) { if (err instanceof SourceError) return Response.json({ error: err.message }, { status: err.status }); return errorResponse(err); } }