import { parseLibraryView } from "@/lib/library/filters.mjs"; import { loadLibrary } from "@/lib/library/load"; import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs"; export const dynamic = "force-dynamic"; // GET /api/library?lib=&topic=&state=&gone=1&media=1&author=&q=&new=1&offset= // -> what the Posts library page shows for that view (lib/library/load.ts LibraryData): // { ok: true, libraries, lib, name, view, topics, posts, total, authors, pageSize } // or { ok: false, reason, sentence } when the editor cannot be asked or holds no such library // // THE PAGE'S OWN READ, ASKED AGAIN AFTER A PRESS (lane posts-library): the same read the page makes // when it is opened, through the editor (GET /api/ops/trending), so the rows on screen are the // editor's after every keep, drop, watch or purge. READ ONLY. It carries a private library's posts, // so a cross-site request, or one naming a host that is not this machine, is refused, and nothing // caches it. const PRIVATE = { "cache-control": "private, no-store", "cross-origin-resource-policy": "same-origin" }; export async function GET(request: Request) { if (crossSiteRefusal(request.headers)) return Response.json({ error: "refused: the library is read by umtool's own pages only" }, { status: 403, headers: PRIVATE }); const sp = new URL(request.url).searchParams; const params: Record = {}; for (const [k, v] of sp) if (!(k in params)) params[k] = v; return Response.json(await loadLibrary(parseLibraryView(params)), { headers: PRIVATE }); }