@hyperframes/producer 0.9.51 → 0.9.53
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 +133 -69
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.d.ts +1 -1
- package/dist/index.js +315 -98
- package/dist/public-server.js +313 -97
- package/dist/server.d.ts +18 -1
- 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 +1 -1
- package/dist/services/render/stages/compileStage.d.ts +1 -1
- package/dist/services/render/stages/extractVideosStage.d.ts +13 -6
- package/dist/services/renderOrchestrator.d.ts +6 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -315,6 +315,7 @@ var MIME_TYPES = {
|
|
|
315
315
|
".css": "text/css; charset=utf-8",
|
|
316
316
|
".js": "application/javascript; charset=utf-8",
|
|
317
317
|
".mjs": "application/javascript; charset=utf-8",
|
|
318
|
+
".cjs": "application/javascript; charset=utf-8",
|
|
318
319
|
".json": "application/json; charset=utf-8",
|
|
319
320
|
".cube": "text/plain; charset=utf-8",
|
|
320
321
|
".png": "image/png",
|
|
@@ -858,6 +859,10 @@ function createFileServer(options) {
|
|
|
858
859
|
const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
|
|
859
860
|
const app = new Hono();
|
|
860
861
|
const warnLeftOut = (line) => console.warn(`[FileServer] ${line}`);
|
|
862
|
+
app.use(async function loadEachFileOnlyAsItsNamedType(c, next) {
|
|
863
|
+
await next();
|
|
864
|
+
c.res.headers.set("X-Content-Type-Options", "nosniff");
|
|
865
|
+
});
|
|
861
866
|
app.get("/*", async (c) => {
|
|
862
867
|
let requestPath = c.req.path;
|
|
863
868
|
if (requestPath === "/") requestPath = "/index.html";
|
|
@@ -1119,6 +1124,9 @@ import {
|
|
|
1119
1124
|
import {
|
|
1120
1125
|
mediaIdPathSegment
|
|
1121
1126
|
} from "@hyperframes/engine";
|
|
1127
|
+
function audioWorkDir(workDir) {
|
|
1128
|
+
return join3(workDir, "audio-work");
|
|
1129
|
+
}
|
|
1122
1130
|
var BROWSER_MEDIA_EPSILON = 1e-4;
|
|
1123
1131
|
function resolveBrowserMediaEnd(start, end, duration) {
|
|
1124
1132
|
return Number.isFinite(duration) && duration > 0 ? start + duration : end;
|
|
@@ -6516,12 +6524,26 @@ function countAuthoredTimedClips(html) {
|
|
|
6516
6524
|
// src/services/render/stages/compileStage.ts
|
|
6517
6525
|
import { existsSync as existsSync12, writeFileSync as writeFileSync5 } from "node:fs";
|
|
6518
6526
|
import { join as join20, relative as relative3 } from "node:path";
|
|
6527
|
+
import { privateCacheRoot } from "@hyperframes/engine";
|
|
6519
6528
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
6520
6529
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
6521
6530
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
6522
6531
|
|
|
6523
6532
|
// src/services/htmlCompiler.ts
|
|
6524
6533
|
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
6534
|
+
import {
|
|
6535
|
+
cssRuleMatches,
|
|
6536
|
+
cssUrlMatches,
|
|
6537
|
+
fontFaceBlockMatches,
|
|
6538
|
+
hasBackgroundImageDeclaration,
|
|
6539
|
+
importRuleMatches,
|
|
6540
|
+
localFontFaceUrlMatches,
|
|
6541
|
+
remoteBackgroundUrlMatches,
|
|
6542
|
+
remoteFontFaceUrlMatches,
|
|
6543
|
+
replaceMatches,
|
|
6544
|
+
styleBlockMatches,
|
|
6545
|
+
stylesheetLinkMatches
|
|
6546
|
+
} from "@hyperframes/parsers/css-url-scans";
|
|
6525
6547
|
import { createHash as createHash6 } from "node:crypto";
|
|
6526
6548
|
import { createReadStream as createReadStream2, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
6527
6549
|
import { join as join19, dirname as dirname8, resolve as resolve7, basename as basename5, relative as relative2, sep as sep3 } from "path";
|
|
@@ -6547,7 +6569,6 @@ import {
|
|
|
6547
6569
|
extractResolvedMedia,
|
|
6548
6570
|
clampDurations,
|
|
6549
6571
|
shouldClampResolvedMediaDuration,
|
|
6550
|
-
CSS_URL_RE,
|
|
6551
6572
|
isNonRelativeUrl,
|
|
6552
6573
|
parseStrictFiniteTimingNumber,
|
|
6553
6574
|
readMediaStart,
|
|
@@ -7625,10 +7646,16 @@ function normalizeCompositionSrcs(html, projectDir) {
|
|
|
7625
7646
|
return `${name}${quote}${relative2(projectDir, file).split(sep3).join("/")}${quote}`;
|
|
7626
7647
|
});
|
|
7627
7648
|
}
|
|
7628
|
-
|
|
7649
|
+
var COMPOSITION_FILE = /\.html?$/i;
|
|
7650
|
+
var NOT_A_COMPOSITION_FILE = "it is not an .html file, so it is refused";
|
|
7651
|
+
function resolveCompositionPath(projectDir, src, assetRoot) {
|
|
7629
7652
|
const file = resolveCompositionSrc(projectDir, src);
|
|
7630
7653
|
return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
|
|
7631
7654
|
}
|
|
7655
|
+
function resolveCompositionFile(projectDir, src, assetRoot) {
|
|
7656
|
+
const file = resolveCompositionPath(projectDir, src, assetRoot);
|
|
7657
|
+
return file !== null && COMPOSITION_FILE.test(file) ? file : null;
|
|
7658
|
+
}
|
|
7632
7659
|
var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isVcsOrSecretPath2);
|
|
7633
7660
|
function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
|
|
7634
7661
|
const { document: document2 } = parseHTML5(html);
|
|
@@ -7638,7 +7665,7 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
|
|
|
7638
7665
|
const srcPath = el.getAttribute("data-composition-src");
|
|
7639
7666
|
if (!srcPath) continue;
|
|
7640
7667
|
if (isUnresolvedAssetPlaceholder(srcPath)) continue;
|
|
7641
|
-
const filePath =
|
|
7668
|
+
const filePath = resolveCompositionPath(projectDir, srcPath, assetRoot);
|
|
7642
7669
|
if (filePath === null) {
|
|
7643
7670
|
problems.push({ srcPath, detail: "it is outside the project folder" });
|
|
7644
7671
|
continue;
|
|
@@ -7651,6 +7678,10 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
|
|
|
7651
7678
|
problems.push({ srcPath, detail: "it is git metadata or an env file" });
|
|
7652
7679
|
continue;
|
|
7653
7680
|
}
|
|
7681
|
+
if (!COMPOSITION_FILE.test(filePath)) {
|
|
7682
|
+
problems.push({ srcPath, detail: NOT_A_COMPOSITION_FILE });
|
|
7683
|
+
continue;
|
|
7684
|
+
}
|
|
7654
7685
|
if (visited.has(filePath)) continue;
|
|
7655
7686
|
const read = readProjectFile(filePath);
|
|
7656
7687
|
if (read.kind === "missing") {
|
|
@@ -7746,7 +7777,6 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
|
|
|
7746
7777
|
function detectThreeDTransformUsage(html) {
|
|
7747
7778
|
return THREE_D_CONTEXT_PATTERN.test(html);
|
|
7748
7779
|
}
|
|
7749
|
-
var BACKGROUND_IMAGE_DECL_PATTERN = /(?:^|;|\{)\s*background(?:-image)?\s*:[^;}]*(?:\bgradient\s*\(|url\s*\()/i;
|
|
7750
7780
|
function detectAncestorBackgroundImage(html) {
|
|
7751
7781
|
const { document: document2 } = parseHTML5(html);
|
|
7752
7782
|
const root = document2.querySelector("[data-composition-id]");
|
|
@@ -7758,13 +7788,13 @@ function detectAncestorBackgroundImage(html) {
|
|
|
7758
7788
|
}
|
|
7759
7789
|
for (const el of ancestors) {
|
|
7760
7790
|
const style = el.getAttribute("style");
|
|
7761
|
-
if (style &&
|
|
7791
|
+
if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
|
|
7762
7792
|
}
|
|
7763
7793
|
for (const styleEl of document2.querySelectorAll("style")) {
|
|
7764
7794
|
const css = styleEl.textContent ?? "";
|
|
7765
|
-
for (const rule of css
|
|
7766
|
-
const [, selectorList
|
|
7767
|
-
if (!
|
|
7795
|
+
for (const { parts: rule } of cssRuleMatches(css)) {
|
|
7796
|
+
const [, selectorList, declarations] = rule;
|
|
7797
|
+
if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
|
|
7768
7798
|
for (const selector of selectorList.split(",")) {
|
|
7769
7799
|
const sel = selector.trim();
|
|
7770
7800
|
if (!sel || sel.startsWith("@")) continue;
|
|
@@ -8085,7 +8115,6 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
8085
8115
|
el.textContent = dedupedStyles[i] ?? "";
|
|
8086
8116
|
});
|
|
8087
8117
|
const styleEls = head ? Array.from(head.querySelectorAll("style")) : [];
|
|
8088
|
-
const importRe = /@import\s+url\([^)]*\)\s*;|@import\s+["'][^"']+["']\s*;/gi;
|
|
8089
8118
|
for (const run of styleEls.length > 1 ? headStyleRuns(styleEls) : []) {
|
|
8090
8119
|
const imports = [];
|
|
8091
8120
|
const cssParts = [];
|
|
@@ -8093,7 +8122,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
8093
8122
|
for (const el of run) {
|
|
8094
8123
|
const raw = (el.textContent || "").trim();
|
|
8095
8124
|
if (!raw) continue;
|
|
8096
|
-
const nonImportCss = raw
|
|
8125
|
+
const nonImportCss = replaceMatches(raw, importRuleMatches(raw), (match) => {
|
|
8097
8126
|
const cleaned = match.trim();
|
|
8098
8127
|
if (!seenImports.has(cleaned)) {
|
|
8099
8128
|
seenImports.add(cleaned);
|
|
@@ -8403,7 +8432,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
8403
8432
|
for (const styleEl of document2.querySelectorAll("style")) {
|
|
8404
8433
|
const css = styleEl.textContent || "";
|
|
8405
8434
|
if (!css.includes("url(")) continue;
|
|
8406
|
-
const rewritten = css
|
|
8435
|
+
const rewritten = replaceMatches(css, cssUrlMatches(css), (full, quote, rawUrl) => {
|
|
8407
8436
|
const result = processPath((rawUrl || "").trim());
|
|
8408
8437
|
if (!result) return full;
|
|
8409
8438
|
return `url(${quote || ""}${result}${quote || ""})`;
|
|
@@ -8413,7 +8442,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
8413
8442
|
for (const el of document2.querySelectorAll("[style]")) {
|
|
8414
8443
|
const style = el.getAttribute("style") || "";
|
|
8415
8444
|
if (!style.includes("url(")) continue;
|
|
8416
|
-
const rewritten = style
|
|
8445
|
+
const rewritten = replaceMatches(style, cssUrlMatches(style), (full, quote, rawUrl) => {
|
|
8417
8446
|
const result = processPath((rawUrl || "").trim());
|
|
8418
8447
|
if (!result) return full;
|
|
8419
8448
|
return `url(${quote || ""}${result}${quote || ""})`;
|
|
@@ -8516,13 +8545,10 @@ async function localizeRemoteImageSources(html, downloadDir) {
|
|
|
8516
8545
|
"Localized remote image source(s)"
|
|
8517
8546
|
);
|
|
8518
8547
|
}
|
|
8519
|
-
var REMOTE_BG_URL_RE = /background(?:-image)?\s*:\s*[^;}"']*?url\(\s*["']?(https?:\/\/[^"')]+)["']?\s*\)/gi;
|
|
8520
8548
|
async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
8521
8549
|
const urlSet = /* @__PURE__ */ new Set();
|
|
8522
|
-
const
|
|
8523
|
-
|
|
8524
|
-
while ((m = re.exec(html)) !== null) {
|
|
8525
|
-
if (m[1] && !isGoogleFontsUrl(m[1])) urlSet.add(m[1]);
|
|
8550
|
+
for (const { parts } of remoteBackgroundUrlMatches(html)) {
|
|
8551
|
+
if (parts[1] && !isGoogleFontsUrl(parts[1])) urlSet.add(parts[1]);
|
|
8526
8552
|
}
|
|
8527
8553
|
return downloadAndRewriteUrls(
|
|
8528
8554
|
urlSet,
|
|
@@ -8535,7 +8561,6 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
8535
8561
|
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
8536
8562
|
);
|
|
8537
8563
|
}
|
|
8538
|
-
var REMOTE_FONTFACE_URL_RE = /url\(["']?(https?:\/\/[^"')]+)["']?\)/gi;
|
|
8539
8564
|
function isGoogleFontsUrl(href) {
|
|
8540
8565
|
try {
|
|
8541
8566
|
const host = new URL(href).hostname.toLowerCase();
|
|
@@ -8563,31 +8588,33 @@ async function fetchExternalStylesheetCss(href) {
|
|
|
8563
8588
|
}
|
|
8564
8589
|
function extractFontFaceBlocks(css) {
|
|
8565
8590
|
const blocks = [];
|
|
8591
|
+
const closes = matchingBraces(css);
|
|
8566
8592
|
const atRule = /@font-face\s*/gi;
|
|
8567
|
-
let
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
if (
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
else if (css[i] === "}") depth--;
|
|
8576
|
-
}
|
|
8577
|
-
if (depth === 0) {
|
|
8578
|
-
blocks.push(css.slice(m.index, i));
|
|
8579
|
-
atRule.lastIndex = i;
|
|
8580
|
-
}
|
|
8593
|
+
let open2 = -1;
|
|
8594
|
+
for (let m = atRule.exec(css); m; m = atRule.exec(css)) {
|
|
8595
|
+
if (open2 < atRule.lastIndex) open2 = css.indexOf("{", atRule.lastIndex);
|
|
8596
|
+
if (open2 === -1) break;
|
|
8597
|
+
const close = closes.get(open2);
|
|
8598
|
+
if (close === void 0) continue;
|
|
8599
|
+
blocks.push(css.slice(m.index, close + 1));
|
|
8600
|
+
atRule.lastIndex = close + 1;
|
|
8581
8601
|
}
|
|
8582
8602
|
return blocks;
|
|
8583
8603
|
}
|
|
8604
|
+
function matchingBraces(css) {
|
|
8605
|
+
const closes = /* @__PURE__ */ new Map();
|
|
8606
|
+
const unclosed = [];
|
|
8607
|
+
for (let i = 0; i < css.length; i++) {
|
|
8608
|
+
if (css[i] === "{") unclosed.push(i);
|
|
8609
|
+
else if (css[i] === "}" && unclosed.length > 0) closes.set(unclosed.pop(), i);
|
|
8610
|
+
}
|
|
8611
|
+
return closes;
|
|
8612
|
+
}
|
|
8584
8613
|
async function inlineExternalFontStylesheets(html) {
|
|
8585
|
-
const linkRe = /<link\b[^>]*\brel=["']stylesheet["'][^>]*>/gi;
|
|
8586
8614
|
const hrefRe = /\bhref=["']([^"']+)["']/i;
|
|
8587
8615
|
const linkMatches = [];
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
const tag = linkMatch[0];
|
|
8616
|
+
for (const { parts } of stylesheetLinkMatches(html)) {
|
|
8617
|
+
const tag = parts[0];
|
|
8591
8618
|
const hrefMatch = hrefRe.exec(tag);
|
|
8592
8619
|
if (!hrefMatch?.[1]) continue;
|
|
8593
8620
|
const href = hrefMatch[1];
|
|
@@ -8628,14 +8655,16 @@ ${fontFaceBlocks.join("\n")}
|
|
|
8628
8655
|
}
|
|
8629
8656
|
function projectStylesheetFontFamilies(html, projectDir) {
|
|
8630
8657
|
const families = [];
|
|
8631
|
-
for (const
|
|
8658
|
+
for (const {
|
|
8659
|
+
parts: [tag]
|
|
8660
|
+
} of stylesheetLinkMatches(html)) {
|
|
8632
8661
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
8633
8662
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
8634
8663
|
const sheet = resolve7(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
8635
8664
|
if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
8636
8665
|
for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
|
|
8637
8666
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
8638
|
-
const shipsFile = [...face
|
|
8667
|
+
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
8639
8668
|
const path = decodedUrlPath(url);
|
|
8640
8669
|
const file = path.startsWith("/") ? resolve7(projectDir, `.${path}`) : resolve7(dirname8(sheet), path);
|
|
8641
8670
|
return isPathInside(file, projectDir) && existsSync11(file);
|
|
@@ -8646,11 +8675,9 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
8646
8675
|
return families;
|
|
8647
8676
|
}
|
|
8648
8677
|
function collectFontFaceUrls(html) {
|
|
8649
|
-
const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
8650
8678
|
const urlSet = /* @__PURE__ */ new Set();
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
const cssText = styleMatch[1] ?? "";
|
|
8679
|
+
for (const { parts } of styleBlockMatches(html)) {
|
|
8680
|
+
const cssText = parts[1];
|
|
8654
8681
|
let i = 0;
|
|
8655
8682
|
while (i < cssText.length) {
|
|
8656
8683
|
const atIdx = cssText.indexOf("@font-face", i);
|
|
@@ -8665,10 +8692,8 @@ function collectFontFaceUrls(html) {
|
|
|
8665
8692
|
j++;
|
|
8666
8693
|
}
|
|
8667
8694
|
const block = cssText.slice(braceStart + 1, j - 1);
|
|
8668
|
-
const
|
|
8669
|
-
|
|
8670
|
-
while ((urlMatch = urlRe.exec(block)) !== null) {
|
|
8671
|
-
if (urlMatch[1]) urlSet.add(urlMatch[1]);
|
|
8695
|
+
for (const { parts: parts2 } of remoteFontFaceUrlMatches(block)) {
|
|
8696
|
+
if (parts2[1]) urlSet.add(parts2[1]);
|
|
8672
8697
|
}
|
|
8673
8698
|
i = j;
|
|
8674
8699
|
}
|
|
@@ -8688,7 +8713,6 @@ function localizeFontFaceUrls(html, downloadDir) {
|
|
|
8688
8713
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
8689
8714
|
);
|
|
8690
8715
|
}
|
|
8691
|
-
var LOCAL_FONTFACE_URL_RE = /url\(["']?(?!data:|file:|https?:\/\/)([^"')]+)["']?\)/gi;
|
|
8692
8716
|
function urlOccurrenceRe(localPath) {
|
|
8693
8717
|
const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8694
8718
|
return new RegExp(`url\\((["']?)${escaped}\\1\\)`, "g");
|
|
@@ -8709,23 +8733,15 @@ async function readLocalFont(absPath) {
|
|
|
8709
8733
|
}
|
|
8710
8734
|
async function embedLocalFontFaces(html, projectDir, assetRoot, log = defaultLogger) {
|
|
8711
8735
|
const { fontToDataUri: toDataUri } = await import("@hyperframes/core/fonts/embed");
|
|
8712
|
-
const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
8713
|
-
const fontFaceRe = /@font-face\s*\{([^}]*)\}/gi;
|
|
8714
8736
|
let result = html;
|
|
8715
8737
|
const embeddedPaths = /* @__PURE__ */ new Set();
|
|
8716
8738
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
8717
8739
|
const fileBackedAbsolutePaths = /* @__PURE__ */ new Set();
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
|
|
8723
|
-
while ((ffMatch = ffRe.exec(cssText)) !== null) {
|
|
8724
|
-
const block = ffMatch[1] ?? "";
|
|
8725
|
-
const urlRe = new RegExp(LOCAL_FONTFACE_URL_RE.source, LOCAL_FONTFACE_URL_RE.flags);
|
|
8726
|
-
let urlMatch;
|
|
8727
|
-
while ((urlMatch = urlRe.exec(block)) !== null) {
|
|
8728
|
-
const localPath = urlMatch[1];
|
|
8740
|
+
for (const { parts: style } of styleBlockMatches(html)) {
|
|
8741
|
+
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
8742
|
+
const block = face[1];
|
|
8743
|
+
for (const { parts } of localFontFaceUrlMatches(block)) {
|
|
8744
|
+
const localPath = parts[1];
|
|
8729
8745
|
if (!localPath || embeddedPaths.has(localPath)) continue;
|
|
8730
8746
|
const absPath = localPath.startsWith("/") ? localPath : resolve7(projectDir, localPath);
|
|
8731
8747
|
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
|
|
@@ -8844,6 +8860,9 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
8844
8860
|
if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
|
|
8845
8861
|
throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
|
|
8846
8862
|
}
|
|
8863
|
+
if (!COMPOSITION_FILE.test(htmlPath)) {
|
|
8864
|
+
throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
|
|
8865
|
+
}
|
|
8847
8866
|
const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
|
|
8848
8867
|
const rawHtml = bindVariableMediaSources(
|
|
8849
8868
|
normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
|
|
@@ -9399,6 +9418,14 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
|
|
|
9399
9418
|
}
|
|
9400
9419
|
|
|
9401
9420
|
// src/services/render/stages/compileStage.ts
|
|
9421
|
+
function animatedGifCacheDir(extractCacheDir) {
|
|
9422
|
+
try {
|
|
9423
|
+
const root = extractCacheDir && privateCacheRoot(extractCacheDir);
|
|
9424
|
+
return root ? join20(root, "animated-gif") : void 0;
|
|
9425
|
+
} catch {
|
|
9426
|
+
return void 0;
|
|
9427
|
+
}
|
|
9428
|
+
}
|
|
9402
9429
|
function adaptAspectAgnosticResolution(requested, aspectAgnostic, width, height, log) {
|
|
9403
9430
|
if (!requested || !aspectAgnostic) return requested;
|
|
9404
9431
|
const flipped = suggestMatchingPreset(width, height, requested);
|
|
@@ -9478,7 +9505,7 @@ async function runCompileStage(input) {
|
|
|
9478
9505
|
variables: input.variables,
|
|
9479
9506
|
urlByAbsentLocalPath: input.urlByAbsentLocalPath,
|
|
9480
9507
|
pageMotionBlur: input.pageMotionBlur,
|
|
9481
|
-
animatedGifCacheDir:
|
|
9508
|
+
animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
|
|
9482
9509
|
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
|
|
9483
9510
|
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
|
|
9484
9511
|
});
|
|
@@ -10358,6 +10385,10 @@ import {
|
|
|
10358
10385
|
resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
|
|
10359
10386
|
isHttpUrl as isHttpUrl2,
|
|
10360
10387
|
assertPublicHttpsUrl,
|
|
10388
|
+
downloadToTemp as downloadToTemp2,
|
|
10389
|
+
resolveRestrictPageNetwork,
|
|
10390
|
+
isUrlNotPermittedError,
|
|
10391
|
+
writeUrlDownloadTelemetry as writeUrlDownloadTelemetry2,
|
|
10361
10392
|
resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
|
|
10362
10393
|
runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
|
|
10363
10394
|
safeVideoExtractionSourceIdentity,
|
|
@@ -10598,6 +10629,7 @@ async function runExtractVideosStage(input) {
|
|
|
10598
10629
|
deferRangeExtraction,
|
|
10599
10630
|
shownBoxes,
|
|
10600
10631
|
urlByAbsentLocalPath,
|
|
10632
|
+
audioDownloadDir,
|
|
10601
10633
|
skipFrameExtractionIds = []
|
|
10602
10634
|
} = input;
|
|
10603
10635
|
const stage2Start = Date.now();
|
|
@@ -10670,7 +10702,15 @@ async function runExtractVideosStage(input) {
|
|
|
10670
10702
|
imageColorSpaces.push(...probed);
|
|
10671
10703
|
}
|
|
10672
10704
|
if (skipFrameExtractionIds.length > 0) {
|
|
10673
|
-
await appendVideoAudioFromProbe({
|
|
10705
|
+
await appendVideoAudioFromProbe({
|
|
10706
|
+
projectDir,
|
|
10707
|
+
compiledDir,
|
|
10708
|
+
composition,
|
|
10709
|
+
urlByAbsentLocalPath,
|
|
10710
|
+
downloadDir: audioDownloadDir,
|
|
10711
|
+
signal: abortSignal,
|
|
10712
|
+
log
|
|
10713
|
+
});
|
|
10674
10714
|
videoReadinessSkipIds = [...skipFrameExtractionIds];
|
|
10675
10715
|
} else if (composition.videos.length > 0) {
|
|
10676
10716
|
const totalVideos = composition.videos.length;
|
|
@@ -10777,17 +10817,37 @@ function isPublicHttpsUrl(url) {
|
|
|
10777
10817
|
return false;
|
|
10778
10818
|
}
|
|
10779
10819
|
}
|
|
10820
|
+
function localProbeSource(src, input) {
|
|
10821
|
+
const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
|
|
10822
|
+
const readFrom = input.urlByAbsentLocalPath?.get(path) ?? path;
|
|
10823
|
+
return isHttpUrl2(readFrom) || existsSync13(readFrom) ? readFrom : null;
|
|
10824
|
+
}
|
|
10825
|
+
async function remoteProbeSource(video, input) {
|
|
10826
|
+
if (!isPublicHttpsUrl(video.src)) return null;
|
|
10827
|
+
if (!resolveRestrictPageNetwork()) return video.src;
|
|
10828
|
+
if (!video.hasAudio || video.hidden) return null;
|
|
10829
|
+
const downloadDir = input.downloadDir ?? join22(input.compiledDir, REMOTE_MEDIA_SUBDIR);
|
|
10830
|
+
try {
|
|
10831
|
+
return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
|
|
10832
|
+
onTelemetry: writeUrlDownloadTelemetry2
|
|
10833
|
+
});
|
|
10834
|
+
} catch (error) {
|
|
10835
|
+
if (!isUrlNotPermittedError(error)) throw error;
|
|
10836
|
+
input.log?.warn("Video sound skipped: its URL is outside the download address rules", {
|
|
10837
|
+
videoId: video.id
|
|
10838
|
+
});
|
|
10839
|
+
return null;
|
|
10840
|
+
}
|
|
10841
|
+
}
|
|
10780
10842
|
async function appendVideoAudioFromProbe(input) {
|
|
10781
|
-
const {
|
|
10843
|
+
const { composition } = input;
|
|
10782
10844
|
const videos = composition.videos.filter(
|
|
10783
10845
|
(video) => !isVideoPastTimelineEnd(video, composition.duration)
|
|
10784
10846
|
);
|
|
10785
10847
|
const probed = await Promise.all(
|
|
10786
10848
|
videos.map(async (video) => {
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
|
|
10790
|
-
if (!isHttpUrl2(readFrom) && !existsSync13(readFrom)) return null;
|
|
10849
|
+
const readFrom = isHttpUrl2(video.src) ? await remoteProbeSource(video, input) : localProbeSource(video.src, input);
|
|
10850
|
+
if (readFrom === null) return null;
|
|
10791
10851
|
const metadata = await extractMediaMetadata4(readFrom);
|
|
10792
10852
|
const window2 = await resolveFinalFrameExtractionWindow2(
|
|
10793
10853
|
readFrom,
|
|
@@ -11565,7 +11625,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
11565
11625
|
audioResult = await processCompositionAudio(
|
|
11566
11626
|
audios,
|
|
11567
11627
|
projectDir,
|
|
11568
|
-
|
|
11628
|
+
audioWorkDir(workDir),
|
|
11569
11629
|
audioOutputPath,
|
|
11570
11630
|
duration,
|
|
11571
11631
|
abortSignal,
|
|
@@ -14463,6 +14523,19 @@ function resolveCaptureForceScreenshotForPageSideCompositing(args) {
|
|
|
14463
14523
|
function shouldDiscardProbeSessionForPageSideCompositing(args) {
|
|
14464
14524
|
return args.hasProbeSession && args.usePageSideCompositing;
|
|
14465
14525
|
}
|
|
14526
|
+
var PAGE_SIDE_COMPOSITOR_CANVAS_ID = "__hf-page-side-compositor";
|
|
14527
|
+
async function pageInstallsShaderCompositor(open2, session = { initializeSession: initializeSession8, closeCaptureSession: closeCaptureSession8 }) {
|
|
14528
|
+
const probe = await open2();
|
|
14529
|
+
try {
|
|
14530
|
+
await session.initializeSession(probe);
|
|
14531
|
+
return await probe.page.evaluate(
|
|
14532
|
+
(id) => document.getElementById(id) !== null,
|
|
14533
|
+
PAGE_SIDE_COMPOSITOR_CANVAS_ID
|
|
14534
|
+
);
|
|
14535
|
+
} finally {
|
|
14536
|
+
await session.closeCaptureSession(probe);
|
|
14537
|
+
}
|
|
14538
|
+
}
|
|
14466
14539
|
function deVerifyFallbackTelemetry(err) {
|
|
14467
14540
|
const details = getDrawElementVerificationDetails(err);
|
|
14468
14541
|
return {
|
|
@@ -14893,6 +14966,7 @@ async function executeRenderPipeline(input) {
|
|
|
14893
14966
|
log,
|
|
14894
14967
|
composition,
|
|
14895
14968
|
skipFrameExtractionIds: videoLayer ? [videoLayer.videoId] : [],
|
|
14969
|
+
audioDownloadDir: audioWorkDir(workDir),
|
|
14896
14970
|
abortSignal: executionSignal,
|
|
14897
14971
|
assertNotAborted,
|
|
14898
14972
|
// Local staging can use links; distributed plan() alone requires real copies.
|
|
@@ -15598,7 +15672,7 @@ async function executeRenderPipeline(input) {
|
|
|
15598
15672
|
};
|
|
15599
15673
|
const videoExt = FORMAT_EXT[outputFormat] ?? ".mp4";
|
|
15600
15674
|
const videoOnlyPath = join32(workDir, `video-only${videoExt}`);
|
|
15601
|
-
|
|
15675
|
+
let usePageSideCompositingForTransitions = (cfg.enablePageSideCompositing || isGif) && compiled.hasShaderTransitions && !hasHdrContent && outputSupportsPageSideShaderCompositing(outputFormat);
|
|
15602
15676
|
if (usePageSideCompositingForTransitions) {
|
|
15603
15677
|
activeFileServer.addPreHeadScript(HF_PAGE_SIDE_COMPOSITING_STUB);
|
|
15604
15678
|
if (shouldDiscardProbeSessionForPageSideCompositing({
|
|
@@ -15612,6 +15686,26 @@ async function executeRenderPipeline(input) {
|
|
|
15612
15686
|
"[Render] Recreating capture session so page-side compositing pre-head script is loaded."
|
|
15613
15687
|
);
|
|
15614
15688
|
}
|
|
15689
|
+
try {
|
|
15690
|
+
usePageSideCompositingForTransitions = await pageInstallsShaderCompositor(
|
|
15691
|
+
() => createCaptureSession8(activeFileServer.url, framesDir, buildPrepCaptureOptions(), null, {
|
|
15692
|
+
...cfg,
|
|
15693
|
+
forceScreenshot: true
|
|
15694
|
+
})
|
|
15695
|
+
);
|
|
15696
|
+
} catch (error) {
|
|
15697
|
+
assertNotAborted();
|
|
15698
|
+
log.warn("[Render] Shader compositor check failed; keeping page-side compositing.", {
|
|
15699
|
+
error: error instanceof Error ? error.message : String(error)
|
|
15700
|
+
});
|
|
15701
|
+
}
|
|
15702
|
+
if (!usePageSideCompositingForTransitions) {
|
|
15703
|
+
log.warn(
|
|
15704
|
+
"[Render] The page's shader-transitions build cannot composite in this browser; shader transitions blend on the Node-side layered path."
|
|
15705
|
+
);
|
|
15706
|
+
}
|
|
15707
|
+
}
|
|
15708
|
+
if (usePageSideCompositingForTransitions) {
|
|
15615
15709
|
captureForceScreenshot = resolveCaptureForceScreenshotForPageSideCompositing({
|
|
15616
15710
|
forceScreenshot: captureForceScreenshot,
|
|
15617
15711
|
usePageSideCompositing: true
|
|
@@ -21587,7 +21681,7 @@ import {
|
|
|
21587
21681
|
|
|
21588
21682
|
// src/index.ts
|
|
21589
21683
|
import { createVideoFrameInjector as createVideoFrameInjector4 } from "@hyperframes/engine";
|
|
21590
|
-
import { isBlockedNetworkHost } from "@hyperframes/engine";
|
|
21684
|
+
import { isBlockedNetworkHost, onRenderRefusal } from "@hyperframes/engine";
|
|
21591
21685
|
|
|
21592
21686
|
// src/config.ts
|
|
21593
21687
|
import {
|
|
@@ -21608,6 +21702,7 @@ import {
|
|
|
21608
21702
|
import { resolve as resolve12, dirname as dirname19, join as join49 } from "node:path";
|
|
21609
21703
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
21610
21704
|
import { parseArgs } from "node:util";
|
|
21705
|
+
import { isIP } from "node:net";
|
|
21611
21706
|
import crypto from "node:crypto";
|
|
21612
21707
|
import { Hono as Hono2 } from "hono";
|
|
21613
21708
|
import { streamSSE } from "hono/streaming";
|
|
@@ -21617,6 +21712,7 @@ import {
|
|
|
21617
21712
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD5,
|
|
21618
21713
|
referenceBackgroundResult as referenceBackgroundResult7
|
|
21619
21714
|
} from "@hyperframes/engine";
|
|
21715
|
+
import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
|
|
21620
21716
|
|
|
21621
21717
|
// src/services/hyperframeLint.ts
|
|
21622
21718
|
import {
|
|
@@ -21672,7 +21768,11 @@ function readEntryHtml(filePath) {
|
|
|
21672
21768
|
closeSync7(fd);
|
|
21673
21769
|
}
|
|
21674
21770
|
}
|
|
21675
|
-
function
|
|
21771
|
+
function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
21772
|
+
const entryRelativePath = relative8(absProjectDir, absoluteEntryPath);
|
|
21773
|
+
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep6}`) || isAbsolute5(entryRelativePath) || isAllowedEntry !== void 0 && !isAllowedEntry(absoluteEntryPath);
|
|
21774
|
+
}
|
|
21775
|
+
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
21676
21776
|
const absProjectDir = resolve11(projectDir);
|
|
21677
21777
|
if (!existsSync30(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
|
|
21678
21778
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
@@ -21682,8 +21782,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile) {
|
|
|
21682
21782
|
);
|
|
21683
21783
|
for (const entryFile of entryCandidates) {
|
|
21684
21784
|
const absoluteEntryPath = resolve11(absProjectDir, entryFile);
|
|
21685
|
-
|
|
21686
|
-
if (entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep6}`) || isAbsolute5(entryRelativePath)) {
|
|
21785
|
+
if (leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry)) {
|
|
21687
21786
|
return { error: `Entry file must stay inside project directory: ${entryFile}` };
|
|
21688
21787
|
}
|
|
21689
21788
|
const html = readEntryHtml(absoluteEntryPath);
|
|
@@ -21699,10 +21798,10 @@ function readProjectEntryFile(projectDir, preferredEntryFile) {
|
|
|
21699
21798
|
error: `No HTML entry file found in project directory: ${join47(absProjectDir, preferredEntryFile || "index.html")}`
|
|
21700
21799
|
};
|
|
21701
21800
|
}
|
|
21702
|
-
function prepareHyperframeLintBody(body) {
|
|
21801
|
+
function prepareHyperframeLintBody(body, isAllowedEntry) {
|
|
21703
21802
|
const requestedEntryFile = typeof body.entryFile === "string" && body.entryFile.trim().length > 0 ? body.entryFile.trim() : void 0;
|
|
21704
21803
|
if (typeof body.projectDir === "string" && body.projectDir.trim().length > 0) {
|
|
21705
|
-
const prepared = readProjectEntryFile(body.projectDir, requestedEntryFile);
|
|
21804
|
+
const prepared = readProjectEntryFile(body.projectDir, requestedEntryFile, isAllowedEntry);
|
|
21706
21805
|
if ("error" in prepared) {
|
|
21707
21806
|
return prepared;
|
|
21708
21807
|
}
|
|
@@ -21978,16 +22077,22 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
21978
22077
|
});
|
|
21979
22078
|
return renderConfigFromRequest(request, { logger: log });
|
|
21980
22079
|
}
|
|
21981
|
-
function resolvePreparedRenderOutput(prepared, rendersDir, log) {
|
|
22080
|
+
function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
21982
22081
|
const { input, cleanupProjectDir } = prepared;
|
|
21983
22082
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
|
|
22083
|
+
if (confineOutput) {
|
|
22084
|
+
mkdirSync21(rendersDir, { recursive: true });
|
|
22085
|
+
if (!isSafePath3(rendersDir, absoluteOutputPath)) {
|
|
22086
|
+
throw new Error("outputPath must be inside the renders directory");
|
|
22087
|
+
}
|
|
22088
|
+
}
|
|
21984
22089
|
const outputDir = dirname19(absoluteOutputPath);
|
|
21985
22090
|
if (!existsSync32(outputDir)) mkdirSync21(outputDir, { recursive: true });
|
|
21986
22091
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
21987
22092
|
}
|
|
21988
|
-
function prepareRenderJob(prepared, rendersDir, log) {
|
|
22093
|
+
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
21989
22094
|
try {
|
|
21990
|
-
const output = resolvePreparedRenderOutput(prepared, rendersDir, log);
|
|
22095
|
+
const output = resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput);
|
|
21991
22096
|
const job = createRenderJob(buildRenderJobConfig(output.input, output.absoluteOutputPath, log));
|
|
21992
22097
|
return { ...output, job };
|
|
21993
22098
|
} catch (error) {
|
|
@@ -22038,16 +22143,32 @@ function validateOutputResolutionOverride(body) {
|
|
|
22038
22143
|
return void 0;
|
|
22039
22144
|
}
|
|
22040
22145
|
var MAX_PREVIEW_HTML_BYTES = 20 * 1024 * 1024;
|
|
22041
|
-
function
|
|
22146
|
+
function resolveRenderRequestPolicy(options) {
|
|
22147
|
+
return {
|
|
22148
|
+
projectsDir: resolve12(
|
|
22149
|
+
options.projectsDir ?? (process.env.PRODUCER_PROJECTS_DIR || process.cwd())
|
|
22150
|
+
),
|
|
22151
|
+
allowDebug: options.allowDebug ?? process.env.PRODUCER_ALLOW_DEBUG === "1"
|
|
22152
|
+
};
|
|
22153
|
+
}
|
|
22154
|
+
function isAllowedProjectPath(projectsDir, path) {
|
|
22155
|
+
return isSafePath3(projectsDir, path) && !isSafePath3(resolveRenderDebugDir(), path);
|
|
22156
|
+
}
|
|
22157
|
+
function isAllowedEntryPath(policy, projectDir, path) {
|
|
22158
|
+
return isSafePath3(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
|
|
22159
|
+
}
|
|
22160
|
+
function prepareProjectDirectory(projectDir, options, policy) {
|
|
22042
22161
|
const candidate = nonEmptyString(projectDir);
|
|
22043
22162
|
if (!candidate) return null;
|
|
22044
|
-
const absProjectDir = resolve12(candidate);
|
|
22045
|
-
|
|
22046
|
-
|
|
22163
|
+
const absProjectDir = policy ? resolve12(policy.projectsDir, candidate) : resolve12(candidate);
|
|
22164
|
+
const shown = policy ? candidate : absProjectDir;
|
|
22165
|
+
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync32(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
|
|
22166
|
+
return { error: `Project directory not found: ${shown}` };
|
|
22047
22167
|
}
|
|
22048
22168
|
const entry = options.entryFile || "index.html";
|
|
22049
|
-
|
|
22050
|
-
|
|
22169
|
+
const entryPath = resolve12(absProjectDir, entry);
|
|
22170
|
+
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync32(entryPath)) {
|
|
22171
|
+
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
22051
22172
|
}
|
|
22052
22173
|
return { prepared: { input: { projectDir: absProjectDir, ...options } } };
|
|
22053
22174
|
}
|
|
@@ -22076,15 +22197,18 @@ function materializeInlineProject(html, options) {
|
|
|
22076
22197
|
}
|
|
22077
22198
|
};
|
|
22078
22199
|
}
|
|
22079
|
-
async function prepareRenderBody(body) {
|
|
22200
|
+
async function prepareRenderBody(body, policy) {
|
|
22080
22201
|
const overrideError = validateRenderOverrides(body);
|
|
22081
22202
|
if (overrideError) return { error: overrideError };
|
|
22203
|
+
if (policy && body.debug === true && !policy.allowDebug) {
|
|
22204
|
+
return { error: "debug is disabled on this server (set allowDebug or PRODUCER_ALLOW_DEBUG=1)" };
|
|
22205
|
+
}
|
|
22082
22206
|
const pageMotionBlur = body.pageMotionBlur;
|
|
22083
22207
|
if (pageMotionBlur !== void 0 && pageMotionBlur !== "off") {
|
|
22084
22208
|
return { error: "pageMotionBlur must be off when supplied" };
|
|
22085
22209
|
}
|
|
22086
22210
|
const options = { ...parseRenderOptions(body), pageMotionBlur };
|
|
22087
|
-
const project = prepareProjectDirectory(body.projectDir, options);
|
|
22211
|
+
const project = prepareProjectDirectory(body.projectDir, options, policy);
|
|
22088
22212
|
if (project) return project;
|
|
22089
22213
|
const source = await resolveInlineRenderHtml(body);
|
|
22090
22214
|
return "error" in source ? source : materializeInlineProject(source.html, options);
|
|
@@ -22137,6 +22261,9 @@ function cleanupTempDir(dir, log) {
|
|
|
22137
22261
|
});
|
|
22138
22262
|
}
|
|
22139
22263
|
}
|
|
22264
|
+
function publicPerfSummary(job) {
|
|
22265
|
+
return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
|
|
22266
|
+
}
|
|
22140
22267
|
function outputFileSize(path) {
|
|
22141
22268
|
return existsSync32(path) ? statSync14(path).size : 0;
|
|
22142
22269
|
}
|
|
@@ -22149,7 +22276,7 @@ function createBlockingProgressReporter(log, requestId) {
|
|
|
22149
22276
|
log.info(`render progress ${pct}%`, { requestId, stage: job.currentStage, message });
|
|
22150
22277
|
};
|
|
22151
22278
|
}
|
|
22152
|
-
async function prepareSseRenderRequest(c, stream, requestId) {
|
|
22279
|
+
async function prepareSseRenderRequest(c, stream, requestId, policy) {
|
|
22153
22280
|
let body;
|
|
22154
22281
|
try {
|
|
22155
22282
|
body = await c.req.json();
|
|
@@ -22164,7 +22291,7 @@ async function prepareSseRenderRequest(c, stream, requestId) {
|
|
|
22164
22291
|
});
|
|
22165
22292
|
return null;
|
|
22166
22293
|
}
|
|
22167
|
-
const prepared = await prepareRenderBody(body);
|
|
22294
|
+
const prepared = await prepareRenderBody(body, policy);
|
|
22168
22295
|
if (!("error" in prepared)) return prepared.prepared;
|
|
22169
22296
|
await stream.writeSSE({
|
|
22170
22297
|
data: JSON.stringify({
|
|
@@ -22236,6 +22363,7 @@ function createRenderHandlers(options = {}) {
|
|
|
22236
22363
|
const getRequestId = options.getRequestId ?? ((c) => c.req.header("x-request-id") || crypto.randomUUID());
|
|
22237
22364
|
const outputUrlPrefix = options.outputUrlPrefix ?? "/outputs";
|
|
22238
22365
|
const rendersDir = options.rendersDir ?? process.env.PRODUCER_RENDERS_DIR ?? "/tmp";
|
|
22366
|
+
const policy = options.confineRequests ? resolveRenderRequestPolicy(options) : void 0;
|
|
22239
22367
|
const artifactTtlMs = options.artifactTtlMs ?? Number(process.env.PRODUCER_OUTPUT_ARTIFACT_TTL_MS || 15 * 60 * 1e3);
|
|
22240
22368
|
const store = createArtifactStore(artifactTtlMs);
|
|
22241
22369
|
const maxConcurrentRenders = options.maxConcurrentRenders ?? Number(process.env.PRODUCER_MAX_CONCURRENT_RENDERS || 2);
|
|
@@ -22254,7 +22382,18 @@ function createRenderHandlers(options = {}) {
|
|
|
22254
22382
|
} catch {
|
|
22255
22383
|
return c.json({ success: false, requestId, error: "Invalid JSON body" }, 400);
|
|
22256
22384
|
}
|
|
22257
|
-
const
|
|
22385
|
+
const lintProjectDir = nonEmptyString(body.projectDir);
|
|
22386
|
+
let isAllowedEntry;
|
|
22387
|
+
if (policy && lintProjectDir) {
|
|
22388
|
+
const absProjectDir = resolve12(policy.projectsDir, lintProjectDir);
|
|
22389
|
+
if (!isAllowedProjectPath(policy.projectsDir, absProjectDir)) {
|
|
22390
|
+
const error = `Project directory not found: ${lintProjectDir}`;
|
|
22391
|
+
return c.json({ success: false, requestId, error }, 400);
|
|
22392
|
+
}
|
|
22393
|
+
body = { ...body, projectDir: absProjectDir };
|
|
22394
|
+
isAllowedEntry = (path) => isAllowedEntryPath(policy, absProjectDir, path);
|
|
22395
|
+
}
|
|
22396
|
+
const preparedResult = prepareHyperframeLintBody(body, isAllowedEntry);
|
|
22258
22397
|
if ("error" in preparedResult) {
|
|
22259
22398
|
return c.json({ success: false, requestId, error: preparedResult.error }, 400);
|
|
22260
22399
|
}
|
|
@@ -22283,11 +22422,11 @@ function createRenderHandlers(options = {}) {
|
|
|
22283
22422
|
} catch {
|
|
22284
22423
|
return c.json({ success: false, requestId, error: "Invalid JSON body" }, 400);
|
|
22285
22424
|
}
|
|
22286
|
-
const preparedResult = await prepareRenderBody(body);
|
|
22425
|
+
const preparedResult = await prepareRenderBody(body, policy);
|
|
22287
22426
|
if ("error" in preparedResult) {
|
|
22288
22427
|
return c.json({ success: false, requestId, error: preparedResult.error }, 400);
|
|
22289
22428
|
}
|
|
22290
|
-
const preparedJob = prepareRenderJob(preparedResult.prepared, rendersDir, log);
|
|
22429
|
+
const preparedJob = prepareRenderJob(preparedResult.prepared, rendersDir, log, !!policy);
|
|
22291
22430
|
if ("error" in preparedJob) {
|
|
22292
22431
|
return c.json({ success: false, requestId, error: preparedJob.error }, 400);
|
|
22293
22432
|
}
|
|
@@ -22328,7 +22467,7 @@ function createRenderHandlers(options = {}) {
|
|
|
22328
22467
|
videoDurationSeconds: job.duration ?? null,
|
|
22329
22468
|
outcome: job.outcome ?? "completed",
|
|
22330
22469
|
warnings: job.warnings,
|
|
22331
|
-
perf: job.perfSummary ?? null,
|
|
22470
|
+
perf: policy ? publicPerfSummary(job) : job.perfSummary ?? null,
|
|
22332
22471
|
...strictVariablesResult(job)
|
|
22333
22472
|
});
|
|
22334
22473
|
} catch (error) {
|
|
@@ -22365,9 +22504,9 @@ function createRenderHandlers(options = {}) {
|
|
|
22365
22504
|
return streamSSE(c, async (stream) => {
|
|
22366
22505
|
const requestId = getRequestId(c);
|
|
22367
22506
|
const t0 = Date.now();
|
|
22368
|
-
const prepared = await prepareSseRenderRequest(c, stream, requestId);
|
|
22507
|
+
const prepared = await prepareSseRenderRequest(c, stream, requestId, policy);
|
|
22369
22508
|
if (!prepared) return;
|
|
22370
|
-
const preparedJob = prepareRenderJob(prepared, rendersDir, log);
|
|
22509
|
+
const preparedJob = prepareRenderJob(prepared, rendersDir, log, !!policy);
|
|
22371
22510
|
if ("error" in preparedJob) {
|
|
22372
22511
|
await stream.writeSSE({
|
|
22373
22512
|
data: JSON.stringify({
|
|
@@ -22424,7 +22563,7 @@ function createRenderHandlers(options = {}) {
|
|
|
22424
22563
|
videoDurationSeconds: job.duration ?? null,
|
|
22425
22564
|
outcome: job.outcome ?? "completed",
|
|
22426
22565
|
warnings: job.warnings,
|
|
22427
|
-
perf: job.perfSummary ?? null,
|
|
22566
|
+
perf: policy ? publicPerfSummary(job) : job.perfSummary ?? null,
|
|
22428
22567
|
producerVersion: readProducerVersion(),
|
|
22429
22568
|
...strictVariablesResult(job)
|
|
22430
22569
|
})
|
|
@@ -22482,9 +22621,79 @@ function isCrossOriginBrowserRequest(c) {
|
|
|
22482
22621
|
return true;
|
|
22483
22622
|
}
|
|
22484
22623
|
}
|
|
22624
|
+
function hostnameOf(host) {
|
|
22625
|
+
try {
|
|
22626
|
+
return new URL(`http://${host}`).hostname.toLowerCase();
|
|
22627
|
+
} catch {
|
|
22628
|
+
return null;
|
|
22629
|
+
}
|
|
22630
|
+
}
|
|
22631
|
+
function isAllowedBrowserHostname(hostname2, allowed) {
|
|
22632
|
+
if (!hostname2) return false;
|
|
22633
|
+
if (hostname2 === "localhost" || hostname2.endsWith(".localhost")) return true;
|
|
22634
|
+
if (isIP(hostname2.replace(/^\[|\]$/g, "")) !== 0) return true;
|
|
22635
|
+
return allowed.has(hostname2);
|
|
22636
|
+
}
|
|
22637
|
+
function allowedHostnames(options) {
|
|
22638
|
+
const fromEnv = (process.env.PRODUCER_ALLOWED_HOSTS ?? "").split(",");
|
|
22639
|
+
const names = /* @__PURE__ */ new Set();
|
|
22640
|
+
for (const entry of [...options.allowedHosts ?? [], ...fromEnv]) {
|
|
22641
|
+
const hostname2 = entry.trim() ? hostnameOf(entry.trim()) : null;
|
|
22642
|
+
if (hostname2) names.add(hostname2);
|
|
22643
|
+
}
|
|
22644
|
+
return names;
|
|
22645
|
+
}
|
|
22646
|
+
function resolveAuthToken(options) {
|
|
22647
|
+
return options.authToken?.trim() || process.env.PRODUCER_AUTH_TOKEN?.trim() || "";
|
|
22648
|
+
}
|
|
22649
|
+
function hasBearerToken(c, token) {
|
|
22650
|
+
const digest = (value) => crypto.createHash("sha256").update(value).digest();
|
|
22651
|
+
return crypto.timingSafeEqual(
|
|
22652
|
+
digest(c.req.header("authorization") ?? ""),
|
|
22653
|
+
digest(`Bearer ${token}`)
|
|
22654
|
+
);
|
|
22655
|
+
}
|
|
22656
|
+
function isLoopbackHostname(hostname2) {
|
|
22657
|
+
const host = hostname2.replace(/^\[|\]$/g, "").toLowerCase();
|
|
22658
|
+
return host === "localhost" || host === "::1" || isIP(host) === 4 && host.startsWith("127.");
|
|
22659
|
+
}
|
|
22660
|
+
function isDisallowedBrowserHost(c, allowed) {
|
|
22661
|
+
const origin = c.req.header("origin");
|
|
22662
|
+
if (!origin && !c.req.header("sec-fetch-site")) return false;
|
|
22663
|
+
if (!isAllowedBrowserHostname(hostnameOf(c.req.header("host") ?? ""), allowed)) return true;
|
|
22664
|
+
if (!origin) return false;
|
|
22665
|
+
try {
|
|
22666
|
+
return !isAllowedBrowserHostname(new URL(origin).hostname.toLowerCase(), allowed);
|
|
22667
|
+
} catch {
|
|
22668
|
+
return true;
|
|
22669
|
+
}
|
|
22670
|
+
}
|
|
22485
22671
|
function createProducerApp(options = {}) {
|
|
22486
22672
|
const app = new Hono2();
|
|
22487
|
-
const handlers = createRenderHandlers(
|
|
22673
|
+
const handlers = createRenderHandlers({
|
|
22674
|
+
...options,
|
|
22675
|
+
confineRequests: options.confineRequests ?? true
|
|
22676
|
+
});
|
|
22677
|
+
const allowed = allowedHostnames(options);
|
|
22678
|
+
const authToken = resolveAuthToken(options);
|
|
22679
|
+
app.use("*", async (c, next) => {
|
|
22680
|
+
if (authToken && c.req.path !== "/health" && !hasBearerToken(c, authToken)) {
|
|
22681
|
+
return c.json({ success: false, error: "Unauthorized" }, 401);
|
|
22682
|
+
}
|
|
22683
|
+
await next();
|
|
22684
|
+
});
|
|
22685
|
+
app.use("*", async (c, next) => {
|
|
22686
|
+
if (isDisallowedBrowserHost(c, allowed)) {
|
|
22687
|
+
return c.json(
|
|
22688
|
+
{
|
|
22689
|
+
success: false,
|
|
22690
|
+
error: "Host not allowed. Add it to allowedHosts or PRODUCER_ALLOWED_HOSTS."
|
|
22691
|
+
},
|
|
22692
|
+
403
|
|
22693
|
+
);
|
|
22694
|
+
}
|
|
22695
|
+
await next();
|
|
22696
|
+
});
|
|
22488
22697
|
app.post("*", async (c, next) => {
|
|
22489
22698
|
if (isCrossOriginBrowserRequest(c)) {
|
|
22490
22699
|
return c.json({ success: false, error: "Cross-origin requests are not allowed" }, 403);
|
|
@@ -22501,10 +22710,17 @@ function createProducerApp(options = {}) {
|
|
|
22501
22710
|
}
|
|
22502
22711
|
function startServer(options = {}) {
|
|
22503
22712
|
const port = options.port ?? parseInt(process.env.PRODUCER_PORT ?? "9847", 10);
|
|
22713
|
+
const hostname2 = options.hostname || process.env.PRODUCER_HOST || "127.0.0.1";
|
|
22504
22714
|
const log = options.logger ?? defaultLogger;
|
|
22715
|
+
if (!isLoopbackHostname(hostname2) && !resolveAuthToken(options)) {
|
|
22716
|
+
throw new Error(
|
|
22717
|
+
`Refusing to listen on ${hostname2} without an auth token. Set authToken or PRODUCER_AUTH_TOKEN, or listen on a loopback address.`
|
|
22718
|
+
);
|
|
22719
|
+
}
|
|
22505
22720
|
const app = createProducerApp(options);
|
|
22506
|
-
const server = serve2({ fetch: app.fetch, port }, () => {
|
|
22507
|
-
|
|
22721
|
+
const server = serve2({ fetch: app.fetch, port, hostname: hostname2 }, (info) => {
|
|
22722
|
+
const address = info.family === "IPv6" ? `[${info.address}]` : info.address;
|
|
22723
|
+
log.info(`Listening on http://${address}:${info.port}`);
|
|
22508
22724
|
});
|
|
22509
22725
|
server.setTimeout(0);
|
|
22510
22726
|
server.requestTimeout = 0;
|
|
@@ -23007,6 +23223,7 @@ export {
|
|
|
23007
23223
|
materializePlanV2Target,
|
|
23008
23224
|
mediaProfileMatchesElementType,
|
|
23009
23225
|
normalizeErrorMessage,
|
|
23226
|
+
onRenderRefusal,
|
|
23010
23227
|
parseRenderRequest,
|
|
23011
23228
|
planV2,
|
|
23012
23229
|
planV2WithPublisher,
|