@hyperframes/producer 0.9.52 → 0.9.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/distributed.js +204 -121
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.js +394 -159
- package/dist/public-server.js +372 -138
- package/dist/server.d.ts +18 -1
- package/dist/services/assetMediaType.d.ts +1 -0
- package/dist/services/htmlCompiler.d.ts +11 -0
- package/dist/services/hyperframeLint.d.ts +1 -1
- package/dist/services/render/shared.d.ts +1 -0
- package/dist/services/render/stages/audioStage.d.ts +2 -1
- package/dist/services/render/stages/compileStage.d.ts +1 -1
- package/dist/services/render/stages/extractVideosStage.d.ts +14 -6
- package/dist/services/renderOrchestrator.d.ts +6 -1
- package/package.json +7 -7
package/dist/public-server.js
CHANGED
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
rmSync as rmSync13,
|
|
11
11
|
createReadStream as createReadStream3
|
|
12
12
|
} from "node:fs";
|
|
13
|
-
import { resolve as resolve10, dirname as
|
|
13
|
+
import { resolve as resolve10, dirname as dirname17, join as join37 } from "node:path";
|
|
14
14
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
15
15
|
import { parseArgs } from "node:util";
|
|
16
|
+
import { isIP } from "node:net";
|
|
16
17
|
import crypto from "node:crypto";
|
|
17
18
|
import { Hono as Hono2 } from "hono";
|
|
18
19
|
import { streamSSE } from "hono/streaming";
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD3,
|
|
23
24
|
referenceBackgroundResult as referenceBackgroundResult5
|
|
24
25
|
} from "@hyperframes/engine";
|
|
26
|
+
import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
|
|
25
27
|
|
|
26
28
|
// src/services/renderOrchestrator.ts
|
|
27
29
|
import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
|
|
@@ -84,7 +86,7 @@ import {
|
|
|
84
86
|
referenceBackgroundResult,
|
|
85
87
|
createReferenceBackgroundRecorder
|
|
86
88
|
} from "@hyperframes/engine";
|
|
87
|
-
import { join as join32, dirname as
|
|
89
|
+
import { join as join32, dirname as dirname14, resolve as resolve8 } from "path";
|
|
88
90
|
import { totalmem as totalmem2 } from "node:os";
|
|
89
91
|
import { randomUUID } from "crypto";
|
|
90
92
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
@@ -92,7 +94,7 @@ import { fileURLToPath as fileURLToPath4 } from "url";
|
|
|
92
94
|
// src/services/fileServer.ts
|
|
93
95
|
import { Hono } from "hono";
|
|
94
96
|
import { serve } from "@hono/node-server";
|
|
95
|
-
import { settleOnBrowserSafePort } from "@hyperframes/engine";
|
|
97
|
+
import { answerOwnLoopbackHostOnly, settleOnBrowserSafePort } from "@hyperframes/engine";
|
|
96
98
|
import {
|
|
97
99
|
existsSync as existsSync2,
|
|
98
100
|
realpathSync,
|
|
@@ -109,7 +111,7 @@ import { Readable } from "node:stream";
|
|
|
109
111
|
import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
|
|
110
112
|
import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
|
|
111
113
|
import { fpsToNumber } from "@hyperframes/core";
|
|
112
|
-
import { isPrivateFileUnder,
|
|
114
|
+
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
|
113
115
|
import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
|
|
114
116
|
import { openRangeEnd } from "@hyperframes/studio-server/media-range";
|
|
115
117
|
|
|
@@ -332,6 +334,7 @@ var MIME_TYPES = {
|
|
|
332
334
|
".css": "text/css; charset=utf-8",
|
|
333
335
|
".js": "application/javascript; charset=utf-8",
|
|
334
336
|
".mjs": "application/javascript; charset=utf-8",
|
|
337
|
+
".cjs": "application/javascript; charset=utf-8",
|
|
335
338
|
".json": "application/json; charset=utf-8",
|
|
336
339
|
".cube": "text/plain; charset=utf-8",
|
|
337
340
|
".png": "image/png",
|
|
@@ -875,6 +878,12 @@ function createFileServer(options) {
|
|
|
875
878
|
const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
|
|
876
879
|
const app = new Hono();
|
|
877
880
|
const warnLeftOut = (line) => console.warn(`[FileServer] ${line}`);
|
|
881
|
+
let listeningPort = -1;
|
|
882
|
+
app.use(async function loadEachFileOnlyAsItsNamedType(c, next) {
|
|
883
|
+
await next();
|
|
884
|
+
c.res.headers.set("X-Content-Type-Options", "nosniff");
|
|
885
|
+
});
|
|
886
|
+
answerOwnLoopbackHostOnly(app, () => listeningPort);
|
|
878
887
|
app.get("/*", async (c) => {
|
|
879
888
|
let requestPath = c.req.path;
|
|
880
889
|
if (requestPath === "/") requestPath = "/index.html";
|
|
@@ -884,7 +893,7 @@ function createFileServer(options) {
|
|
|
884
893
|
const candidate = join2(root, relativePath);
|
|
885
894
|
const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
|
|
886
895
|
if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
|
|
887
|
-
if (isPrivateFileUnder(root, candidate,
|
|
896
|
+
if (isPrivateFileUnder(root, candidate, isStudioPrivatePath)) continue;
|
|
888
897
|
const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
|
|
889
898
|
if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
|
|
890
899
|
file = openRegularFile(candidate);
|
|
@@ -970,6 +979,7 @@ function createFileServer(options) {
|
|
|
970
979
|
const server = serve({ fetch: app.fetch, port, hostname: "127.0.0.1" }, (info) => {
|
|
971
980
|
const bound = port === 0 ? settleOnBrowserSafePort(server, "127.0.0.1") : Promise.resolve(info.port);
|
|
972
981
|
bound.then((boundPort) => {
|
|
982
|
+
listeningPort = boundPort;
|
|
973
983
|
resolve11({
|
|
974
984
|
url: `http://localhost:${boundPort}`,
|
|
975
985
|
port: boundPort,
|
|
@@ -1133,6 +1143,9 @@ import {
|
|
|
1133
1143
|
import {
|
|
1134
1144
|
mediaIdPathSegment
|
|
1135
1145
|
} from "@hyperframes/engine";
|
|
1146
|
+
function audioWorkDir(workDir) {
|
|
1147
|
+
return join3(workDir, "audio-work");
|
|
1148
|
+
}
|
|
1136
1149
|
var BROWSER_MEDIA_EPSILON = 1e-4;
|
|
1137
1150
|
function resolveBrowserMediaEnd(start, end, duration) {
|
|
1138
1151
|
return Number.isFinite(duration) && duration > 0 ? start + duration : end;
|
|
@@ -6529,15 +6542,29 @@ function countAuthoredTimedClips(html) {
|
|
|
6529
6542
|
// src/services/render/stages/compileStage.ts
|
|
6530
6543
|
import { existsSync as existsSync12, writeFileSync as writeFileSync5 } from "node:fs";
|
|
6531
6544
|
import { join as join20, relative as relative3 } from "node:path";
|
|
6545
|
+
import { privateCacheRoot } from "@hyperframes/engine";
|
|
6532
6546
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
6533
6547
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
6534
6548
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
6535
6549
|
|
|
6536
6550
|
// src/services/htmlCompiler.ts
|
|
6537
6551
|
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
6552
|
+
import {
|
|
6553
|
+
cssRuleMatches,
|
|
6554
|
+
cssUrlMatches,
|
|
6555
|
+
fontFaceBlockMatches,
|
|
6556
|
+
hasBackgroundImageDeclaration,
|
|
6557
|
+
importRuleMatches,
|
|
6558
|
+
localFontFaceUrlMatches,
|
|
6559
|
+
remoteBackgroundUrlMatches,
|
|
6560
|
+
remoteFontFaceUrlMatches,
|
|
6561
|
+
replaceMatches,
|
|
6562
|
+
styleBlockMatches,
|
|
6563
|
+
stylesheetLinkMatches
|
|
6564
|
+
} from "@hyperframes/parsers/css-url-scans";
|
|
6538
6565
|
import { createHash as createHash6 } from "node:crypto";
|
|
6539
6566
|
import { createReadStream as createReadStream2, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
6540
|
-
import { join as join19, dirname as
|
|
6567
|
+
import { join as join19, dirname as dirname9, resolve as resolve7, basename as basename5, relative as relative2, sep as sep3 } from "path";
|
|
6541
6568
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
6542
6569
|
|
|
6543
6570
|
// src/services/bundledScripts.ts
|
|
@@ -6560,7 +6587,6 @@ import {
|
|
|
6560
6587
|
extractResolvedMedia,
|
|
6561
6588
|
clampDurations,
|
|
6562
6589
|
shouldClampResolvedMediaDuration,
|
|
6563
|
-
CSS_URL_RE,
|
|
6564
6590
|
isNonRelativeUrl,
|
|
6565
6591
|
parseStrictFiniteTimingNumber,
|
|
6566
6592
|
readMediaStart,
|
|
@@ -6610,7 +6636,7 @@ import {
|
|
|
6610
6636
|
readTextFile,
|
|
6611
6637
|
resolveCompositionSrc
|
|
6612
6638
|
} from "@hyperframes/parsers/asset-resolution";
|
|
6613
|
-
import { isPrivateFileUnder as isPrivateFileUnder2,
|
|
6639
|
+
import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
|
|
6614
6640
|
|
|
6615
6641
|
// src/services/renderMediaCollector.ts
|
|
6616
6642
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -7442,9 +7468,11 @@ import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position
|
|
|
7442
7468
|
|
|
7443
7469
|
// src/services/assetMediaType.ts
|
|
7444
7470
|
import { existsSync as existsSync10 } from "node:fs";
|
|
7445
|
-
import { join as join18 } from "node:path";
|
|
7471
|
+
import { dirname as dirname8, join as join18 } from "node:path";
|
|
7446
7472
|
import {
|
|
7447
7473
|
fingerprintElementId,
|
|
7474
|
+
isHttpUrl as isHttpUrl2,
|
|
7475
|
+
isInsideAssetRoots,
|
|
7448
7476
|
isNotMediaPayload,
|
|
7449
7477
|
playlistLeavesItsFolder,
|
|
7450
7478
|
NotMediaPayloadError,
|
|
@@ -7490,17 +7518,17 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
|
|
|
7490
7518
|
}
|
|
7491
7519
|
]);
|
|
7492
7520
|
}
|
|
7493
|
-
function
|
|
7494
|
-
return
|
|
7521
|
+
function mediaAssetRoots(projectDir, compiledDir) {
|
|
7522
|
+
return [projectDir, compiledDir, join18(dirname8(compiledDir), "downloads")];
|
|
7495
7523
|
}
|
|
7496
7524
|
function dropMediaOutsideProject(input) {
|
|
7497
7525
|
const { projectDir, workDir, composition, log } = input;
|
|
7498
7526
|
const compiledDir = join18(workDir, "compiled");
|
|
7499
|
-
const roots =
|
|
7527
|
+
const roots = mediaAssetRoots(projectDir, compiledDir);
|
|
7500
7528
|
const staysInside = ({ id, src }) => {
|
|
7501
|
-
if (!src ||
|
|
7529
|
+
if (!src || isHttpUrl2(src)) return true;
|
|
7502
7530
|
const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
|
|
7503
|
-
if (
|
|
7531
|
+
if (isInsideAssetRoots(path, roots)) return true;
|
|
7504
7532
|
if (input.allowOutsideProjectAssets) {
|
|
7505
7533
|
const refusal = outsideAssetRefusal(projectDir, path);
|
|
7506
7534
|
if (refusal) log.warn(`[Render] ${leftOutOfRender(`Media "${id}"`, src, refusal)}`);
|
|
@@ -7538,7 +7566,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
7538
7566
|
];
|
|
7539
7567
|
const byPath = /* @__PURE__ */ new Map();
|
|
7540
7568
|
for (const reference of references) {
|
|
7541
|
-
if (!reference.src ||
|
|
7569
|
+
if (!reference.src || isHttpUrl2(reference.src)) continue;
|
|
7542
7570
|
const resolvedPath = resolveProjectRelativeSrc3(
|
|
7543
7571
|
reference.src,
|
|
7544
7572
|
input.projectDir,
|
|
@@ -7638,11 +7666,17 @@ function normalizeCompositionSrcs(html, projectDir) {
|
|
|
7638
7666
|
return `${name}${quote}${relative2(projectDir, file).split(sep3).join("/")}${quote}`;
|
|
7639
7667
|
});
|
|
7640
7668
|
}
|
|
7641
|
-
|
|
7669
|
+
var COMPOSITION_FILE = /\.html?$/i;
|
|
7670
|
+
var NOT_A_COMPOSITION_FILE = "it is not an .html file, so it is refused";
|
|
7671
|
+
function resolveCompositionPath(projectDir, src, assetRoot) {
|
|
7642
7672
|
const file = resolveCompositionSrc(projectDir, src);
|
|
7643
7673
|
return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
|
|
7644
7674
|
}
|
|
7645
|
-
|
|
7675
|
+
function resolveCompositionFile(projectDir, src, assetRoot) {
|
|
7676
|
+
const file = resolveCompositionPath(projectDir, src, assetRoot);
|
|
7677
|
+
return file !== null && COMPOSITION_FILE.test(file) ? file : null;
|
|
7678
|
+
}
|
|
7679
|
+
var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
|
|
7646
7680
|
function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
|
|
7647
7681
|
const { document: document2 } = parseHTML5(html);
|
|
7648
7682
|
const hosts = [...document2.querySelectorAll("[data-composition-src]")];
|
|
@@ -7651,7 +7685,7 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
|
|
|
7651
7685
|
const srcPath = el.getAttribute("data-composition-src");
|
|
7652
7686
|
if (!srcPath) continue;
|
|
7653
7687
|
if (isUnresolvedAssetPlaceholder(srcPath)) continue;
|
|
7654
|
-
const filePath =
|
|
7688
|
+
const filePath = resolveCompositionPath(projectDir, srcPath, assetRoot);
|
|
7655
7689
|
if (filePath === null) {
|
|
7656
7690
|
problems.push({ srcPath, detail: "it is outside the project folder" });
|
|
7657
7691
|
continue;
|
|
@@ -7661,7 +7695,14 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
|
|
|
7661
7695
|
continue;
|
|
7662
7696
|
}
|
|
7663
7697
|
if (isPrivateCompositionFile(projectDir, filePath)) {
|
|
7664
|
-
problems.push({
|
|
7698
|
+
problems.push({
|
|
7699
|
+
srcPath,
|
|
7700
|
+
detail: "it is git metadata, an env file or a private tool record"
|
|
7701
|
+
});
|
|
7702
|
+
continue;
|
|
7703
|
+
}
|
|
7704
|
+
if (!COMPOSITION_FILE.test(filePath)) {
|
|
7705
|
+
problems.push({ srcPath, detail: NOT_A_COMPOSITION_FILE });
|
|
7665
7706
|
continue;
|
|
7666
7707
|
}
|
|
7667
7708
|
if (visited.has(filePath)) continue;
|
|
@@ -7759,7 +7800,6 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
|
|
|
7759
7800
|
function detectThreeDTransformUsage(html) {
|
|
7760
7801
|
return THREE_D_CONTEXT_PATTERN.test(html);
|
|
7761
7802
|
}
|
|
7762
|
-
var BACKGROUND_IMAGE_DECL_PATTERN = /(?:^|;|\{)\s*background(?:-image)?\s*:[^;}]*(?:\bgradient\s*\(|url\s*\()/i;
|
|
7763
7803
|
function detectAncestorBackgroundImage(html) {
|
|
7764
7804
|
const { document: document2 } = parseHTML5(html);
|
|
7765
7805
|
const root = document2.querySelector("[data-composition-id]");
|
|
@@ -7771,13 +7811,13 @@ function detectAncestorBackgroundImage(html) {
|
|
|
7771
7811
|
}
|
|
7772
7812
|
for (const el of ancestors) {
|
|
7773
7813
|
const style = el.getAttribute("style");
|
|
7774
|
-
if (style &&
|
|
7814
|
+
if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
|
|
7775
7815
|
}
|
|
7776
7816
|
for (const styleEl of document2.querySelectorAll("style")) {
|
|
7777
7817
|
const css = styleEl.textContent ?? "";
|
|
7778
|
-
for (const rule of css
|
|
7779
|
-
const [, selectorList
|
|
7780
|
-
if (!
|
|
7818
|
+
for (const { parts: rule } of cssRuleMatches(css)) {
|
|
7819
|
+
const [, selectorList, declarations] = rule;
|
|
7820
|
+
if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
|
|
7781
7821
|
for (const selector of selectorList.split(",")) {
|
|
7782
7822
|
const sel = selector.trim();
|
|
7783
7823
|
if (!sel || sel.startsWith("@")) continue;
|
|
@@ -7987,7 +8027,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
7987
8027
|
workItems.map(async (item) => {
|
|
7988
8028
|
const { html: compiledSub } = await compileHtmlFile(
|
|
7989
8029
|
rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
|
|
7990
|
-
|
|
8030
|
+
dirname9(item.filePath),
|
|
7991
8031
|
downloadDir,
|
|
7992
8032
|
void 0,
|
|
7993
8033
|
urlByAbsentLocalPath,
|
|
@@ -8098,7 +8138,6 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
8098
8138
|
el.textContent = dedupedStyles[i] ?? "";
|
|
8099
8139
|
});
|
|
8100
8140
|
const styleEls = head ? Array.from(head.querySelectorAll("style")) : [];
|
|
8101
|
-
const importRe = /@import\s+url\([^)]*\)\s*;|@import\s+["'][^"']+["']\s*;/gi;
|
|
8102
8141
|
for (const run of styleEls.length > 1 ? headStyleRuns(styleEls) : []) {
|
|
8103
8142
|
const imports = [];
|
|
8104
8143
|
const cssParts = [];
|
|
@@ -8106,7 +8145,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
8106
8145
|
for (const el of run) {
|
|
8107
8146
|
const raw = (el.textContent || "").trim();
|
|
8108
8147
|
if (!raw) continue;
|
|
8109
|
-
const nonImportCss = raw
|
|
8148
|
+
const nonImportCss = replaceMatches(raw, importRuleMatches(raw), (match) => {
|
|
8110
8149
|
const cleaned = match.trim();
|
|
8111
8150
|
if (!seenImports.has(cleaned)) {
|
|
8112
8151
|
seenImports.add(cleaned);
|
|
@@ -8416,7 +8455,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
8416
8455
|
for (const styleEl of document2.querySelectorAll("style")) {
|
|
8417
8456
|
const css = styleEl.textContent || "";
|
|
8418
8457
|
if (!css.includes("url(")) continue;
|
|
8419
|
-
const rewritten = css
|
|
8458
|
+
const rewritten = replaceMatches(css, cssUrlMatches(css), (full, quote, rawUrl) => {
|
|
8420
8459
|
const result = processPath((rawUrl || "").trim());
|
|
8421
8460
|
if (!result) return full;
|
|
8422
8461
|
return `url(${quote || ""}${result}${quote || ""})`;
|
|
@@ -8426,7 +8465,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
8426
8465
|
for (const el of document2.querySelectorAll("[style]")) {
|
|
8427
8466
|
const style = el.getAttribute("style") || "";
|
|
8428
8467
|
if (!style.includes("url(")) continue;
|
|
8429
|
-
const rewritten = style
|
|
8468
|
+
const rewritten = replaceMatches(style, cssUrlMatches(style), (full, quote, rawUrl) => {
|
|
8430
8469
|
const result = processPath((rawUrl || "").trim());
|
|
8431
8470
|
if (!result) return full;
|
|
8432
8471
|
return `url(${quote || ""}${result}${quote || ""})`;
|
|
@@ -8529,13 +8568,10 @@ async function localizeRemoteImageSources(html, downloadDir) {
|
|
|
8529
8568
|
"Localized remote image source(s)"
|
|
8530
8569
|
);
|
|
8531
8570
|
}
|
|
8532
|
-
var REMOTE_BG_URL_RE = /background(?:-image)?\s*:\s*[^;}"']*?url\(\s*["']?(https?:\/\/[^"')]+)["']?\s*\)/gi;
|
|
8533
8571
|
async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
8534
8572
|
const urlSet = /* @__PURE__ */ new Set();
|
|
8535
|
-
const
|
|
8536
|
-
|
|
8537
|
-
while ((m = re.exec(html)) !== null) {
|
|
8538
|
-
if (m[1] && !isGoogleFontsUrl(m[1])) urlSet.add(m[1]);
|
|
8573
|
+
for (const { parts } of remoteBackgroundUrlMatches(html)) {
|
|
8574
|
+
if (parts[1] && !isGoogleFontsUrl(parts[1])) urlSet.add(parts[1]);
|
|
8539
8575
|
}
|
|
8540
8576
|
return downloadAndRewriteUrls(
|
|
8541
8577
|
urlSet,
|
|
@@ -8548,7 +8584,6 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
8548
8584
|
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
8549
8585
|
);
|
|
8550
8586
|
}
|
|
8551
|
-
var REMOTE_FONTFACE_URL_RE = /url\(["']?(https?:\/\/[^"')]+)["']?\)/gi;
|
|
8552
8587
|
function isGoogleFontsUrl(href) {
|
|
8553
8588
|
try {
|
|
8554
8589
|
const host = new URL(href).hostname.toLowerCase();
|
|
@@ -8576,31 +8611,33 @@ async function fetchExternalStylesheetCss(href) {
|
|
|
8576
8611
|
}
|
|
8577
8612
|
function extractFontFaceBlocks(css) {
|
|
8578
8613
|
const blocks = [];
|
|
8614
|
+
const closes = matchingBraces(css);
|
|
8579
8615
|
const atRule = /@font-face\s*/gi;
|
|
8580
|
-
let
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
if (
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
else if (css[i] === "}") depth--;
|
|
8589
|
-
}
|
|
8590
|
-
if (depth === 0) {
|
|
8591
|
-
blocks.push(css.slice(m.index, i));
|
|
8592
|
-
atRule.lastIndex = i;
|
|
8593
|
-
}
|
|
8616
|
+
let open = -1;
|
|
8617
|
+
for (let m = atRule.exec(css); m; m = atRule.exec(css)) {
|
|
8618
|
+
if (open < atRule.lastIndex) open = css.indexOf("{", atRule.lastIndex);
|
|
8619
|
+
if (open === -1) break;
|
|
8620
|
+
const close = closes.get(open);
|
|
8621
|
+
if (close === void 0) continue;
|
|
8622
|
+
blocks.push(css.slice(m.index, close + 1));
|
|
8623
|
+
atRule.lastIndex = close + 1;
|
|
8594
8624
|
}
|
|
8595
8625
|
return blocks;
|
|
8596
8626
|
}
|
|
8627
|
+
function matchingBraces(css) {
|
|
8628
|
+
const closes = /* @__PURE__ */ new Map();
|
|
8629
|
+
const unclosed = [];
|
|
8630
|
+
for (let i = 0; i < css.length; i++) {
|
|
8631
|
+
if (css[i] === "{") unclosed.push(i);
|
|
8632
|
+
else if (css[i] === "}" && unclosed.length > 0) closes.set(unclosed.pop(), i);
|
|
8633
|
+
}
|
|
8634
|
+
return closes;
|
|
8635
|
+
}
|
|
8597
8636
|
async function inlineExternalFontStylesheets(html) {
|
|
8598
|
-
const linkRe = /<link\b[^>]*\brel=["']stylesheet["'][^>]*>/gi;
|
|
8599
8637
|
const hrefRe = /\bhref=["']([^"']+)["']/i;
|
|
8600
8638
|
const linkMatches = [];
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
const tag = linkMatch[0];
|
|
8639
|
+
for (const { parts } of stylesheetLinkMatches(html)) {
|
|
8640
|
+
const tag = parts[0];
|
|
8604
8641
|
const hrefMatch = hrefRe.exec(tag);
|
|
8605
8642
|
if (!hrefMatch?.[1]) continue;
|
|
8606
8643
|
const href = hrefMatch[1];
|
|
@@ -8641,16 +8678,18 @@ ${fontFaceBlocks.join("\n")}
|
|
|
8641
8678
|
}
|
|
8642
8679
|
function projectStylesheetFontFamilies(html, projectDir) {
|
|
8643
8680
|
const families = [];
|
|
8644
|
-
for (const
|
|
8681
|
+
for (const {
|
|
8682
|
+
parts: [tag]
|
|
8683
|
+
} of stylesheetLinkMatches(html)) {
|
|
8645
8684
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
8646
8685
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
8647
8686
|
const sheet = resolve7(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
8648
8687
|
if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
8649
8688
|
for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
|
|
8650
8689
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
8651
|
-
const shipsFile = [...face
|
|
8690
|
+
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
8652
8691
|
const path = decodedUrlPath(url);
|
|
8653
|
-
const file = path.startsWith("/") ? resolve7(projectDir, `.${path}`) : resolve7(
|
|
8692
|
+
const file = path.startsWith("/") ? resolve7(projectDir, `.${path}`) : resolve7(dirname9(sheet), path);
|
|
8654
8693
|
return isPathInside(file, projectDir) && existsSync11(file);
|
|
8655
8694
|
});
|
|
8656
8695
|
if (family && shipsFile) families.push(family);
|
|
@@ -8659,11 +8698,9 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
8659
8698
|
return families;
|
|
8660
8699
|
}
|
|
8661
8700
|
function collectFontFaceUrls(html) {
|
|
8662
|
-
const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
8663
8701
|
const urlSet = /* @__PURE__ */ new Set();
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
const cssText = styleMatch[1] ?? "";
|
|
8702
|
+
for (const { parts } of styleBlockMatches(html)) {
|
|
8703
|
+
const cssText = parts[1];
|
|
8667
8704
|
let i = 0;
|
|
8668
8705
|
while (i < cssText.length) {
|
|
8669
8706
|
const atIdx = cssText.indexOf("@font-face", i);
|
|
@@ -8678,10 +8715,8 @@ function collectFontFaceUrls(html) {
|
|
|
8678
8715
|
j++;
|
|
8679
8716
|
}
|
|
8680
8717
|
const block = cssText.slice(braceStart + 1, j - 1);
|
|
8681
|
-
const
|
|
8682
|
-
|
|
8683
|
-
while ((urlMatch = urlRe.exec(block)) !== null) {
|
|
8684
|
-
if (urlMatch[1]) urlSet.add(urlMatch[1]);
|
|
8718
|
+
for (const { parts: parts2 } of remoteFontFaceUrlMatches(block)) {
|
|
8719
|
+
if (parts2[1]) urlSet.add(parts2[1]);
|
|
8685
8720
|
}
|
|
8686
8721
|
i = j;
|
|
8687
8722
|
}
|
|
@@ -8698,7 +8733,6 @@ function localizeFontFaceUrls(html, downloadDir) {
|
|
|
8698
8733
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
8699
8734
|
);
|
|
8700
8735
|
}
|
|
8701
|
-
var LOCAL_FONTFACE_URL_RE = /url\(["']?(?!data:|file:|https?:\/\/)([^"')]+)["']?\)/gi;
|
|
8702
8736
|
function urlOccurrenceRe(localPath) {
|
|
8703
8737
|
const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8704
8738
|
return new RegExp(`url\\((["']?)${escaped}\\1\\)`, "g");
|
|
@@ -8719,23 +8753,15 @@ async function readLocalFont(absPath) {
|
|
|
8719
8753
|
}
|
|
8720
8754
|
async function embedLocalFontFaces(html, projectDir, assetRoot, log = defaultLogger) {
|
|
8721
8755
|
const { fontToDataUri: toDataUri } = await import("@hyperframes/core/fonts/embed");
|
|
8722
|
-
const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
8723
|
-
const fontFaceRe = /@font-face\s*\{([^}]*)\}/gi;
|
|
8724
8756
|
let result = html;
|
|
8725
8757
|
const embeddedPaths = /* @__PURE__ */ new Set();
|
|
8726
8758
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
8727
8759
|
const fileBackedAbsolutePaths = /* @__PURE__ */ new Set();
|
|
8728
|
-
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
while ((ffMatch = ffRe.exec(cssText)) !== null) {
|
|
8734
|
-
const block = ffMatch[1] ?? "";
|
|
8735
|
-
const urlRe = new RegExp(LOCAL_FONTFACE_URL_RE.source, LOCAL_FONTFACE_URL_RE.flags);
|
|
8736
|
-
let urlMatch;
|
|
8737
|
-
while ((urlMatch = urlRe.exec(block)) !== null) {
|
|
8738
|
-
const localPath = urlMatch[1];
|
|
8760
|
+
for (const { parts: style } of styleBlockMatches(html)) {
|
|
8761
|
+
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
8762
|
+
const block = face[1];
|
|
8763
|
+
for (const { parts } of localFontFaceUrlMatches(block)) {
|
|
8764
|
+
const localPath = parts[1];
|
|
8739
8765
|
if (!localPath || embeddedPaths.has(localPath)) continue;
|
|
8740
8766
|
const absPath = localPath.startsWith("/") ? localPath : resolve7(projectDir, localPath);
|
|
8741
8767
|
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
|
|
@@ -8854,6 +8880,9 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
8854
8880
|
if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
|
|
8855
8881
|
throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
|
|
8856
8882
|
}
|
|
8883
|
+
if (!COMPOSITION_FILE.test(htmlPath)) {
|
|
8884
|
+
throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
|
|
8885
|
+
}
|
|
8857
8886
|
const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
|
|
8858
8887
|
const rawHtml = bindVariableMediaSources(
|
|
8859
8888
|
normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
|
|
@@ -9409,6 +9438,14 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
|
|
|
9409
9438
|
}
|
|
9410
9439
|
|
|
9411
9440
|
// src/services/render/stages/compileStage.ts
|
|
9441
|
+
function animatedGifCacheDir(extractCacheDir) {
|
|
9442
|
+
try {
|
|
9443
|
+
const root = extractCacheDir && privateCacheRoot(extractCacheDir);
|
|
9444
|
+
return root ? join20(root, "animated-gif") : void 0;
|
|
9445
|
+
} catch {
|
|
9446
|
+
return void 0;
|
|
9447
|
+
}
|
|
9448
|
+
}
|
|
9412
9449
|
function adaptAspectAgnosticResolution(requested, aspectAgnostic, width, height, log) {
|
|
9413
9450
|
if (!requested || !aspectAgnostic) return requested;
|
|
9414
9451
|
const flipped = suggestMatchingPreset(width, height, requested);
|
|
@@ -9488,7 +9525,7 @@ async function runCompileStage(input) {
|
|
|
9488
9525
|
variables: input.variables,
|
|
9489
9526
|
urlByAbsentLocalPath: input.urlByAbsentLocalPath,
|
|
9490
9527
|
pageMotionBlur: input.pageMotionBlur,
|
|
9491
|
-
animatedGifCacheDir:
|
|
9528
|
+
animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
|
|
9492
9529
|
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
|
|
9493
9530
|
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
|
|
9494
9531
|
});
|
|
@@ -10334,8 +10371,13 @@ import {
|
|
|
10334
10371
|
rebaseVideoToWindow,
|
|
10335
10372
|
resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
|
|
10336
10373
|
resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
|
|
10337
|
-
isHttpUrl as
|
|
10374
|
+
isHttpUrl as isHttpUrl3,
|
|
10375
|
+
isInsideAssetRoots as isInsideAssetRoots2,
|
|
10338
10376
|
assertPublicHttpsUrl,
|
|
10377
|
+
downloadToTemp as downloadToTemp2,
|
|
10378
|
+
resolveRestrictPageNetwork,
|
|
10379
|
+
isUrlNotPermittedError,
|
|
10380
|
+
writeUrlDownloadTelemetry as writeUrlDownloadTelemetry2,
|
|
10339
10381
|
resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
|
|
10340
10382
|
runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
|
|
10341
10383
|
safeVideoExtractionSourceIdentity,
|
|
@@ -10571,9 +10613,11 @@ async function runExtractVideosStage(input) {
|
|
|
10571
10613
|
deferRangeExtraction,
|
|
10572
10614
|
shownBoxes,
|
|
10573
10615
|
urlByAbsentLocalPath,
|
|
10616
|
+
audioDownloadDir,
|
|
10574
10617
|
skipFrameExtractionIds = []
|
|
10575
10618
|
} = input;
|
|
10576
10619
|
const stage2Start = Date.now();
|
|
10620
|
+
const assetRoots = job.config.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir);
|
|
10577
10621
|
const extractionPolicy = resolveVideoExtractionPolicy();
|
|
10578
10622
|
composition.videos = composition.videos.filter(
|
|
10579
10623
|
(video) => !isVideoPastTimelineEnd(video, composition.duration)
|
|
@@ -10592,7 +10636,7 @@ async function runExtractVideosStage(input) {
|
|
|
10592
10636
|
const probeFailures = await Promise.all(
|
|
10593
10637
|
composition.videos.map(async (v) => {
|
|
10594
10638
|
const videoPath = resolveProjectRelativeSrc4(v.src, projectDir, compiledDir);
|
|
10595
|
-
if (!
|
|
10639
|
+
if (!opensLocally(videoPath, assetRoots)) return null;
|
|
10596
10640
|
try {
|
|
10597
10641
|
const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata4(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata4(videoPath), {
|
|
10598
10642
|
signal: abortSignal,
|
|
@@ -10630,7 +10674,7 @@ async function runExtractVideosStage(input) {
|
|
|
10630
10674
|
const probed = await Promise.all(
|
|
10631
10675
|
composition.images.map(async (img) => {
|
|
10632
10676
|
const imgPath = resolveProjectRelativeSrc4(img.src, projectDir, compiledDir);
|
|
10633
|
-
if (!
|
|
10677
|
+
if (!opensLocally(imgPath, assetRoots)) return null;
|
|
10634
10678
|
const colorSpace = await probeColorSpaceSafely(imgPath, log);
|
|
10635
10679
|
if (isHdrColorSpace2(colorSpace)) {
|
|
10636
10680
|
nativeHdrImageIds.add(img.id);
|
|
@@ -10643,7 +10687,16 @@ async function runExtractVideosStage(input) {
|
|
|
10643
10687
|
imageColorSpaces.push(...probed);
|
|
10644
10688
|
}
|
|
10645
10689
|
if (skipFrameExtractionIds.length > 0) {
|
|
10646
|
-
await appendVideoAudioFromProbe({
|
|
10690
|
+
await appendVideoAudioFromProbe({
|
|
10691
|
+
projectDir,
|
|
10692
|
+
compiledDir,
|
|
10693
|
+
composition,
|
|
10694
|
+
urlByAbsentLocalPath,
|
|
10695
|
+
downloadDir: audioDownloadDir,
|
|
10696
|
+
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
|
|
10697
|
+
signal: abortSignal,
|
|
10698
|
+
log
|
|
10699
|
+
});
|
|
10647
10700
|
videoReadinessSkipIds = [...skipFrameExtractionIds];
|
|
10648
10701
|
} else if (composition.videos.length > 0) {
|
|
10649
10702
|
const totalVideos = composition.videos.length;
|
|
@@ -10674,6 +10727,7 @@ async function runExtractVideosStage(input) {
|
|
|
10674
10727
|
shownBoxes,
|
|
10675
10728
|
contentKeyedDirs: [join22(compiledDir, REMOTE_MEDIA_SUBDIR)],
|
|
10676
10729
|
urlByAbsentLocalPath,
|
|
10730
|
+
assetRoots,
|
|
10677
10731
|
onProgress: ({ planned = 0, done = 0 }) => {
|
|
10678
10732
|
framesPlanned += planned;
|
|
10679
10733
|
framesDone += done;
|
|
@@ -10750,17 +10804,41 @@ function isPublicHttpsUrl(url) {
|
|
|
10750
10804
|
return false;
|
|
10751
10805
|
}
|
|
10752
10806
|
}
|
|
10807
|
+
function opensLocally(path, assetRoots) {
|
|
10808
|
+
return existsSync13(path) && (!assetRoots || isInsideAssetRoots2(path, assetRoots));
|
|
10809
|
+
}
|
|
10810
|
+
function localProbeSource(src, input) {
|
|
10811
|
+
const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
|
|
10812
|
+
const readFrom = input.urlByAbsentLocalPath?.get(path) ?? path;
|
|
10813
|
+
const roots = input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(input.projectDir, input.compiledDir);
|
|
10814
|
+
return isHttpUrl3(readFrom) || opensLocally(readFrom, roots) ? readFrom : null;
|
|
10815
|
+
}
|
|
10816
|
+
async function remoteProbeSource(video, input) {
|
|
10817
|
+
if (!isPublicHttpsUrl(video.src)) return null;
|
|
10818
|
+
if (!resolveRestrictPageNetwork()) return video.src;
|
|
10819
|
+
if (!video.hasAudio || video.hidden) return null;
|
|
10820
|
+
const downloadDir = input.downloadDir ?? join22(input.compiledDir, REMOTE_MEDIA_SUBDIR);
|
|
10821
|
+
try {
|
|
10822
|
+
return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
|
|
10823
|
+
onTelemetry: writeUrlDownloadTelemetry2
|
|
10824
|
+
});
|
|
10825
|
+
} catch (error) {
|
|
10826
|
+
if (!isUrlNotPermittedError(error)) throw error;
|
|
10827
|
+
input.log?.warn("Video sound skipped: its URL is outside the download address rules", {
|
|
10828
|
+
videoId: video.id
|
|
10829
|
+
});
|
|
10830
|
+
return null;
|
|
10831
|
+
}
|
|
10832
|
+
}
|
|
10753
10833
|
async function appendVideoAudioFromProbe(input) {
|
|
10754
|
-
const {
|
|
10834
|
+
const { composition } = input;
|
|
10755
10835
|
const videos = composition.videos.filter(
|
|
10756
10836
|
(video) => !isVideoPastTimelineEnd(video, composition.duration)
|
|
10757
10837
|
);
|
|
10758
10838
|
const probed = await Promise.all(
|
|
10759
10839
|
videos.map(async (video) => {
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
|
|
10763
|
-
if (!isHttpUrl2(readFrom) && !existsSync13(readFrom)) return null;
|
|
10840
|
+
const readFrom = isHttpUrl3(video.src) ? await remoteProbeSource(video, input) : localProbeSource(video.src, input);
|
|
10841
|
+
if (readFrom === null) return null;
|
|
10764
10842
|
const metadata = await extractMediaMetadata4(readFrom);
|
|
10765
10843
|
const window2 = await resolveFinalFrameExtractionWindow2(
|
|
10766
10844
|
readFrom,
|
|
@@ -10783,7 +10861,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
10783
10861
|
import { existsSync as existsSync14 } from "node:fs";
|
|
10784
10862
|
import {
|
|
10785
10863
|
buildVideoLayerInput,
|
|
10786
|
-
isHttpUrl as
|
|
10864
|
+
isHttpUrl as isHttpUrl4,
|
|
10787
10865
|
qualifyVideoLayer,
|
|
10788
10866
|
resolveProjectRelativeSrc as resolveProjectRelativeSrc5
|
|
10789
10867
|
} from "@hyperframes/engine";
|
|
@@ -10846,7 +10924,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
10846
10924
|
const q = qualifyVideoLayer(input.videos, input.duration);
|
|
10847
10925
|
if (!q.qualifies) return { reason: q.reason };
|
|
10848
10926
|
const { video } = q;
|
|
10849
|
-
if (
|
|
10927
|
+
if (isHttpUrl4(video.src)) return { reason: "remote_source" };
|
|
10850
10928
|
const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
|
|
10851
10929
|
if (!existsSync14(path)) return { reason: "source_missing" };
|
|
10852
10930
|
const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
|
|
@@ -10875,7 +10953,7 @@ import {
|
|
|
10875
10953
|
|
|
10876
10954
|
// src/services/render/audioDeliveryLimit.ts
|
|
10877
10955
|
import { existsSync as existsSync15 } from "node:fs";
|
|
10878
|
-
import { dirname as
|
|
10956
|
+
import { dirname as dirname11, join as join24 } from "node:path";
|
|
10879
10957
|
import {
|
|
10880
10958
|
applyAudioFxChain,
|
|
10881
10959
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -10885,7 +10963,7 @@ import {
|
|
|
10885
10963
|
|
|
10886
10964
|
// src/services/render/audioPadTrim.ts
|
|
10887
10965
|
import { spawn } from "node:child_process";
|
|
10888
|
-
import { dirname as
|
|
10966
|
+
import { dirname as dirname10, join as join23 } from "node:path";
|
|
10889
10967
|
import {
|
|
10890
10968
|
DEFAULT_CONFIG,
|
|
10891
10969
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -11179,7 +11257,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
|
|
|
11179
11257
|
async function enforceAacTruePeak(input) {
|
|
11180
11258
|
let scratchDir;
|
|
11181
11259
|
try {
|
|
11182
|
-
scratchDir = createStagingDir3(
|
|
11260
|
+
scratchDir = createStagingDir3(dirname10(input.audioPath), ".true-peak-");
|
|
11183
11261
|
const correctedPath = join23(scratchDir, "audio.m4a");
|
|
11184
11262
|
const measurements = [];
|
|
11185
11263
|
let attenuationDb = 0;
|
|
@@ -11390,7 +11468,7 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
11390
11468
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
11391
11469
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
11392
11470
|
const alternating = ["a", "b"].map(
|
|
11393
|
-
(k) => join24(
|
|
11471
|
+
(k) => join24(dirname11(sourcePath), `audio-source-limited-${k}.wav`)
|
|
11394
11472
|
);
|
|
11395
11473
|
let encodedFrom;
|
|
11396
11474
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -11538,7 +11616,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
11538
11616
|
audioResult = await processCompositionAudio(
|
|
11539
11617
|
audios,
|
|
11540
11618
|
projectDir,
|
|
11541
|
-
|
|
11619
|
+
audioWorkDir(workDir),
|
|
11542
11620
|
audioOutputPath,
|
|
11543
11621
|
duration,
|
|
11544
11622
|
abortSignal,
|
|
@@ -11548,7 +11626,8 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
11548
11626
|
masterFxChain,
|
|
11549
11627
|
urlByAbsentLocalPath,
|
|
11550
11628
|
audioSidecarUrlByLocalPath,
|
|
11551
|
-
keepEncoderInputAt: pcmSourcePath
|
|
11629
|
+
keepEncoderInputAt: pcmSourcePath,
|
|
11630
|
+
assetRoots: input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir)
|
|
11552
11631
|
},
|
|
11553
11632
|
compiledDir
|
|
11554
11633
|
);
|
|
@@ -12228,7 +12307,7 @@ import {
|
|
|
12228
12307
|
// src/services/shaderTransitionWorkerPool.ts
|
|
12229
12308
|
import { Worker } from "node:worker_threads";
|
|
12230
12309
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
12231
|
-
import { dirname as
|
|
12310
|
+
import { dirname as dirname12, join as join28 } from "node:path";
|
|
12232
12311
|
import { createRequire } from "node:module";
|
|
12233
12312
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
12234
12313
|
import { existsSync as existsSync18 } from "node:fs";
|
|
@@ -12241,7 +12320,7 @@ function resolveWorkerEntry(explicit) {
|
|
|
12241
12320
|
const isTs = override.endsWith(".ts");
|
|
12242
12321
|
return { path: override, isTs };
|
|
12243
12322
|
}
|
|
12244
|
-
const moduleDir =
|
|
12323
|
+
const moduleDir = dirname12(fileURLToPath3(import.meta.url));
|
|
12245
12324
|
const jsPath = join28(moduleDir, "shaderTransitionWorker.js");
|
|
12246
12325
|
if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
|
|
12247
12326
|
const tsPath = join28(moduleDir, "shaderTransitionWorker.ts");
|
|
@@ -12970,7 +13049,7 @@ import {
|
|
|
12970
13049
|
writeFileSync as writeFileSync6
|
|
12971
13050
|
} from "node:fs";
|
|
12972
13051
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
12973
|
-
import { dirname as
|
|
13052
|
+
import { dirname as dirname13, join as join31 } from "node:path";
|
|
12974
13053
|
import {
|
|
12975
13054
|
encodeFramesChunkedConcat,
|
|
12976
13055
|
encodeFramesFromDir,
|
|
@@ -13288,7 +13367,7 @@ async function runEncodeStage(input) {
|
|
|
13288
13367
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
13289
13368
|
fps: job.config.fps,
|
|
13290
13369
|
loop,
|
|
13291
|
-
palettePath: join31(
|
|
13370
|
+
palettePath: join31(dirname13(videoOnlyPath), "gif-palette.png"),
|
|
13292
13371
|
preserveAlpha: needsAlpha,
|
|
13293
13372
|
signal: abortSignal,
|
|
13294
13373
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -13733,7 +13812,7 @@ function getNextRetryWorkerCount(currentWorkers) {
|
|
|
13733
13812
|
}
|
|
13734
13813
|
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir2()) {
|
|
13735
13814
|
if (platform2 === "win32" || platform2 === "darwin") return join32(systemTempDir, "hf-render-");
|
|
13736
|
-
return join32(
|
|
13815
|
+
return join32(dirname14(outputPath), `work-${jobId}-`);
|
|
13737
13816
|
}
|
|
13738
13817
|
var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
|
|
13739
13818
|
function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
|
|
@@ -14436,6 +14515,19 @@ function resolveCaptureForceScreenshotForPageSideCompositing(args) {
|
|
|
14436
14515
|
function shouldDiscardProbeSessionForPageSideCompositing(args) {
|
|
14437
14516
|
return args.hasProbeSession && args.usePageSideCompositing;
|
|
14438
14517
|
}
|
|
14518
|
+
var PAGE_SIDE_COMPOSITOR_CANVAS_ID = "__hf-page-side-compositor";
|
|
14519
|
+
async function pageInstallsShaderCompositor(open, session = { initializeSession: initializeSession8, closeCaptureSession: closeCaptureSession8 }) {
|
|
14520
|
+
const probe = await open();
|
|
14521
|
+
try {
|
|
14522
|
+
await session.initializeSession(probe);
|
|
14523
|
+
return await probe.page.evaluate(
|
|
14524
|
+
(id) => document.getElementById(id) !== null,
|
|
14525
|
+
PAGE_SIDE_COMPOSITOR_CANVAS_ID
|
|
14526
|
+
);
|
|
14527
|
+
} finally {
|
|
14528
|
+
await session.closeCaptureSession(probe);
|
|
14529
|
+
}
|
|
14530
|
+
}
|
|
14439
14531
|
function deVerifyFallbackTelemetry(err) {
|
|
14440
14532
|
const details = getDrawElementVerificationDetails(err);
|
|
14441
14533
|
return {
|
|
@@ -14446,7 +14538,7 @@ function deVerifyFallbackTelemetry(err) {
|
|
|
14446
14538
|
};
|
|
14447
14539
|
}
|
|
14448
14540
|
function resolveRenderDebugDir() {
|
|
14449
|
-
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve8(process.env.PRODUCER_RENDERS_DIR, "..") : resolve8(
|
|
14541
|
+
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve8(process.env.PRODUCER_RENDERS_DIR, "..") : resolve8(dirname14(fileURLToPath4(import.meta.url)), "../..");
|
|
14450
14542
|
return join32(producerRoot, ".debug");
|
|
14451
14543
|
}
|
|
14452
14544
|
async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
@@ -14454,7 +14546,7 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
|
|
|
14454
14546
|
validateDeliveryEncoderConfig(job.config);
|
|
14455
14547
|
validateChromaSubsamplingConfig(job.config);
|
|
14456
14548
|
const debugDir = resolveRenderDebugDir();
|
|
14457
|
-
const outputDir =
|
|
14549
|
+
const outputDir = dirname14(outputPath);
|
|
14458
14550
|
if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
14459
14551
|
const workDir = job.config.debug ? join32(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
14460
14552
|
const pipelineStart = Date.now();
|
|
@@ -14866,6 +14958,7 @@ async function executeRenderPipeline(input) {
|
|
|
14866
14958
|
log,
|
|
14867
14959
|
composition,
|
|
14868
14960
|
skipFrameExtractionIds: videoLayer ? [videoLayer.videoId] : [],
|
|
14961
|
+
audioDownloadDir: audioWorkDir(workDir),
|
|
14869
14962
|
abortSignal: executionSignal,
|
|
14870
14963
|
assertNotAborted,
|
|
14871
14964
|
// Local staging can use links; distributed plan() alone requires real copies.
|
|
@@ -14952,6 +15045,7 @@ async function executeRenderPipeline(input) {
|
|
|
14952
15045
|
audioGain: cfg.audioGain,
|
|
14953
15046
|
audios: composition.audios,
|
|
14954
15047
|
masterFxChain: composition.masterFxChain,
|
|
15048
|
+
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
|
|
14955
15049
|
abortSignal: executionSignal,
|
|
14956
15050
|
assertNotAborted,
|
|
14957
15051
|
log,
|
|
@@ -15571,7 +15665,7 @@ async function executeRenderPipeline(input) {
|
|
|
15571
15665
|
};
|
|
15572
15666
|
const videoExt = FORMAT_EXT[outputFormat] ?? ".mp4";
|
|
15573
15667
|
const videoOnlyPath = join32(workDir, `video-only${videoExt}`);
|
|
15574
|
-
|
|
15668
|
+
let usePageSideCompositingForTransitions = (cfg.enablePageSideCompositing || isGif) && compiled.hasShaderTransitions && !hasHdrContent && outputSupportsPageSideShaderCompositing(outputFormat);
|
|
15575
15669
|
if (usePageSideCompositingForTransitions) {
|
|
15576
15670
|
activeFileServer.addPreHeadScript(HF_PAGE_SIDE_COMPOSITING_STUB);
|
|
15577
15671
|
if (shouldDiscardProbeSessionForPageSideCompositing({
|
|
@@ -15585,6 +15679,26 @@ async function executeRenderPipeline(input) {
|
|
|
15585
15679
|
"[Render] Recreating capture session so page-side compositing pre-head script is loaded."
|
|
15586
15680
|
);
|
|
15587
15681
|
}
|
|
15682
|
+
try {
|
|
15683
|
+
usePageSideCompositingForTransitions = await pageInstallsShaderCompositor(
|
|
15684
|
+
() => createCaptureSession8(activeFileServer.url, framesDir, buildPrepCaptureOptions(), null, {
|
|
15685
|
+
...cfg,
|
|
15686
|
+
forceScreenshot: true
|
|
15687
|
+
})
|
|
15688
|
+
);
|
|
15689
|
+
} catch (error) {
|
|
15690
|
+
assertNotAborted();
|
|
15691
|
+
log.warn("[Render] Shader compositor check failed; keeping page-side compositing.", {
|
|
15692
|
+
error: error instanceof Error ? error.message : String(error)
|
|
15693
|
+
});
|
|
15694
|
+
}
|
|
15695
|
+
if (!usePageSideCompositingForTransitions) {
|
|
15696
|
+
log.warn(
|
|
15697
|
+
"[Render] The page's shader-transitions build cannot composite in this browser; shader transitions blend on the Node-side layered path."
|
|
15698
|
+
);
|
|
15699
|
+
}
|
|
15700
|
+
}
|
|
15701
|
+
if (usePageSideCompositingForTransitions) {
|
|
15588
15702
|
captureForceScreenshot = resolveCaptureForceScreenshotForPageSideCompositing({
|
|
15589
15703
|
forceScreenshot: captureForceScreenshot,
|
|
15590
15704
|
usePageSideCompositing: true
|
|
@@ -16645,7 +16759,11 @@ function readEntryHtml(filePath) {
|
|
|
16645
16759
|
closeSync5(fd);
|
|
16646
16760
|
}
|
|
16647
16761
|
}
|
|
16648
|
-
function
|
|
16762
|
+
function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
16763
|
+
const entryRelativePath = relative4(absProjectDir, absoluteEntryPath);
|
|
16764
|
+
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep4}`) || isAbsolute3(entryRelativePath) || isAllowedEntry !== void 0 && !isAllowedEntry(absoluteEntryPath);
|
|
16765
|
+
}
|
|
16766
|
+
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
16649
16767
|
const absProjectDir = resolve9(projectDir);
|
|
16650
16768
|
if (!existsSync22(absProjectDir) || !statSync11(absProjectDir).isDirectory()) {
|
|
16651
16769
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
@@ -16655,8 +16773,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile) {
|
|
|
16655
16773
|
);
|
|
16656
16774
|
for (const entryFile of entryCandidates) {
|
|
16657
16775
|
const absoluteEntryPath = resolve9(absProjectDir, entryFile);
|
|
16658
|
-
|
|
16659
|
-
if (entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep4}`) || isAbsolute3(entryRelativePath)) {
|
|
16776
|
+
if (leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry)) {
|
|
16660
16777
|
return { error: `Entry file must stay inside project directory: ${entryFile}` };
|
|
16661
16778
|
}
|
|
16662
16779
|
const html = readEntryHtml(absoluteEntryPath);
|
|
@@ -16672,10 +16789,10 @@ function readProjectEntryFile(projectDir, preferredEntryFile) {
|
|
|
16672
16789
|
error: `No HTML entry file found in project directory: ${join33(absProjectDir, preferredEntryFile || "index.html")}`
|
|
16673
16790
|
};
|
|
16674
16791
|
}
|
|
16675
|
-
function prepareHyperframeLintBody(body) {
|
|
16792
|
+
function prepareHyperframeLintBody(body, isAllowedEntry) {
|
|
16676
16793
|
const requestedEntryFile = typeof body.entryFile === "string" && body.entryFile.trim().length > 0 ? body.entryFile.trim() : void 0;
|
|
16677
16794
|
if (typeof body.projectDir === "string" && body.projectDir.trim().length > 0) {
|
|
16678
|
-
const prepared = readProjectEntryFile(body.projectDir, requestedEntryFile);
|
|
16795
|
+
const prepared = readProjectEntryFile(body.projectDir, requestedEntryFile, isAllowedEntry);
|
|
16679
16796
|
if ("error" in prepared) {
|
|
16680
16797
|
return prepared;
|
|
16681
16798
|
}
|
|
@@ -16715,7 +16832,7 @@ async function runHyperframeLint(prepared) {
|
|
|
16715
16832
|
// src/services/healthWorker.ts
|
|
16716
16833
|
import { Worker as Worker2 } from "node:worker_threads";
|
|
16717
16834
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
16718
|
-
import { dirname as
|
|
16835
|
+
import { dirname as dirname15, join as join34 } from "node:path";
|
|
16719
16836
|
import { existsSync as existsSync23 } from "node:fs";
|
|
16720
16837
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
16721
16838
|
async function startHealthWorker(options = {}) {
|
|
@@ -16790,7 +16907,7 @@ function defaultLogger2() {
|
|
|
16790
16907
|
};
|
|
16791
16908
|
}
|
|
16792
16909
|
function resolveWorkerEntry2() {
|
|
16793
|
-
const here =
|
|
16910
|
+
const here = dirname15(fileURLToPath5(import.meta.url));
|
|
16794
16911
|
const candidates = [join34(here, "healthWorkerThread.js"), join34(here, "healthWorkerThread.ts")];
|
|
16795
16912
|
for (const candidate of candidates) {
|
|
16796
16913
|
if (existsSync23(candidate)) return candidate;
|
|
@@ -16866,7 +16983,7 @@ import {
|
|
|
16866
16983
|
|
|
16867
16984
|
// src/services/distributed/shared.ts
|
|
16868
16985
|
import { execFile as execFileCallback } from "node:child_process";
|
|
16869
|
-
import { dirname as
|
|
16986
|
+
import { dirname as dirname16, join as join35 } from "node:path";
|
|
16870
16987
|
import { existsSync as existsSync24, readFileSync as readFileSync11 } from "node:fs";
|
|
16871
16988
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
16872
16989
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -16879,7 +16996,7 @@ var execFile = promisify2(execFileCallback);
|
|
|
16879
16996
|
var cachedProducerVersion = null;
|
|
16880
16997
|
function readProducerVersion() {
|
|
16881
16998
|
if (cachedProducerVersion !== null) return cachedProducerVersion;
|
|
16882
|
-
const startDir =
|
|
16999
|
+
const startDir = dirname16(fileURLToPath6(import.meta.url));
|
|
16883
17000
|
let current = startDir;
|
|
16884
17001
|
for (let i = 0; i < 10; i++) {
|
|
16885
17002
|
const candidate = join35(current, "package.json");
|
|
@@ -16893,7 +17010,7 @@ function readProducerVersion() {
|
|
|
16893
17010
|
} catch {
|
|
16894
17011
|
}
|
|
16895
17012
|
}
|
|
16896
|
-
const parent =
|
|
17013
|
+
const parent = dirname16(current);
|
|
16897
17014
|
if (parent === current) break;
|
|
16898
17015
|
current = parent;
|
|
16899
17016
|
}
|
|
@@ -17390,16 +17507,22 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
17390
17507
|
});
|
|
17391
17508
|
return renderConfigFromRequest(request, { logger: log });
|
|
17392
17509
|
}
|
|
17393
|
-
function resolvePreparedRenderOutput(prepared, rendersDir, log) {
|
|
17510
|
+
function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
17394
17511
|
const { input, cleanupProjectDir } = prepared;
|
|
17395
17512
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
|
|
17396
|
-
|
|
17513
|
+
if (confineOutput) {
|
|
17514
|
+
mkdirSync13(rendersDir, { recursive: true });
|
|
17515
|
+
if (!isSafePath3(rendersDir, absoluteOutputPath)) {
|
|
17516
|
+
throw new Error("outputPath must be inside the renders directory");
|
|
17517
|
+
}
|
|
17518
|
+
}
|
|
17519
|
+
const outputDir = dirname17(absoluteOutputPath);
|
|
17397
17520
|
if (!existsSync25(outputDir)) mkdirSync13(outputDir, { recursive: true });
|
|
17398
17521
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
17399
17522
|
}
|
|
17400
|
-
function prepareRenderJob(prepared, rendersDir, log) {
|
|
17523
|
+
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
17401
17524
|
try {
|
|
17402
|
-
const output = resolvePreparedRenderOutput(prepared, rendersDir, log);
|
|
17525
|
+
const output = resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput);
|
|
17403
17526
|
const job = createRenderJob(buildRenderJobConfig(output.input, output.absoluteOutputPath, log));
|
|
17404
17527
|
return { ...output, job };
|
|
17405
17528
|
} catch (error) {
|
|
@@ -17450,16 +17573,32 @@ function validateOutputResolutionOverride(body) {
|
|
|
17450
17573
|
return void 0;
|
|
17451
17574
|
}
|
|
17452
17575
|
var MAX_PREVIEW_HTML_BYTES = 20 * 1024 * 1024;
|
|
17453
|
-
function
|
|
17576
|
+
function resolveRenderRequestPolicy(options) {
|
|
17577
|
+
return {
|
|
17578
|
+
projectsDir: resolve10(
|
|
17579
|
+
options.projectsDir ?? (process.env.PRODUCER_PROJECTS_DIR || process.cwd())
|
|
17580
|
+
),
|
|
17581
|
+
allowDebug: options.allowDebug ?? process.env.PRODUCER_ALLOW_DEBUG === "1"
|
|
17582
|
+
};
|
|
17583
|
+
}
|
|
17584
|
+
function isAllowedProjectPath(projectsDir, path) {
|
|
17585
|
+
return isSafePath3(projectsDir, path) && !isSafePath3(resolveRenderDebugDir(), path);
|
|
17586
|
+
}
|
|
17587
|
+
function isAllowedEntryPath(policy, projectDir, path) {
|
|
17588
|
+
return isSafePath3(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
|
|
17589
|
+
}
|
|
17590
|
+
function prepareProjectDirectory(projectDir, options, policy) {
|
|
17454
17591
|
const candidate = nonEmptyString(projectDir);
|
|
17455
17592
|
if (!candidate) return null;
|
|
17456
|
-
const absProjectDir = resolve10(candidate);
|
|
17457
|
-
|
|
17458
|
-
|
|
17593
|
+
const absProjectDir = policy ? resolve10(policy.projectsDir, candidate) : resolve10(candidate);
|
|
17594
|
+
const shown = policy ? candidate : absProjectDir;
|
|
17595
|
+
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync25(absProjectDir) || !statSync12(absProjectDir).isDirectory()) {
|
|
17596
|
+
return { error: `Project directory not found: ${shown}` };
|
|
17459
17597
|
}
|
|
17460
17598
|
const entry = options.entryFile || "index.html";
|
|
17461
|
-
|
|
17462
|
-
|
|
17599
|
+
const entryPath = resolve10(absProjectDir, entry);
|
|
17600
|
+
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync25(entryPath)) {
|
|
17601
|
+
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
17463
17602
|
}
|
|
17464
17603
|
return { prepared: { input: { projectDir: absProjectDir, ...options } } };
|
|
17465
17604
|
}
|
|
@@ -17488,15 +17627,18 @@ function materializeInlineProject(html, options) {
|
|
|
17488
17627
|
}
|
|
17489
17628
|
};
|
|
17490
17629
|
}
|
|
17491
|
-
async function prepareRenderBody(body) {
|
|
17630
|
+
async function prepareRenderBody(body, policy) {
|
|
17492
17631
|
const overrideError = validateRenderOverrides(body);
|
|
17493
17632
|
if (overrideError) return { error: overrideError };
|
|
17633
|
+
if (policy && body.debug === true && !policy.allowDebug) {
|
|
17634
|
+
return { error: "debug is disabled on this server (set allowDebug or PRODUCER_ALLOW_DEBUG=1)" };
|
|
17635
|
+
}
|
|
17494
17636
|
const pageMotionBlur = body.pageMotionBlur;
|
|
17495
17637
|
if (pageMotionBlur !== void 0 && pageMotionBlur !== "off") {
|
|
17496
17638
|
return { error: "pageMotionBlur must be off when supplied" };
|
|
17497
17639
|
}
|
|
17498
17640
|
const options = { ...parseRenderOptions(body), pageMotionBlur };
|
|
17499
|
-
const project = prepareProjectDirectory(body.projectDir, options);
|
|
17641
|
+
const project = prepareProjectDirectory(body.projectDir, options, policy);
|
|
17500
17642
|
if (project) return project;
|
|
17501
17643
|
const source = await resolveInlineRenderHtml(body);
|
|
17502
17644
|
return "error" in source ? source : materializeInlineProject(source.html, options);
|
|
@@ -17549,6 +17691,9 @@ function cleanupTempDir(dir, log) {
|
|
|
17549
17691
|
});
|
|
17550
17692
|
}
|
|
17551
17693
|
}
|
|
17694
|
+
function publicPerfSummary(job) {
|
|
17695
|
+
return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
|
|
17696
|
+
}
|
|
17552
17697
|
function outputFileSize(path) {
|
|
17553
17698
|
return existsSync25(path) ? statSync12(path).size : 0;
|
|
17554
17699
|
}
|
|
@@ -17561,7 +17706,7 @@ function createBlockingProgressReporter(log, requestId) {
|
|
|
17561
17706
|
log.info(`render progress ${pct}%`, { requestId, stage: job.currentStage, message });
|
|
17562
17707
|
};
|
|
17563
17708
|
}
|
|
17564
|
-
async function prepareSseRenderRequest(c, stream, requestId) {
|
|
17709
|
+
async function prepareSseRenderRequest(c, stream, requestId, policy) {
|
|
17565
17710
|
let body;
|
|
17566
17711
|
try {
|
|
17567
17712
|
body = await c.req.json();
|
|
@@ -17576,7 +17721,7 @@ async function prepareSseRenderRequest(c, stream, requestId) {
|
|
|
17576
17721
|
});
|
|
17577
17722
|
return null;
|
|
17578
17723
|
}
|
|
17579
|
-
const prepared = await prepareRenderBody(body);
|
|
17724
|
+
const prepared = await prepareRenderBody(body, policy);
|
|
17580
17725
|
if (!("error" in prepared)) return prepared.prepared;
|
|
17581
17726
|
await stream.writeSSE({
|
|
17582
17727
|
data: JSON.stringify({
|
|
@@ -17648,6 +17793,7 @@ function createRenderHandlers(options = {}) {
|
|
|
17648
17793
|
const getRequestId = options.getRequestId ?? ((c) => c.req.header("x-request-id") || crypto.randomUUID());
|
|
17649
17794
|
const outputUrlPrefix = options.outputUrlPrefix ?? "/outputs";
|
|
17650
17795
|
const rendersDir = options.rendersDir ?? process.env.PRODUCER_RENDERS_DIR ?? "/tmp";
|
|
17796
|
+
const policy = options.confineRequests ? resolveRenderRequestPolicy(options) : void 0;
|
|
17651
17797
|
const artifactTtlMs = options.artifactTtlMs ?? Number(process.env.PRODUCER_OUTPUT_ARTIFACT_TTL_MS || 15 * 60 * 1e3);
|
|
17652
17798
|
const store = createArtifactStore(artifactTtlMs);
|
|
17653
17799
|
const maxConcurrentRenders = options.maxConcurrentRenders ?? Number(process.env.PRODUCER_MAX_CONCURRENT_RENDERS || 2);
|
|
@@ -17666,7 +17812,18 @@ function createRenderHandlers(options = {}) {
|
|
|
17666
17812
|
} catch {
|
|
17667
17813
|
return c.json({ success: false, requestId, error: "Invalid JSON body" }, 400);
|
|
17668
17814
|
}
|
|
17669
|
-
const
|
|
17815
|
+
const lintProjectDir = nonEmptyString(body.projectDir);
|
|
17816
|
+
let isAllowedEntry;
|
|
17817
|
+
if (policy && lintProjectDir) {
|
|
17818
|
+
const absProjectDir = resolve10(policy.projectsDir, lintProjectDir);
|
|
17819
|
+
if (!isAllowedProjectPath(policy.projectsDir, absProjectDir)) {
|
|
17820
|
+
const error = `Project directory not found: ${lintProjectDir}`;
|
|
17821
|
+
return c.json({ success: false, requestId, error }, 400);
|
|
17822
|
+
}
|
|
17823
|
+
body = { ...body, projectDir: absProjectDir };
|
|
17824
|
+
isAllowedEntry = (path) => isAllowedEntryPath(policy, absProjectDir, path);
|
|
17825
|
+
}
|
|
17826
|
+
const preparedResult = prepareHyperframeLintBody(body, isAllowedEntry);
|
|
17670
17827
|
if ("error" in preparedResult) {
|
|
17671
17828
|
return c.json({ success: false, requestId, error: preparedResult.error }, 400);
|
|
17672
17829
|
}
|
|
@@ -17695,11 +17852,11 @@ function createRenderHandlers(options = {}) {
|
|
|
17695
17852
|
} catch {
|
|
17696
17853
|
return c.json({ success: false, requestId, error: "Invalid JSON body" }, 400);
|
|
17697
17854
|
}
|
|
17698
|
-
const preparedResult = await prepareRenderBody(body);
|
|
17855
|
+
const preparedResult = await prepareRenderBody(body, policy);
|
|
17699
17856
|
if ("error" in preparedResult) {
|
|
17700
17857
|
return c.json({ success: false, requestId, error: preparedResult.error }, 400);
|
|
17701
17858
|
}
|
|
17702
|
-
const preparedJob = prepareRenderJob(preparedResult.prepared, rendersDir, log);
|
|
17859
|
+
const preparedJob = prepareRenderJob(preparedResult.prepared, rendersDir, log, !!policy);
|
|
17703
17860
|
if ("error" in preparedJob) {
|
|
17704
17861
|
return c.json({ success: false, requestId, error: preparedJob.error }, 400);
|
|
17705
17862
|
}
|
|
@@ -17740,7 +17897,7 @@ function createRenderHandlers(options = {}) {
|
|
|
17740
17897
|
videoDurationSeconds: job.duration ?? null,
|
|
17741
17898
|
outcome: job.outcome ?? "completed",
|
|
17742
17899
|
warnings: job.warnings,
|
|
17743
|
-
perf: job.perfSummary ?? null,
|
|
17900
|
+
perf: policy ? publicPerfSummary(job) : job.perfSummary ?? null,
|
|
17744
17901
|
...strictVariablesResult(job)
|
|
17745
17902
|
});
|
|
17746
17903
|
} catch (error) {
|
|
@@ -17777,9 +17934,9 @@ function createRenderHandlers(options = {}) {
|
|
|
17777
17934
|
return streamSSE(c, async (stream) => {
|
|
17778
17935
|
const requestId = getRequestId(c);
|
|
17779
17936
|
const t0 = Date.now();
|
|
17780
|
-
const prepared = await prepareSseRenderRequest(c, stream, requestId);
|
|
17937
|
+
const prepared = await prepareSseRenderRequest(c, stream, requestId, policy);
|
|
17781
17938
|
if (!prepared) return;
|
|
17782
|
-
const preparedJob = prepareRenderJob(prepared, rendersDir, log);
|
|
17939
|
+
const preparedJob = prepareRenderJob(prepared, rendersDir, log, !!policy);
|
|
17783
17940
|
if ("error" in preparedJob) {
|
|
17784
17941
|
await stream.writeSSE({
|
|
17785
17942
|
data: JSON.stringify({
|
|
@@ -17836,7 +17993,7 @@ function createRenderHandlers(options = {}) {
|
|
|
17836
17993
|
videoDurationSeconds: job.duration ?? null,
|
|
17837
17994
|
outcome: job.outcome ?? "completed",
|
|
17838
17995
|
warnings: job.warnings,
|
|
17839
|
-
perf: job.perfSummary ?? null,
|
|
17996
|
+
perf: policy ? publicPerfSummary(job) : job.perfSummary ?? null,
|
|
17840
17997
|
producerVersion: readProducerVersion(),
|
|
17841
17998
|
...strictVariablesResult(job)
|
|
17842
17999
|
})
|
|
@@ -17894,9 +18051,79 @@ function isCrossOriginBrowserRequest(c) {
|
|
|
17894
18051
|
return true;
|
|
17895
18052
|
}
|
|
17896
18053
|
}
|
|
18054
|
+
function hostnameOf(host) {
|
|
18055
|
+
try {
|
|
18056
|
+
return new URL(`http://${host}`).hostname.toLowerCase();
|
|
18057
|
+
} catch {
|
|
18058
|
+
return null;
|
|
18059
|
+
}
|
|
18060
|
+
}
|
|
18061
|
+
function isAllowedBrowserHostname(hostname2, allowed) {
|
|
18062
|
+
if (!hostname2) return false;
|
|
18063
|
+
if (hostname2 === "localhost" || hostname2.endsWith(".localhost")) return true;
|
|
18064
|
+
if (isIP(hostname2.replace(/^\[|\]$/g, "")) !== 0) return true;
|
|
18065
|
+
return allowed.has(hostname2);
|
|
18066
|
+
}
|
|
18067
|
+
function allowedHostnames(options) {
|
|
18068
|
+
const fromEnv = (process.env.PRODUCER_ALLOWED_HOSTS ?? "").split(",");
|
|
18069
|
+
const names = /* @__PURE__ */ new Set();
|
|
18070
|
+
for (const entry of [...options.allowedHosts ?? [], ...fromEnv]) {
|
|
18071
|
+
const hostname2 = entry.trim() ? hostnameOf(entry.trim()) : null;
|
|
18072
|
+
if (hostname2) names.add(hostname2);
|
|
18073
|
+
}
|
|
18074
|
+
return names;
|
|
18075
|
+
}
|
|
18076
|
+
function resolveAuthToken(options) {
|
|
18077
|
+
return options.authToken?.trim() || process.env.PRODUCER_AUTH_TOKEN?.trim() || "";
|
|
18078
|
+
}
|
|
18079
|
+
function hasBearerToken(c, token) {
|
|
18080
|
+
const digest = (value) => crypto.createHash("sha256").update(value).digest();
|
|
18081
|
+
return crypto.timingSafeEqual(
|
|
18082
|
+
digest(c.req.header("authorization") ?? ""),
|
|
18083
|
+
digest(`Bearer ${token}`)
|
|
18084
|
+
);
|
|
18085
|
+
}
|
|
18086
|
+
function isLoopbackHostname(hostname2) {
|
|
18087
|
+
const host = hostname2.replace(/^\[|\]$/g, "").toLowerCase();
|
|
18088
|
+
return host === "localhost" || host === "::1" || isIP(host) === 4 && host.startsWith("127.");
|
|
18089
|
+
}
|
|
18090
|
+
function isDisallowedBrowserHost(c, allowed) {
|
|
18091
|
+
const origin = c.req.header("origin");
|
|
18092
|
+
if (!origin && !c.req.header("sec-fetch-site")) return false;
|
|
18093
|
+
if (!isAllowedBrowserHostname(hostnameOf(c.req.header("host") ?? ""), allowed)) return true;
|
|
18094
|
+
if (!origin) return false;
|
|
18095
|
+
try {
|
|
18096
|
+
return !isAllowedBrowserHostname(new URL(origin).hostname.toLowerCase(), allowed);
|
|
18097
|
+
} catch {
|
|
18098
|
+
return true;
|
|
18099
|
+
}
|
|
18100
|
+
}
|
|
17897
18101
|
function createProducerApp(options = {}) {
|
|
17898
18102
|
const app = new Hono2();
|
|
17899
|
-
const handlers = createRenderHandlers(
|
|
18103
|
+
const handlers = createRenderHandlers({
|
|
18104
|
+
...options,
|
|
18105
|
+
confineRequests: options.confineRequests ?? true
|
|
18106
|
+
});
|
|
18107
|
+
const allowed = allowedHostnames(options);
|
|
18108
|
+
const authToken = resolveAuthToken(options);
|
|
18109
|
+
app.use("*", async (c, next) => {
|
|
18110
|
+
if (authToken && c.req.path !== "/health" && !hasBearerToken(c, authToken)) {
|
|
18111
|
+
return c.json({ success: false, error: "Unauthorized" }, 401);
|
|
18112
|
+
}
|
|
18113
|
+
await next();
|
|
18114
|
+
});
|
|
18115
|
+
app.use("*", async (c, next) => {
|
|
18116
|
+
if (isDisallowedBrowserHost(c, allowed)) {
|
|
18117
|
+
return c.json(
|
|
18118
|
+
{
|
|
18119
|
+
success: false,
|
|
18120
|
+
error: "Host not allowed. Add it to allowedHosts or PRODUCER_ALLOWED_HOSTS."
|
|
18121
|
+
},
|
|
18122
|
+
403
|
|
18123
|
+
);
|
|
18124
|
+
}
|
|
18125
|
+
await next();
|
|
18126
|
+
});
|
|
17900
18127
|
app.post("*", async (c, next) => {
|
|
17901
18128
|
if (isCrossOriginBrowserRequest(c)) {
|
|
17902
18129
|
return c.json({ success: false, error: "Cross-origin requests are not allowed" }, 403);
|
|
@@ -17913,10 +18140,17 @@ function createProducerApp(options = {}) {
|
|
|
17913
18140
|
}
|
|
17914
18141
|
function startServer(options = {}) {
|
|
17915
18142
|
const port = options.port ?? parseInt(process.env.PRODUCER_PORT ?? "9847", 10);
|
|
18143
|
+
const hostname2 = options.hostname || process.env.PRODUCER_HOST || "127.0.0.1";
|
|
17916
18144
|
const log = options.logger ?? defaultLogger;
|
|
18145
|
+
if (!isLoopbackHostname(hostname2) && !resolveAuthToken(options)) {
|
|
18146
|
+
throw new Error(
|
|
18147
|
+
`Refusing to listen on ${hostname2} without an auth token. Set authToken or PRODUCER_AUTH_TOKEN, or listen on a loopback address.`
|
|
18148
|
+
);
|
|
18149
|
+
}
|
|
17917
18150
|
const app = createProducerApp(options);
|
|
17918
|
-
const server = serve2({ fetch: app.fetch, port }, () => {
|
|
17919
|
-
|
|
18151
|
+
const server = serve2({ fetch: app.fetch, port, hostname: hostname2 }, (info) => {
|
|
18152
|
+
const address = info.family === "IPv6" ? `[${info.address}]` : info.address;
|
|
18153
|
+
log.info(`Listening on http://${address}:${info.port}`);
|
|
17920
18154
|
});
|
|
17921
18155
|
server.setTimeout(0);
|
|
17922
18156
|
server.requestTimeout = 0;
|