import { DO_NOT_CLEAN_FILENAME, type DoNotCleanRecord, } from "./doNotClean"; import { sidecar, sidecarField } from "./sidecar-server"; // A parseable-but-malformed marker still means "protected" — it reads as an // empty record rather than as absent. Only an absent, unreadable or // unparseable file reads as null (sidecar-server's rule). export function coerceDoNotClean(value: unknown): DoNotCleanRecord { const parsed = value as Partial | null; if (typeof parsed?.setAt === "string") return parsed as DoNotCleanRecord; return { setAt: "" }; } export const doNotCleanSidecar = sidecar( DO_NOT_CLEAN_FILENAME, sidecarField(coerceDoNotClean), ); export const { path: doNotCleanPath, load: loadDoNotClean } = doNotCleanSidecar; // Presence of a valid sidecar = protected. Cheap existence check for the // cleanup controllers' per-dir loops. export async function isDoNotClean(videoDir: string): Promise { return (await loadDoNotClean(videoDir)) !== null; } export async function setDoNotClean( videoDir: string, enabled: boolean, note?: string, ): Promise { if (!enabled) return doNotCleanSidecar.remove(videoDir); await doNotCleanSidecar.write(videoDir, { setAt: new Date().toISOString(), ...(note ? { note } : {}), }); }