Archilyzer · Source

archilyzer

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

commit 51616ccb8f15149294cde6a2e1e1d58eb4af189d
parent e14909070255967ee0a34548bca1ae77f666c489
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 19 Nov 2026 17:38:46 -0500

common: Save to a file…, for a small clip too, where the browser can

A browser with showSaveFilePicker now offers "Save to a file…" beside
"Save clip" for a clip built in memory, so the disk path is the visitor's
choice at any size (a clip over 128 MB still goes there only). The saving,
done and cancelled states follow the target the save really used. A clip
that grows past the memory limit on such a browser says to save it to a
file instead.

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

Diffstat:
Mcommon/components/LocalClipPanel.tsx | 16++++++++++++----
Mcommon/lib/localClip.test.ts | 2+-
Mcommon/lib/localClip.ts | 2+-
Mcommon/lib/localClipJob.ts | 16++++++++++------
4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/common/components/LocalClipPanel.tsx b/common/components/LocalClipPanel.tsx @@ -145,8 +145,8 @@ export function LocalClipPanel() { requestAnimationFrame(() => triggerRef.current?.querySelector("button")?.focus()); }; - const save = async (st: Extract<ClipJobState, { phase: "ready" }>) => { - if (st.path === "disk") { + const save = async (st: Extract<ClipJobState, { phase: "ready" }>, to: "memory" | "disk") => { + if (to === "disk") { const picker = savePicker(); if (!picker) return; const ext = extOf(st.name); @@ -236,7 +236,7 @@ function ClipBody({ }: { job: ClipJobState; canClip: boolean; - onSave: (st: Extract<ClipJobState, { phase: "ready" }>) => void; + onSave: (st: Extract<ClipJobState, { phase: "ready" }>, to: "memory" | "disk") => void; onClose: () => void; }) { const closeButton = <ControlButton title="Close the clip" label="Close" icon={<span aria-hidden="true" className="hidden" />} onClick={onClose} />; @@ -290,7 +290,15 @@ function ClipBody({ {job.plan.extraTracks && <p>Only the main video and audio are kept.</p>} </div> <Actions> - <ControlButton title="Save clip" label="Save clip" icon={<span aria-hidden="true" className="hidden" />} onClick={() => onSave(job)} /> + <ControlButton title="Save clip" label="Save clip" icon={<span aria-hidden="true" className="hidden" />} onClick={() => onSave(job, job.path)} /> + {job.path === "memory" && job.canSaveToDisk && ( + <ControlButton + title="Save the clip to a file you choose" + label="Save to a file…" + icon={<span aria-hidden="true" className="hidden" />} + onClick={() => onSave(job, "disk")} + /> + )} {closeButton} </Actions> </> diff --git a/common/lib/localClip.test.ts b/common/lib/localClip.test.ts @@ -201,7 +201,7 @@ test("every refusal is one plain sentence", () => { ); assert.equal( refusalSentence({ kind: "grew", canSaveToDisk: true }), - "This clip grew past 256 MB while it was being made, too big for this browser's memory; nothing was saved. Mark a shorter clip.", + "This clip grew past 256 MB while it was being made, too big for this browser's memory; nothing was saved. Save it to a file you choose instead, or mark a shorter clip.", ); assert.equal( refusalSentence({ kind: "read" }), diff --git a/common/lib/localClip.ts b/common/lib/localClip.ts @@ -257,7 +257,7 @@ export function refusalSentence(r: Refusal): string { case "too-big": return `This clip would be about ${formatBytes(r.bytes)}, too big to build in this browser's memory (at most ${formatBytes(MEMORY_LIMIT_BYTES)}). ${SHORTER_OR_DISK}`; case "grew": - return `This clip grew past ${formatBytes(MEMORY_LIMIT_BYTES)} while it was being made, too big for this browser's memory; nothing was saved. ${r.canSaveToDisk ? "Mark a shorter clip." : SHORTER_OR_DISK}`; + return `This clip grew past ${formatBytes(MEMORY_LIMIT_BYTES)} while it was being made, too big for this browser's memory; nothing was saved. ${r.canSaveToDisk ? "Save it to a file you choose instead, or mark a shorter clip." : SHORTER_OR_DISK}`; case "read": return "Your browser could not read the file. It may have moved or changed since you picked it; pick it again."; case "no-key": diff --git a/common/lib/localClipJob.ts b/common/lib/localClipJob.ts @@ -28,7 +28,11 @@ export type ClipRequest = { type Prepared = { plan: ClipPlan; name: string; + // How "Save clip" saves it: in memory (a download), or to a file the + // visitor picks (a big clip, on a browser that can). A browser that can + // also offers the file for a small clip ("Save to a file…"). path: "memory" | "disk"; + canSaveToDisk: boolean; // From describeClip, one set of facts: the range the clip holds, where it // really starts, where it ends when that is before the out mark. range: string; @@ -43,7 +47,7 @@ export type ClipJobState = // `retry`: the refusal may not hold the next time (a read that failed, a // copy that broke), so asking for the same key again prepares again. | { phase: "refused"; key: string; sentence: string; retry: boolean } - | ({ phase: "saving"; key: string; fraction: number; doneSeconds: number; totalSeconds: number } & Prepared) + | ({ phase: "saving"; key: string; fraction: number; doneSeconds: number; totalSeconds: number; to: "memory" | "disk" } & Prepared) | { phase: "done"; key: string; name: string; bytes: number; path: "memory" | "disk" } | { phase: "cancelled"; key: string; path: "memory" | "disk" } | { phase: "failed"; key: string; sentence: string }; @@ -138,7 +142,7 @@ export async function prepareLocalClip(req: ClipRequest): Promise<void> { slug: req.slug, ext: plan.ext, }); - set({ phase: "ready", key, plan, path, ...words }); + set({ phase: "ready", key, plan, path, canSaveToDisk: req.canSaveToDisk, ...words }); } catch { if (mine !== token) return; refuse(key, { kind: "copy" }); @@ -169,7 +173,7 @@ export async function saveLocalClip(target: SaveTarget): Promise<void> { saving = ac; const { phase: _phase, ...rest } = prepared; void _phase; - set({ ...rest, phase: "saving", fraction: 0, doneSeconds: 0, totalSeconds: prepared.plan.endTs - prepared.plan.startTs }); + set({ ...rest, phase: "saving", to: target.kind, fraction: 0, doneSeconds: 0, totalSeconds: prepared.plan.endTs - prepared.plan.startTs }); try { const eng = (engine ??= await loadClipEngine()); try { @@ -185,10 +189,10 @@ export async function saveLocalClip(target: SaveTarget): Promise<void> { ); if (mine !== token) return; if (result.blob) startDownload(result.blob, prepared.name); - set({ phase: "done", key: prepared.key, name: prepared.name, bytes: result.bytes, path: prepared.path }); + set({ phase: "done", key: prepared.key, name: prepared.name, bytes: result.bytes, path: target.kind }); } catch (e) { if (mine !== token) return; - if (e instanceof eng.ClipCancelled) set({ phase: "cancelled", key: prepared.key, path: prepared.path }); + if (e instanceof eng.ClipCancelled) set({ phase: "cancelled", key: prepared.key, path: target.kind }); else set({ phase: "failed", key: prepared.key, sentence: refusalSentence(eng.saveFailure(e, req.canSaveToDisk)) }); } } finally { @@ -204,7 +208,7 @@ export function cancelLocalClip(): void { function forget(): "memory" | "disk" | null { token++; - const was = state.phase === "saving" ? state.path : null; + const was = state.phase === "saving" ? state.to : null; saving?.abort(); saving = null; if (engine && current) void engine.forgetClipInput(current.file);