mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix: preview image prep reads no HEIC or GIF outside the project unless render would (#8001)
* fix: preview image prep reads no HEIC or GIF outside the project unless render would Image prep now keeps sources inside the project unless the caller opts in with allowOutsideFiles. Studio preview opts in only when a local render of the project would bring in outside files, so a received project's preview converts nothing from outside it. * fix: keep comment share flat; Windows share test takes the trusted path The Windows path test checks that image prep never looks at a share. It now passes allowOutsideFiles, so a local path is still looked up on the widest path even though the fake project folder does not exist. * test(cli): the Windows share preview test takes the trusted outside-file path The fake C:\project folder does not exist on the test host, so the received-project check fails closed and preview would contain every source. The test mocks that check to allow outside files, so a local path is still looked up on the widest path.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { createStudioServer, type StudioServer } from "./studioServer.js";
|
||||
import { cleanupStudioServerRoot, makeStudioServerRoot } from "./studioServerTestFixture.js";
|
||||
|
||||
@@ -141,3 +142,50 @@ describe("bundled GSAP", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("preview image prep and files outside the project", () => {
|
||||
const heic = fileURLToPath(
|
||||
new URL("../../../producer/tests/fixtures/heic/rotated-grid.heic", import.meta.url),
|
||||
);
|
||||
const outsidePhoto = () => path.join(root, "Pictures", "IMG_0001.HEIC");
|
||||
const preparedHeif = () => path.join(projectDir, ".hyperframes", "prepared-assets", "heif");
|
||||
|
||||
beforeEach(() => {
|
||||
fs.mkdirSync(path.dirname(outsidePhoto()));
|
||||
fs.copyFileSync(heic, outsidePhoto());
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, "index.html"),
|
||||
`<!doctype html><html><body><div data-composition-id="main" data-width="320" data-height="180">
|
||||
<img id="photo" src="../Pictures/IMG_0001.HEIC" data-start="0" data-duration="1">
|
||||
</div></body></html>`,
|
||||
);
|
||||
});
|
||||
|
||||
async function previewPhotoSrc(): Promise<string | undefined> {
|
||||
const html = await (await server.app.request("/api/projects/film/preview")).text();
|
||||
return html.match(/<img [^>]*id="photo"[^>]*src="([^"]+)"/)?.[1];
|
||||
}
|
||||
|
||||
it("converts no outside photo for a received project, as its render would not", async () => {
|
||||
fs.mkdirSync(path.join(projectDir, ".hyperframes"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(projectDir, ".hyperframes", "received-files.json"),
|
||||
JSON.stringify({ files: ["index.html"] }),
|
||||
);
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
try {
|
||||
expect(await previewPhotoSrc()).not.toContain("prepared-assets");
|
||||
expect(await previewPhotoSrc()).not.toContain("prepared-assets");
|
||||
expect(fs.existsSync(preparedHeif())).toBe(false);
|
||||
const refusals = warn.mock.calls.filter(([line]) => String(line).includes("someone else"));
|
||||
expect(refusals).toHaveLength(1);
|
||||
} finally {
|
||||
warn.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("still converts an outside photo for the developer's own project, as its render does", async () => {
|
||||
expect(await previewPhotoSrc()).toMatch(/^\.hyperframes\/prepared-assets\/heif\//);
|
||||
expect(fs.readdirSync(preparedHeif())).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,6 +35,8 @@ vi.mock("node:fs", async () => {
|
||||
return { ...fs, ...overrides, default: { ...fs, ...overrides } };
|
||||
});
|
||||
|
||||
vi.mock("../utils/receivedRender.js", () => ({ outsideAssetsAllowed: () => true }));
|
||||
|
||||
const { createStudioServer } = await import("./studioServer.js");
|
||||
const { cleanupStudioServerRoot, makeStudioServerRoot } =
|
||||
await import("./studioServerTestFixture.js");
|
||||
|
||||
@@ -540,6 +540,13 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
// launching a browser shutdown() has no way to know about and close.
|
||||
let shuttingDown = false;
|
||||
|
||||
const previewWarnings = new Set<string>();
|
||||
const warnPreviewOnce = (line: string) => {
|
||||
if (previewWarnings.has(line)) return;
|
||||
previewWarnings.add(line);
|
||||
console.warn(`[studio] ${line}`);
|
||||
};
|
||||
|
||||
const adapter: PreviewApiAdapter = {
|
||||
history: () => (hostAppOwnsHistory ? null : projectHistory()),
|
||||
loadSharp: () => loadSharpInBackground("image thumbnails"),
|
||||
@@ -594,11 +601,13 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
const preparedDirs = [gifOutputDir, gifDownloadDir, heifOutputDir];
|
||||
if (!preparedDirs.every((dir) => isLinkFreeWithinProject(project.dir, dir)))
|
||||
return injectDeterministicFontFaces(html);
|
||||
const allowOutsideFiles = outsideAssetsAllowed(project.dir, undefined, warnPreviewOnce);
|
||||
const { html: htmlWithJpegs } = await prepareHeifImageInputs(html, {
|
||||
projectDir: project.dir,
|
||||
downloadDir: gifDownloadDir,
|
||||
outputDir: heifOutputDir,
|
||||
outputSrcPrefix: ".hyperframes/prepared-assets/heif",
|
||||
allowOutsideFiles,
|
||||
onFailure: (error) => console.warn(`[studio] ${error.message}`),
|
||||
});
|
||||
const prepared = await prepareAnimatedGifInputs(htmlWithJpegs, {
|
||||
@@ -606,6 +615,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
|
||||
downloadDir: gifDownloadDir,
|
||||
outputDir: gifOutputDir,
|
||||
outputSrcPrefix: ".hyperframes/prepared-assets/gif",
|
||||
allowOutsideFiles,
|
||||
cacheDir: gifOutputDir,
|
||||
sourceAssets: await downloadRemoteGifImageSources(html, gifDownloadDir, (url, destDir) =>
|
||||
downloadToTemp(url, destDir, undefined, undefined, undefined, {
|
||||
|
||||
Reference in New Issue
Block a user