import { readFile } from "node:fs/promises"; import path from "node:path"; import { runningJob } from "@/lib/jobs"; import { reportDirFor, sitesPaths } from "@/lib/articles/sites"; import { projectsRootOf, readPolicy } from "@/lib/articles/generation"; import { configuredProjectsRoot } from "@/lib/report/chain.mjs"; import { MEDIA_ROOT, REPORTS_ROOT } from "@/lib/paths"; // What the project and take delete routes tell lib/report/delete.mjs that it // cannot see from a plain module (release 27 follow-up): the umtool job working // in the project, the generation projects root and the article store (an // iteration project's article), and whether an article a manifest names has a // video attached. SERVER-ONLY. export async function projectDeleteContext(projectId: string) { const job = runningJob(); let projectsRoot: string; try { projectsRoot = projectsRootOf((await readPolicy()).generation); } catch { projectsRoot = configuredProjectsRoot(); } return { reportsRoot: REPORTS_ROOT, mediaRoot: MEDIA_ROOT, busyJob: job && job.project === projectId ? job.kind : null, projectsRoot, articlesDir: sitesPaths().articlesDir, // `/` (articles/ for an article): its report.json has a `video`. articleVideo: async (ref: string) => { const [site, report] = ref.split("/"); if (!site || !report) return false; try { const doc = JSON.parse(await readFile(/* turbopackIgnore: true */ path.join(/* turbopackIgnore: true */ reportDirFor(site, report), "report.json"), "utf8")); return !!doc?.video; } catch { return false; } }, }; }