mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(cli): cloud render uses the composition's data-fps and skips unused heavy files (#6895)
* fix(cli): cloud render uses the composition's data-fps and skips unused heavy files * fix(cli): satisfy typecheck and comment ratchet for cloud render fps
This commit is contained in:
@@ -158,6 +158,30 @@ describe("offloadHeavyMedia", () => {
|
||||
expect(second.get("index.html")!.toString()).toContain("https://assets.example/1/clip.mp4");
|
||||
});
|
||||
|
||||
it("leaves heavy files nothing references out of the archive, but keeps one a variable names", async () => {
|
||||
const dir = project({
|
||||
"index.html": html(`<video src="clip.mp4"></video>`),
|
||||
"clip.mp4": HEAVY,
|
||||
"assets/guide.mov": HEAVY,
|
||||
"assets/plate.png": HEAVY,
|
||||
"assets/small.txt": "notes",
|
||||
});
|
||||
const fileMap = stagePublishFiles(dir, OFFLOAD_MIN_BYTES);
|
||||
|
||||
await offloadHeavyMedia(dir, fileMap, {
|
||||
apiBaseUrl: "https://api.example",
|
||||
upload: fakeUpload(),
|
||||
cachePath: cachePath(),
|
||||
variablesText: JSON.stringify({ photo: "assets/plate.png" }),
|
||||
});
|
||||
|
||||
expect([...fileMap.keys()].sort()).toEqual([
|
||||
"assets/plate.png",
|
||||
"assets/small.txt",
|
||||
"index.html",
|
||||
]);
|
||||
});
|
||||
|
||||
describe("a dry run (no upload)", () => {
|
||||
const opts = { apiBaseUrl: "https://api.example" };
|
||||
const files = { "index.html": html(`<video src="clip.mp4"></video>`), "clip.mp4": HEAVY };
|
||||
@@ -456,7 +480,7 @@ describe("offloadHeavyMedia", () => {
|
||||
|
||||
expect(prepared?.equals(nested)).toBe(true);
|
||||
expect(fileMap.has("compositions/logo.gif")).toBe(false);
|
||||
expect(fileMap.has("logo.gif")).toBe(true);
|
||||
expect(fileMap.has("logo.gif")).toBe(false);
|
||||
});
|
||||
|
||||
it("hashes and encodes media over 4 GiB from disk, never reading it whole", async () => {
|
||||
@@ -704,11 +728,12 @@ describe("offloadHeavyMedia", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps a heavy file no reference names in the zip, since --variables can pick it at render time", async () => {
|
||||
it("keeps a heavy file only a --variables value names, and drops the one nothing names", async () => {
|
||||
const dir = project({
|
||||
"index.html": html(`<video data-var-src="clip" src="media/a.mp4"></video>`),
|
||||
"media/a.mp4": HEAVY,
|
||||
"media/b.mp4": HEAVY,
|
||||
"media/c.mp4": HEAVY,
|
||||
});
|
||||
const fileMap = buildPublishFileMap(dir);
|
||||
const upload = fakeUpload();
|
||||
@@ -717,11 +742,13 @@ describe("offloadHeavyMedia", () => {
|
||||
apiBaseUrl: "https://api.example",
|
||||
upload,
|
||||
cachePath: cachePath(),
|
||||
variablesText: JSON.stringify({ clip: "media/b.mp4" }),
|
||||
});
|
||||
|
||||
expect(report.map((item) => item.path)).toEqual(["media/a.mp4"]);
|
||||
expect(upload).toHaveBeenCalledTimes(1);
|
||||
expect(fileMap.has("media/b.mp4")).toBe(true);
|
||||
expect(fileMap.has("media/c.mp4")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps a heavy file a script builds from split strings in the zip", async () => {
|
||||
|
||||
@@ -165,6 +165,7 @@ export interface OffloadOptions {
|
||||
/** Overrides the renderer's GIF preparation for tests. */
|
||||
gifPrep?: GifPrep;
|
||||
onFile?: (item: OffloadedMedia) => void;
|
||||
variablesText?: string;
|
||||
}
|
||||
|
||||
type MediaKind = "video" | "audio" | "image";
|
||||
@@ -714,10 +715,11 @@ export async function offloadHeavyMedia(
|
||||
};
|
||||
const urls = new Map<string, string>();
|
||||
const report: OffloadedMedia[] = [];
|
||||
let referenced = new Set<string>();
|
||||
try {
|
||||
await prepareEntryGifs(ctx, fileMap);
|
||||
// Only files a reference points at: one used through render-time --variables must stay in the zip.
|
||||
const referenced = referencedFiles(ctx.absDir, fileMap);
|
||||
referenced = referencedFiles(ctx.absDir, fileMap);
|
||||
for (const [path, file] of [...fileMap].sort(([a], [b]) => a.localeCompare(b))) {
|
||||
if (!referenced.has(path)) continue;
|
||||
const item = await offloadFile(ctx, path, file);
|
||||
@@ -733,9 +735,27 @@ export async function offloadHeavyMedia(
|
||||
|
||||
if (urls.size > 0) rewriteReferences(ctx.absDir, fileMap, (key) => urls.get(key) ?? null);
|
||||
dropReplacedFiles(fileMap, report, ctx.preparedGifSources, [...urls.values()]);
|
||||
dropUnusedHeavyFiles(ctx, referenced, [...urls.values()]);
|
||||
return report;
|
||||
}
|
||||
|
||||
function dropUnusedHeavyFiles(
|
||||
ctx: OffloadContext,
|
||||
referenced: Set<string>,
|
||||
assetUrls: string[],
|
||||
): void {
|
||||
const { fileMap } = ctx;
|
||||
const withoutUrls = (text: string) =>
|
||||
assetUrls.reduce((acc, url) => acc.replaceAll(url, ""), text);
|
||||
const code = withoutUrls(scriptCode(fileMap));
|
||||
const variables = ctx.opts.variablesText ?? "";
|
||||
for (const [path, file] of [...fileMap]) {
|
||||
if (referenced.has(path) || stagedSize(file) < OFFLOAD_MIN_BYTES) continue;
|
||||
if (variables.includes(basename(path))) continue;
|
||||
if (!isStillMentioned(fileMap, path, code, withoutUrls)) fileMap.delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
function dropReplacedFiles(
|
||||
fileMap: Map<string, StagedFile>,
|
||||
report: OffloadedMedia[],
|
||||
|
||||
Reference in New Issue
Block a user