mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 00:18:27 +00:00
fix(cli): cloud render finds media whose file name is stored in another Unicode form than the page's (#7419)
* fix(cli): cloud render finds media whose file name is stored in another Unicode form than the page's * fix(cli): keep the archive-key change from raising publishProject's comment share * fix(cli): a page that names a decomposed file as the disk lists it still matches its archive entry
This commit is contained in:
@@ -1077,4 +1077,32 @@ describe("offloadHeavyMedia", () => {
|
||||
expect(gifPrep).not.toHaveBeenCalled();
|
||||
expect(fileMap.has("logo.png")).toBe(true);
|
||||
});
|
||||
it("offloads a file stored decomposed when the page names it composed, and the reverse", async () => {
|
||||
const composed = "media/vid\u00e9o.mp4";
|
||||
const decomposed = "media/vide\u0301o.mp4";
|
||||
const dir = project({
|
||||
"index.html": html(`<video src="${composed}"></video>`),
|
||||
[decomposed]: HEAVY,
|
||||
});
|
||||
const fileMap = buildPublishFileMap(dir);
|
||||
const report = await offloadHeavyMedia(dir, fileMap, {
|
||||
apiBaseUrl: "https://api.example",
|
||||
upload: fakeUpload(),
|
||||
cachePath: cachePath(),
|
||||
});
|
||||
expect(report.map((item) => item.path)).toEqual([composed]);
|
||||
expect(fileMap.get("index.html")!.toString()).toContain("https://assets.example/");
|
||||
|
||||
const other = project({
|
||||
"index.html": html(`<video src="${decomposed}"></video>`),
|
||||
[composed]: HEAVY,
|
||||
});
|
||||
const otherMap = buildPublishFileMap(other);
|
||||
await offloadHeavyMedia(other, otherMap, {
|
||||
apiBaseUrl: "https://api.example",
|
||||
upload: fakeUpload(),
|
||||
cachePath: cachePath(),
|
||||
});
|
||||
expect(otherMap.get("index.html")!.toString()).toContain("https://assets.example/");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,6 +35,7 @@ import { formatBytes } from "../ui/format.js";
|
||||
import { bytesMatchExtension } from "./offloadSniff.js";
|
||||
import { type PlayedSegment, planTrim } from "./offloadTrim.js";
|
||||
import {
|
||||
archiveKey,
|
||||
assertUnchanged,
|
||||
type HtmlAttributeResolver,
|
||||
readChecked,
|
||||
@@ -929,9 +930,9 @@ function htmlSrcKey(
|
||||
if (!clean || isRemoteOrInlineUrl(clean)) return null;
|
||||
const rootRelative = clean.startsWith("/")
|
||||
? clean
|
||||
: rewriteAssetPath(entryPath, clean, (p) => fileMap.has(p));
|
||||
: rewriteAssetPath(entryPath, clean, (p) => fileMap.has(archiveKey(p)));
|
||||
for (const candidate of resolveLocalAssetCandidates(absDir, rootRelative)) {
|
||||
const key = relative(absDir, candidate).replaceAll("\\", "/");
|
||||
const key = archiveKey(relative(absDir, candidate).replaceAll("\\", "/"));
|
||||
if (fileMap.has(key)) return key;
|
||||
}
|
||||
return null;
|
||||
@@ -956,7 +957,7 @@ function rewriteReferences(
|
||||
): void {
|
||||
const urlFor: UrlFor = (rootRelative) => {
|
||||
for (const candidate of resolveLocalAssetCandidates(absDir, rootRelative)) {
|
||||
const url = urlForKey(relative(absDir, candidate).replaceAll("\\", "/"));
|
||||
const url = urlForKey(archiveKey(relative(absDir, candidate).replaceAll("\\", "/")));
|
||||
if (url) return url;
|
||||
}
|
||||
return null;
|
||||
@@ -1032,7 +1033,11 @@ function rewriteHtmlDocument(
|
||||
const referrerAbsDir = resolve(absDir, dirname(entryPath));
|
||||
// Sub-composition srcs resolve the way the renderer inlines them.
|
||||
const resolveTarget: HtmlAttributeResolver = (raw) =>
|
||||
localTarget(raw, (clean) => rewriteAssetPath(entryPath, clean, (p) => fileMap.has(p)), urlFor);
|
||||
localTarget(
|
||||
raw,
|
||||
(clean) => rewriteAssetPath(entryPath, clean, (p) => fileMap.has(archiveKey(p))),
|
||||
urlFor,
|
||||
);
|
||||
const { document } = parseHTML(html);
|
||||
const attrs = rewriteHtmlAttributes(document, referrerAbsDir, entryPath, resolveTarget, {
|
||||
attrs: ["src", "poster", "href"],
|
||||
|
||||
Reference in New Issue
Block a user