import { stat } from "node:fs/promises"; import path from "node:path"; import { projectRefs } from "@/lib/projects"; import { MANIFEST_NAME } from "@/lib/projects/report.mjs"; import { deliverablesProblems, deliverablesState, outDirState } from "@/lib/report/storage.mjs"; // Where every project's bulk is, for Settings · system's Storage panel (P5): // `umtool storage`'s table. out/ for every project; the deliverables (clips/, // share-*/ and the switch) for one with a manifest. One lstat per name. export type StorageRow = { id: string; out: "absent" | "dir" | "link" | "dangling" | "other"; deliverables: { mode: "local" | "media" | null; dirs: string; problem: string | null } | null; }; const isFile = (p: string) => stat(p).then((s) => s.isFile(), () => false); export async function storageRows(): Promise { const refs = await projectRefs(); return Promise.all( refs.map(async (p) => { const out = (await outDirState(p.dir)).state as StorageRow["out"]; let deliverables: StorageRow["deliverables"] = null; if (await isFile(path.join(/* turbopackIgnore: true */ p.dir, MANIFEST_NAME))) { const d = await deliverablesState(p.dir); deliverables = { mode: d.mode, dirs: d.dirs.map((x: { name: string; state: string }) => `${x.name}${x.state === "link" ? "→media" : x.state === "dangling" ? " MISSING" : ""}`).join(" "), problem: deliverablesProblems(d)[0] ?? null, }; } return { id: p.id, out, deliverables }; }), ); }