Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: treat snapshot HTML URLs like capture and reject invalid --studio bases (#323)

Li Rui5d52f8d76670
diff --git a/packages/video-cli/src/snapshot.ts b/packages/video-cli/src/snapshot.ts
index ff39ca69..26735c7a 100644
--- a/packages/video-cli/src/snapshot.ts
+++ b/packages/video-cli/src/snapshot.ts
@@ -23,7 +23,7 @@ const MEDIA_TYPES: Readonly<Record<string, string>> = {
async function readProject(source: string, html: string, resources: FileResourceStore): Promise<HyperframesHtmlProject> {
const assets = [];
- const base = /^https?:/u.test(source) ? new URL(source) : pathToFileURL(source);
+ const base = isSnapshotHtmlUrl(source) ? new URL(source) : pathToFileURL(source);
for (const url of hyperframesHtmlAssetUrls(html)) {
const address = new URL(url, base);
let mediaType: string | undefined;
@@ -52,6 +52,20 @@ async function readProject(source: string, html: string, resources: FileResource
const OPTIONS = ["--studio", "--to", "--at-frame", "--start-frame", "--end-frame-exclusive", "--step-frames", "--grid", "--cell", "--runtime", "--workspace"];
+/** Capture already treats HTTP(S) case-insensitively; snapshot must not turn HTTPS:// into a local path. */
+export function isSnapshotHtmlUrl(value: string): boolean {
+ return /^https?:\/\//iu.test(value);
+}
+
+/** `--studio` is a base URL, not a host:port token. `new URL` otherwise throws TypeError. */
+export function studioDocumentUrl(studio: string): string {
+ try {
+ return new URL("/__studio/document", studio).href;
+ } catch {
+ throw new Error(`--studio needs an http(s) Studio URL, got ${studio}`);
+ }
+}
+
export function writeSnapshotHelp(io: CliIo): void {
io.write(`hypit snapshot\nCapture exact frames from an existing compiled HyperFrames HTML programme through the selected Runtime Profile.\n\n`
+ ` hypit snapshot --studio <studio-url> --at-frame <n[,n,…]> --to <directory>\n`
@@ -87,8 +101,8 @@ export async function runSnapshotCli(argv: readonly string[], io: CliIo, environ
return Number(raw);
};
const source = studio === undefined
- ? /^https?:\/\//u.test(positionals[0]!) ? positionals[0]! : resolve(environment.cwd, positionals[0]!)
- : new URL("/__studio/document", studio).href;
+ ? isSnapshotHtmlUrl(positionals[0]!) ? positionals[0]! : resolve(environment.cwd, positionals[0]!)
+ : studioDocumentUrl(studio);
let document: HyperframesDocument | undefined;
let html: string;
if (studio !== undefined) {
@@ -97,7 +111,7 @@ export async function runSnapshotCli(argv: readonly string[], io: CliIo, environ
document = await response.json() as HyperframesDocument;
assertHyperframesDocument(document);
html = document.html;
- } else if (/^https?:/u.test(source)) {
+ } else if (isSnapshotHtmlUrl(source)) {
const response = await fetch(source);
if (!response.ok) throw new Error(`Snapshot HTML: HTTP ${response.status} ${await response.text()}`);
html = await response.text();
diff --git a/packages/video-cli/test/snapshot.test.ts b/packages/video-cli/test/snapshot.test.ts
index 7eb7b7a3..49abb4ae 100644
--- a/packages/video-cli/test/snapshot.test.ts
+++ b/packages/video-cli/test/snapshot.test.ts
@@ -6,7 +6,7 @@ import { join } from "node:path";
import sharp from "sharp";
import { canonicalize } from "@hypit/protocol";
import { verifyHyperframesFramesRequest } from "@hypit/render-hyperframes";
-import { runSnapshotCli } from "../src/snapshot.js";
+import { isSnapshotHtmlUrl, runSnapshotCli, studioDocumentUrl } from "../src/snapshot.js";
import type { CreationEnvironment } from "../src/creation.js";
const html = '<!doctype html><div data-composition-id="test" data-fps="30000/1001" data-hypit-frame-count="12" data-width="96" data-height="64"><img src="still.png"></div>';
@@ -55,6 +55,40 @@ test("snapshot invokes the selected Profile once and writes original-frame PNGs
} finally { await rm(directory, { recursive: true, force: true }); }
});
+test("snapshot --studio without a URL scheme is a usage error, not TypeError", async () => {
+ assert.equal(studioDocumentUrl("http://localhost:5191"), "http://localhost:5191/__studio/document");
+ assert.throws(() => studioDocumentUrl("localhost:5191"), /--studio needs an http\(s\) Studio URL/u);
+ const environment: CreationEnvironment = { cwd: "/tmp", openHost: async () => ({ profile: "empty.json", host: {
+ providers: async () => [], invoke: async () => { throw new Error("must not run"); },
+ } }) };
+ await assert.rejects(
+ runSnapshotCli(["snapshot", "--studio", "localhost:5191", "--at-frame", "0", "--to", "out"], { write() {} }, environment),
+ (error: unknown) => error instanceof Error && error.name === "Error" && /--studio needs an http\(s\) Studio URL/u.test(error.message),
+ );
+});
+
+test("snapshot treats HTTPS HTML URLs as network inputs, matching capture", async (t) => {
+ assert.equal(isSnapshotHtmlUrl("HTTPS://example.test/picture/index.html"), true);
+ assert.equal(isSnapshotHtmlUrl("https://example.test/picture/index.html"), true);
+ assert.equal(isSnapshotHtmlUrl("index.html"), false);
+ const directory = await mkdtemp(join(tmpdir(), "hypit-snapshot-https-"));
+ const fetched: string[] = [];
+ t.mock.method(globalThis, "fetch", async (input: string | URL) => {
+ fetched.push(String(input));
+ return new Response(html.replace('<img src="still.png">', ""));
+ });
+ try {
+ const environment: CreationEnvironment = { cwd: directory, openHost: async () => ({ profile: "empty.json", host: {
+ providers: async () => [], invoke: async () => { throw new Error("must not run"); },
+ } }) };
+ await assert.rejects(runSnapshotCli(
+ ["snapshot", "HTTPS://example.test/picture/index.html", "--at-frame", "0", "--to", "out"],
+ { write() {} }, environment,
+ ), /No Endpoint/u);
+ assert.deepEqual(fetched, ["HTTPS://example.test/picture/index.html"]);
+ } finally { await rm(directory, { recursive: true, force: true }); }
+});
+
test("snapshot reports a missing binding before invocation and preserves existing output", async () => {
const directory = await mkdtemp(join(tmpdir(), "hypit-snapshot-error-"));
try {