mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-01 19:42:03 +00:00
`hyperframes capture` extracts inline SVGs into capture/assets/svgs/, and the
capture manifest advertises them to the agent as `assets/svgs/<name>.svg`, so a
frame names one in `asset_candidates` exactly the way it names a screenshot.
stageAssets searched only capture/{assets,assets/videos,screenshots}, so every
captured SVG resolved to nothing: logged as a non-fatal anomaly, and the frame
404'd the brand mark it had been told to use.
Add the directory to the search list, and cover it with a test that fails
without the fix.
lib/assets.mjs is byte-identical across product-launch-video,
faceless-explainer and pr-to-video, so the fix lands in all three. Folding it
into hyperframes-core/scripts/lib/, where frame-packets-core.mjs already lives,
is a separate change.
Co-authored-by: anikam13 <22992075+anikam13@users.noreply.github.com>
57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
// assets.mjs — stage frame-named capture assets into assets/.
|
|
// Shared by stage-assets.mjs (Step 4 close, BEFORE the frame workers run) and
|
|
// assemble-index.mjs (Step 5, idempotent backstop). Only assets a frame names
|
|
// in `asset_candidates` are staged; unnamed assets never reach the project.
|
|
// asset_candidates value form: "assets/<basename> — desc; assets/… — …".
|
|
|
|
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
import { basename, join } from "node:path";
|
|
|
|
export function basenamesFromCandidates(value) {
|
|
if (typeof value !== "string") return [];
|
|
return value
|
|
.split(";")
|
|
.map((seg) => seg.split(/\s+[—–-]\s+/)[0].trim()) // strip the " — description"
|
|
.filter(Boolean)
|
|
.map((p) => basename(p.replace(/^assets\//, "")));
|
|
}
|
|
|
|
// Copy each frame's asset_candidates from capture/{assets,assets/videos,
|
|
// assets/svgs, screenshots} into assets/. Already-staged files are left as is
|
|
// (first-wins), so calling this twice is safe. Returns { staged, wanted, anomalies }.
|
|
export function stageAssets({ hyperframesDir, frames }) {
|
|
const wanted = new Set();
|
|
for (const f of frames) {
|
|
for (const b of basenamesFromCandidates(f.extra?.asset_candidates)) wanted.add(b);
|
|
}
|
|
const captureDirs = [
|
|
join(hyperframesDir, "capture/assets"),
|
|
join(hyperframesDir, "capture/assets/videos"), // videos download into a subdir
|
|
join(hyperframesDir, "capture/assets/svgs"), // inline SVGs extract into a subdir
|
|
join(hyperframesDir, "capture/screenshots"),
|
|
];
|
|
const assetsDir = join(hyperframesDir, "assets");
|
|
const anomalies = [];
|
|
let staged = 0;
|
|
if (wanted.size > 0) {
|
|
mkdirSync(assetsDir, { recursive: true });
|
|
for (const b of wanted) {
|
|
const dest = join(assetsDir, b);
|
|
if (existsSync(dest)) {
|
|
staged++;
|
|
continue;
|
|
} // first-wins / already staged
|
|
const src = captureDirs.map((d) => join(d, b)).find((p) => existsSync(p));
|
|
if (src) {
|
|
copyFileSync(src, dest);
|
|
staged++;
|
|
} else {
|
|
anomalies.push(
|
|
`asset "${b}" named by a frame but not found under capture/ — frame will 404 it`,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
return { staged, wanted, anomalies };
|
|
}
|