// The disk half of the gone reading (./sourceGone.ts): a recording's video // directory, a post's availability sidecar. // // SERVER-ONLY (node:fs). import path from "node:path"; import { stateFromAvailability } from "./availability"; import { resolveEffectiveAvailability } from "./availability-server"; import { readPostAvailability } from "./posts-server"; import { resolveVideoDir } from "./videoDir-server.mjs"; import { goneState, type GoneState } from "./sourceGone"; // A recording's video directory → its gone state, or null (live, or never // resolved: a missing or unreadable availability is NOT gone). export async function sourceGoneState(videoDir: string): Promise { const a = await resolveEffectiveAvailability(videoDir).catch(() => null); return goneState(stateFromAvailability(a)); } // The same by channel and record id (the record's directory resolved as every // reader resolves it). export async function recordGoneState(channelsDir: string, slug: string, id: string): Promise { const dir = await resolveVideoDir(channelsDir, slug, id).catch(() => null); return dir ? sourceGoneState(dir) : null; } // A post is gone when the channel's posts-availability.json says `deleted` // (a deleted-post sweep or a capture saw it so). Anything else — available, // an unreachable account, an error, never checked — is not. export async function postGoneState(channelsDir: string, slug: string, id: string): Promise<"deleted" | null> { const map = await readPostAvailability(path.join(channelsDir, slug)).catch(() => ({}) as Record); return map[id]?.availability === "deleted" ? "deleted" : null; }