Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

2.0 KB
Raw Blame
import { readFile, writeFile } from "node:fs/promises";
import { installXVideoObserver } from "../extension/x-video-capture.js";
import { PAGE_CAPTURE_LIMITS } from "../extension/resource-limits.js";
import { operationBudget } from "../extension/resource-policy.js";

const check = process.argv.includes("--check");
const root = new URL("../", import.meta.url);
const observer = `// Generated by build:capture-runtime from x-video-capture.js and resource-policy.js.\n(${installXVideoObserver.toString()})(${JSON.stringify({ timeoutMs: PAGE_CAPTURE_LIMITS.navigationTimeoutMs, maxBytes: operationBudget().maxTextBytes, maxMedia: PAGE_CAPTURE_LIMITS.maxMediaPerCandidate })});\n`;
const files = new Map([
  ["x-video-observer.js", Buffer.from(observer)],
  ["hls-runtime.js", await readFile(new URL("node_modules/hls.js/dist/hls.min.js", root))]
]);
for (const [name, bytes] of files) {
  const path = new URL(`extension/${name}`, root);
  if (check) {
    if (!bytes.equals(await readFile(path))) throw new Error(`Capture runtime differs: ${name}`);
  } else await writeFile(path, bytes);
}
const license = await readFile(new URL("node_modules/hls.js/LICENSE", root), "utf8");
const noticePath = new URL("THIRD_PARTY_NOTICES.md", root);
const notices = await readFile(noticePath, "utf8");
const marker = "\n## hls.js\n";
const section = `${marker}\nBundled local video playback runtime. Exact version: package-lock.json. Source: https://github.com/video-dev/hls.js\n\n${license.trim()}\n`;
const sectionStart = notices.indexOf(marker);
const sectionEnd = sectionStart < 0 ? -1 : notices.indexOf("\n## ", sectionStart + marker.length);
const expected = sectionStart < 0
  ? `${notices.trimEnd()}\n${section}`
  : `${notices.slice(0, sectionStart)}${section}${sectionEnd < 0 ? "" : notices.slice(sectionEnd)}`;
if (check && notices !== expected) throw new Error("hls.js license differs");
if (!check) await writeFile(noticePath, expected);
console.log("Capture runtimes and license match locked sources");