import { SvelteSet } from 'svelte/reactivity'; import type { Job } from '$lib/comfy/types'; /** * Output files a done job claims but the asset endpoint could not serve * (spec-v2 §3.4 红/琥珀界线): the backend task status stays the single * verdict for red — a FAILED job is red no matter what. Amber means the * job SUCCEEDED and only its product file is gone (cleaned up, moved, * storage hiccup). We learn that the only way the frontend can: the * media element itself failed to load. A later successful load clears * the mark. */ const missing = new SvelteSet(); /** Mark one output path as unreachable (img/video onerror). */ export function markOutputMissing(path: string): void { if (path) missing.add(path); } /** Clear the mark when the same path loads fine after all. */ export function clearOutputMissing(path: string): void { missing.delete(path); } /** Paths of this job's outputs that are currently unreachable. */ export function missingOutputsOf(job: Job | null | undefined): string[] { if (!job || job.status !== 'done' || !(job.output_paths?.length ?? 0)) return []; return job.output_paths.filter((p) => missing.has(p)); } /** * The take reads as 文件缺失 when it succeeded but at least one claimed * product file cannot be fetched. */ export function isFileMissing(job: Job | null | undefined): boolean { return missingOutputsOf(job).length > 0; }