import path from "node:path"; import { lstat } from "node:fs/promises"; import type { Paths } from "../lib/paths"; import { EXTERNAL_MEDIA_FILENAME, localMediaFetchRefusal } from "../lib/localMedia"; // THE DOORS THAT WRITE MEDIA INTO A RECORD (import-media, attach-media; review // fix 5): besides a local library channel or a local recording // (localMediaFetchRefusal's sentence), a record LINKED to a library original — // one with `external-media.json`, a provider id included — is refused: its // video is the library's, never a copy in the saved-video store. `lstat`, not // the sidecar's loader: a malformed reference must refuse too. export async function localMediaWriteRefusal( paths: Pick, slug: string, config: { localMedia?: unknown; url?: string | null } | null | undefined, id?: string, ): Promise { const fetch = localMediaFetchRefusal(slug, config, id); if (fetch) return fetch; if (!id || /[\\/]|^\.\.?$/.test(id)) return null; const linked = await lstat(path.join(paths.channelsDir, slug, "data", id, EXTERNAL_MEDIA_FILENAME)).then(() => true, () => false); return linked ? `"${slug}/${id}" is linked to a local media library original (${EXTERNAL_MEDIA_FILENAME}), so no media is written into it.` : null; }