Archilyzer · Source

archilyzer

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

commit f064aeb07f6cd5e3b44d8a6cb7e1d99257db687f
parent b8da5060fa9958fa8a75e58aa1ffdc1f0ff13c12
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 07:11:19 -0500

local media: the import job's wrapper moves to controller/, under the layering gate

jobs/localMediaImportJob.ts imported controller/localMediaImport, a back-edge
common/architecture.test.ts refuses (dispatch: jobs/ may not import
controller/). It is controller/localMediaImportJob.ts now, beside the
controller it runs, importing jobs/streamCommand downward. No change to what
it does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diffstat:
Mcommon/controller/localMediaImport.test.ts | 2+-
Acommon/controller/localMediaImportJob.ts | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dcommon/jobs/localMediaImportJob.ts | 70----------------------------------------------------------------------
Meditor/app/api/ops/local-media-import/route.ts | 2+-
Meditor/app/channels/[slug]/local-media/actions.ts | 2+-
5 files changed, 73 insertions(+), 73 deletions(-)

diff --git a/common/controller/localMediaImport.test.ts b/common/controller/localMediaImport.test.ts @@ -116,7 +116,7 @@ test("missing source fails instead of reporting an empty successful preview", as import type { Paths } from "../lib/paths"; import type { JobRunContext } from "../jobs/streamCommand"; -import { localMediaJobOptions } from "../jobs/localMediaImportJob"; +import { localMediaJobOptions } from "./localMediaImportJob"; import { getJobKind, isIngestKind } from "../jobs/jobKinds"; function jobContext(drain = new AbortController()): JobRunContext { diff --git a/common/controller/localMediaImportJob.ts b/common/controller/localMediaImportJob.ts @@ -0,0 +1,70 @@ +import { parseLocalRecordingDetails } from "../lib/localRecordingDetails"; +import type { Paths } from "../lib/paths"; +import { channelQueueKey } from "../lib/queueKeys"; +import { importLocalMedia, type LocalMediaSelection } from "./localMediaImport"; +import { runManagedFunction, type RunManagedFunctionOpts } from "../jobs/streamCommand"; + +export type LocalMediaJobRequest = { + sourceToken: string; + selected: readonly LocalMediaSelection[]; +}; + +// Keep the managed job's body testable with synthetic sources, without starting +// the application's registry or snapshot timers. The production entry point +// below always uses runManagedFunction, including its enqueue/start guards. +export function localMediaJobOptions(paths: Paths, slug: string, request: LocalMediaJobRequest): RunManagedFunctionOpts { + if (!request || typeof request.sourceToken !== "string" || !Array.isArray(request.selected) + || request.selected.length === 0 || request.selected.length > 1000 + || request.selected.some(s => !s || typeof s.media !== "string" || typeof s.fingerprint !== "string") + || new Set(request.selected.map(s => s.media)).size !== request.selected.length) { + throw new Error("Select between 1 and 1000 distinct recordings from a fresh preview"); + } + if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(slug) || slug.endsWith(".")) throw new Error("Invalid channel slug"); + // A caller must not be able to mutate a request while it waits in the queue. + const selected = request.selected.map(({ media, fingerprint, preparation }) => { + if (preparation !== undefined && (!preparation || typeof preparation.sourceFingerprint !== "string")) { + throw new Error("Invalid recording preparation"); + } + return {media, fingerprint, ...(preparation ? {preparation: { + sourceFingerprint: preparation.sourceFingerprint, details: parseLocalRecordingDetails(preparation.details), + }} : {})}; + }); + const sourceToken = request.sourceToken; + return { + kind: "import-local-media", + queueKey: channelQueueKey(slug), + paths, + channelSlug: slug, + // No spec: replaying persisted names/tokens after source edits is misleading. + // The operator takes a new preview to retry or continue a drained batch. + fn: async (onLog, signal, setProgress, ctx) => { + setProgress({ metric: "entries", initial: 0, target: selected.length, current: 0 }); + onLog("Rechecking selected external recordings before import..."); + const result = await importLocalMedia(paths, slug, { + sourceToken, selected, signal, drainSignal: ctx.drainSignal, + onRecord: (record, completed) => { + // JSON quoting prevents filenames with newlines from forging log lines. + // Absolute library roots never enter these progress messages. + onLog(JSON.stringify({ recording: record.media, status: record.status, reason: record.reason, warnings: record.warnings, incomplete: record.incomplete })); + setProgress({ metric: "entries", initial: 0, target: selected.length, current: completed }); + }, + }); + const imported = result.records.filter(r => r.status === "imported").length; + const occupied = result.records.filter(r => r.status === "occupied").length; + const rejected = result.records.length - imported - occupied; + onLog(`Imported ${imported}; already occupied ${occupied}; rejected ${rejected}; unprocessed ${selected.length - result.records.length}.`); + if (result.needsIndexUpdate) onLog("Import complete. Click \"Update searchable library\" on the Local media library page to make the imported recordings searchable on your selected site."); + // The existing managed-job completion hook requests a channel snapshot, + // including on failure/cancellation. This job does not build/publish a site. + if (result.cancelled) { onLog("Import cancelled."); return; } + if (result.drained) onLog("Import stopped between recordings. Preview again to continue."); + if (rejected || result.records.some(r => r.stagingCleanupFailed)) { + throw new Error("Some selected recordings require review. Saved records were retained; preview again before retrying."); + } + }, + }; +} + +export async function startLocalMediaImportJob(paths: Paths, slug: string, request: LocalMediaJobRequest) { + return runManagedFunction(localMediaJobOptions(paths, slug, request)); +} diff --git a/common/jobs/localMediaImportJob.ts b/common/jobs/localMediaImportJob.ts @@ -1,70 +0,0 @@ -import { parseLocalRecordingDetails } from "../lib/localRecordingDetails"; -import type { Paths } from "../lib/paths"; -import { channelQueueKey } from "../lib/queueKeys"; -import { importLocalMedia, type LocalMediaSelection } from "../controller/localMediaImport"; -import { runManagedFunction, type RunManagedFunctionOpts } from "./streamCommand"; - -export type LocalMediaJobRequest = { - sourceToken: string; - selected: readonly LocalMediaSelection[]; -}; - -// Keep the managed job's body testable with synthetic sources, without starting -// the application's registry or snapshot timers. The production entry point -// below always uses runManagedFunction, including its enqueue/start guards. -export function localMediaJobOptions(paths: Paths, slug: string, request: LocalMediaJobRequest): RunManagedFunctionOpts { - if (!request || typeof request.sourceToken !== "string" || !Array.isArray(request.selected) - || request.selected.length === 0 || request.selected.length > 1000 - || request.selected.some(s => !s || typeof s.media !== "string" || typeof s.fingerprint !== "string") - || new Set(request.selected.map(s => s.media)).size !== request.selected.length) { - throw new Error("Select between 1 and 1000 distinct recordings from a fresh preview"); - } - if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(slug) || slug.endsWith(".")) throw new Error("Invalid channel slug"); - // A caller must not be able to mutate a request while it waits in the queue. - const selected = request.selected.map(({ media, fingerprint, preparation }) => { - if (preparation !== undefined && (!preparation || typeof preparation.sourceFingerprint !== "string")) { - throw new Error("Invalid recording preparation"); - } - return {media, fingerprint, ...(preparation ? {preparation: { - sourceFingerprint: preparation.sourceFingerprint, details: parseLocalRecordingDetails(preparation.details), - }} : {})}; - }); - const sourceToken = request.sourceToken; - return { - kind: "import-local-media", - queueKey: channelQueueKey(slug), - paths, - channelSlug: slug, - // No spec: replaying persisted names/tokens after source edits is misleading. - // The operator takes a new preview to retry or continue a drained batch. - fn: async (onLog, signal, setProgress, ctx) => { - setProgress({ metric: "entries", initial: 0, target: selected.length, current: 0 }); - onLog("Rechecking selected external recordings before import..."); - const result = await importLocalMedia(paths, slug, { - sourceToken, selected, signal, drainSignal: ctx.drainSignal, - onRecord: (record, completed) => { - // JSON quoting prevents filenames with newlines from forging log lines. - // Absolute library roots never enter these progress messages. - onLog(JSON.stringify({ recording: record.media, status: record.status, reason: record.reason, warnings: record.warnings, incomplete: record.incomplete })); - setProgress({ metric: "entries", initial: 0, target: selected.length, current: completed }); - }, - }); - const imported = result.records.filter(r => r.status === "imported").length; - const occupied = result.records.filter(r => r.status === "occupied").length; - const rejected = result.records.length - imported - occupied; - onLog(`Imported ${imported}; already occupied ${occupied}; rejected ${rejected}; unprocessed ${selected.length - result.records.length}.`); - if (result.needsIndexUpdate) onLog("Import complete. Click \"Update searchable library\" on the Local media library page to make the imported recordings searchable on your selected site."); - // The existing managed-job completion hook requests a channel snapshot, - // including on failure/cancellation. This job does not build/publish a site. - if (result.cancelled) { onLog("Import cancelled."); return; } - if (result.drained) onLog("Import stopped between recordings. Preview again to continue."); - if (rejected || result.records.some(r => r.stagingCleanupFailed)) { - throw new Error("Some selected recordings require review. Saved records were retained; preview again before retrying."); - } - }, - }; -} - -export async function startLocalMediaImportJob(paths: Paths, slug: string, request: LocalMediaJobRequest) { - return runManagedFunction(localMediaJobOptions(paths, slug, request)); -} diff --git a/editor/app/api/ops/local-media-import/route.ts b/editor/app/api/ops/local-media-import/route.ts @@ -1,6 +1,6 @@ import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { previewLocalMedia } from "yt-dlp-transcript-common/controller/localMediaImport"; -import { startLocalMediaImportJob, type LocalMediaJobRequest } from "yt-dlp-transcript-common/jobs/localMediaImportJob"; +import { startLocalMediaImportJob, type LocalMediaJobRequest } from "yt-dlp-transcript-common/controller/localMediaImportJob"; import { OpsInputError, jobResponse, ops, optBool, reqSlug } from "../_lib"; export const dynamic = "force-dynamic"; diff --git a/editor/app/channels/[slug]/local-media/actions.ts b/editor/app/channels/[slug]/local-media/actions.ts @@ -5,7 +5,7 @@ import { revalidatePath } from "next/cache"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { configureLocalMedia } from "yt-dlp-transcript-common/controller/configureLocalMedia"; import { prepareLocalMediaRecording, type LocalRecordingPreparationRequest, previewLocalMedia } from "yt-dlp-transcript-common/controller/localMediaImport"; -import { startLocalMediaImportJob, type LocalMediaJobRequest } from "yt-dlp-transcript-common/jobs/localMediaImportJob"; +import { startLocalMediaImportJob, type LocalMediaJobRequest } from "yt-dlp-transcript-common/controller/localMediaImportJob"; // These are private editor actions, behind the same deployment access boundary // as the channel's existing actions. Do not expose them through the public export.