Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 0152ab6a690e874169fa1a75cca21bae89ae9de1
parent e846dd7218d0c03943b5184e9b462ffe42c221f7
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 22 Oct 2026 15:14:19 -0400

live capture: a record made for a file or a stream that did not land is removed again; record-live checks the store's root and free space before it records

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/controller/importMedia.ts | 52+++++++++++++++++++++++++++++++++-------------------
Mcommon/controller/landMedia.test.ts | 12++++++++++++
2 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/common/controller/importMedia.ts b/common/controller/importMedia.ts @@ -223,25 +223,39 @@ export async function importMediaRun( } } - const landed = await landMediaFile({ - paths, - slug: req.slug, - channelConfig: opts.channelConfig, - videoId: target.id, - sourcePath: req.path, - via: "import-media", - ...(req.move ? { move: true } : {}), - ...(req.replace ? { replace: true } : {}), - ...(req.audio === false ? { audio: false } : {}), - ...(target.kind === "url" ? { url: target.url } : {}), - ...(req.note ? { note: req.note } : {}), - ...(req.dryRun ? { dryRun: true } : {}), - // A dry run of a record not made yet has no directory to read. - ...(req.dryRun && (record === "would-create") ? { recordMayBeMissing: true } : {}), - onLog, - signal, - ...(opts.deps?.land ? { deps: opts.deps.land } : {}), - }); + let landed: LandMediaResult; + try { + landed = await landMediaFile({ + paths, + slug: req.slug, + channelConfig: opts.channelConfig, + videoId: target.id, + sourcePath: req.path, + via: "import-media", + ...(req.move ? { move: true } : {}), + ...(req.replace ? { replace: true } : {}), + ...(req.audio === false ? { audio: false } : {}), + ...(target.kind === "url" ? { url: target.url } : {}), + ...(req.note ? { note: req.note } : {}), + ...(req.dryRun ? { dryRun: true } : {}), + // A dry run of a record not made yet has no directory to read. + ...(req.dryRun && record === "would-create" ? { recordMayBeMissing: true } : {}), + onLog, + signal, + ...(opts.deps?.land ? { deps: opts.deps.land } : {}), + }); + } catch (err) { + // A record this run made for a file that did not land is not left behind: + // a data/<id>/ with metadata is what every enumerator reads as "fetched". + if (!req.dryRun && (record === "created" || record === "by-hand")) { + const left = await readdir(videoDir).catch(() => [] as string[]); + if (left.every((n) => n === "metadata.info.json" || n === "metadata.history.json")) { + await rm(videoDir, { recursive: true, force: true }); + say(`The record ${target.id} this import made is removed again (nothing landed).`); + } + } + throw err; + } if (req.doNotClean) { if (!req.dryRun) await setDoNotClean(videoDir, true, req.note); diff --git a/common/controller/landMedia.test.ts b/common/controller/landMedia.test.ts @@ -172,6 +172,18 @@ test("import: a record by hand for a file with no source page, marked Do not cle assert.match((again as { error: string }).error, /already has a record old-talk/); }); +test("import: a record made for a file that does not land is removed again", async () => { + const bad = path.join(OUTSIDE, "Broken Thing.mp4"); + await writeFile(bad, "not media at all"); + const req = { slug: SLUG, path: bad, meta: { title: "Broken" } }; + const target = await resolveImportTarget(paths, req); + await assert.rejects( + importMediaRun({ paths, request: req, channelConfig: CONFIG, cookiePolicy: { cookies: undefined, mode: "when-required" }, target: target as never, onLog, signal, deps: { land: deps } }), + /ffprobe cannot read/, + ); + await assert.rejects(stat(path.join(CORPUS, "channels", SLUG, "data", "broken-thing"))); +}); + test("import by url: one metadata pass makes the record under the URL id", async () => { const req = { slug: SLUG, path: await fake("rec.mp4.part", "mpegts", 1200), url: "https://rumble.com/v9abcde-a-stream.html" }; const target = await resolveImportTarget(paths, req);