@hyperframes/producer 0.9.69 → 0.9.71
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/dist/distributed.js +143 -90
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +72 -72
- package/dist/index.js +379 -292
- package/dist/public-server.js +268 -183
- package/dist/services/htmlCompiler.d.ts +16 -2
- package/dist/services/render/audioPadTrim.d.ts +2 -1
- package/dist/services/render/segmentManifest.d.ts +3 -4
- package/dist/services/renderOrchestrator.d.ts +1 -1
- package/package.json +7 -7
package/dist/public-server.js
CHANGED
|
@@ -18,11 +18,11 @@ function requireOutputDimensions(expected, width, height) {
|
|
|
18
18
|
|
|
19
19
|
// src/server.ts
|
|
20
20
|
import {
|
|
21
|
-
existsSync as
|
|
21
|
+
existsSync as existsSync25,
|
|
22
22
|
mkdirSync as mkdirSync13,
|
|
23
23
|
statSync as statSync12,
|
|
24
24
|
mkdtempSync,
|
|
25
|
-
writeFileSync as
|
|
25
|
+
writeFileSync as writeFileSync7,
|
|
26
26
|
rmSync as rmSync13,
|
|
27
27
|
createReadStream as createReadStream4
|
|
28
28
|
} from "node:fs";
|
|
@@ -39,17 +39,17 @@ import {
|
|
|
39
39
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD3,
|
|
40
40
|
referenceBackgroundResult as referenceBackgroundResult5
|
|
41
41
|
} from "@hyperframes/engine";
|
|
42
|
-
import { isSafePath as
|
|
42
|
+
import { isSafePath as isSafePath4 } from "@hyperframes/core/safe-path";
|
|
43
43
|
|
|
44
44
|
// src/services/renderOrchestrator.ts
|
|
45
45
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
|
|
46
46
|
import {
|
|
47
|
-
existsSync as
|
|
47
|
+
existsSync as existsSync21,
|
|
48
48
|
mkdirSync as mkdirSync12,
|
|
49
49
|
readdirSync as readdirSync6,
|
|
50
50
|
rmSync as rmSync12,
|
|
51
51
|
statSync as statSync10,
|
|
52
|
-
writeFileSync as
|
|
52
|
+
writeFileSync as writeFileSync6,
|
|
53
53
|
copyFileSync as copyFileSync5,
|
|
54
54
|
appendFileSync
|
|
55
55
|
} from "fs";
|
|
@@ -2624,7 +2624,7 @@ function replanAfterFailure(plan, failure) {
|
|
|
2624
2624
|
}
|
|
2625
2625
|
|
|
2626
2626
|
// src/services/render/stages/captureSegmentedStage.ts
|
|
2627
|
-
import { existsSync as
|
|
2627
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync4, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
|
|
2628
2628
|
import { join as join12 } from "node:path";
|
|
2629
2629
|
import {
|
|
2630
2630
|
captureFrameToBuffer as captureFrameToBuffer2,
|
|
@@ -4356,16 +4356,25 @@ function createSegmentQueue(slices) {
|
|
|
4356
4356
|
// src/services/render/segmentManifest.ts
|
|
4357
4357
|
import { createHash as createHash2, createHmac, timingSafeEqual } from "node:crypto";
|
|
4358
4358
|
import {
|
|
4359
|
+
closeSync as closeSync4,
|
|
4360
|
+
constants as constants3,
|
|
4359
4361
|
createReadStream as createReadStream2,
|
|
4360
|
-
|
|
4362
|
+
fstatSync as fstatSync3,
|
|
4361
4363
|
lstatSync as lstatSync3,
|
|
4362
4364
|
mkdirSync as mkdirSync3,
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
+
openSync as openSync4,
|
|
4366
|
+
readFileSync as readFileSync4
|
|
4365
4367
|
} from "node:fs";
|
|
4366
4368
|
import { join as join10 } from "node:path";
|
|
4369
|
+
import {
|
|
4370
|
+
assertPrivateCachePath,
|
|
4371
|
+
ensurePrivateCacheDir,
|
|
4372
|
+
hyperframesCacheDir
|
|
4373
|
+
} from "@hyperframes/core/cache-dir";
|
|
4374
|
+
import { isSafePath as isSafePath2, realpath } from "@hyperframes/core/safe-path";
|
|
4375
|
+
import { isPathInside as isPathInside3 } from "@hyperframes/parsers/asset-paths";
|
|
4367
4376
|
import { previewToken } from "@hyperframes/core/preview-proof";
|
|
4368
|
-
import {
|
|
4377
|
+
import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
|
|
4369
4378
|
var MANIFEST_FILENAME = "segments.json";
|
|
4370
4379
|
function computeSegmentPlanHash(input) {
|
|
4371
4380
|
const ordered = [
|
|
@@ -4391,8 +4400,20 @@ function computeSegmentPlanHash(input) {
|
|
|
4391
4400
|
if (delivery.some((v) => v !== "")) ordered.push(...delivery.map(String));
|
|
4392
4401
|
return createHash2("sha256").update(ordered.join(" ")).digest("hex").slice(0, 16);
|
|
4393
4402
|
}
|
|
4394
|
-
function segmentDirFor(
|
|
4395
|
-
|
|
4403
|
+
function segmentDirFor(projectDir, planHash) {
|
|
4404
|
+
const root = hyperframesCacheDir();
|
|
4405
|
+
const projectKey = createHash2("sha256").update(realpath(projectDir)).digest("hex");
|
|
4406
|
+
const parent = join10(root, "segments", projectKey);
|
|
4407
|
+
const dir = join10(parent, planHash);
|
|
4408
|
+
if (isPathInside3(root, projectDir) || isSafePath2(projectDir, root) || isSafePath2(projectDir, parent) || isSafePath2(projectDir, dir)) {
|
|
4409
|
+
throw new Error("Segmented capture requires HYPERFRAMES_CACHE_DIR outside the project.");
|
|
4410
|
+
}
|
|
4411
|
+
assertPrivateCachePath(root, root);
|
|
4412
|
+
ensurePrivateCacheDir(parent, root);
|
|
4413
|
+
if (!isSafePath2(parent, dir) || lstatSync3(dir, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
4414
|
+
throw new Error("Invalid segment cache directory");
|
|
4415
|
+
}
|
|
4416
|
+
return dir;
|
|
4396
4417
|
}
|
|
4397
4418
|
function hasNumber(value, key) {
|
|
4398
4419
|
return key in value && typeof Reflect.get(value, key) === "number";
|
|
@@ -4411,12 +4432,22 @@ function isManifest(value) {
|
|
|
4411
4432
|
}
|
|
4412
4433
|
function readSegmentManifest(segmentDir) {
|
|
4413
4434
|
const path = join10(segmentDir, MANIFEST_FILENAME);
|
|
4414
|
-
|
|
4435
|
+
let fd;
|
|
4415
4436
|
try {
|
|
4416
|
-
|
|
4437
|
+
fd = openSync4(
|
|
4438
|
+
path,
|
|
4439
|
+
constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0)
|
|
4440
|
+
);
|
|
4441
|
+
const opened = fstatSync3(fd);
|
|
4442
|
+
if (!opened.isFile() || opened.nlink !== 1) return null;
|
|
4443
|
+
const named = lstatSync3(path);
|
|
4444
|
+
if (!named.isFile() || named.dev !== opened.dev || named.ino !== opened.ino) return null;
|
|
4445
|
+
const parsed = JSON.parse(readFileSync4(fd, "utf-8"));
|
|
4417
4446
|
return isManifest(parsed) ? parsed : null;
|
|
4418
4447
|
} catch {
|
|
4419
4448
|
return null;
|
|
4449
|
+
} finally {
|
|
4450
|
+
if (fd !== void 0) closeSync4(fd);
|
|
4420
4451
|
}
|
|
4421
4452
|
}
|
|
4422
4453
|
function segmentManifestKey(token = previewToken()) {
|
|
@@ -4449,9 +4480,11 @@ async function hashSegmentFile(path) {
|
|
|
4449
4480
|
}
|
|
4450
4481
|
function writeSegmentManifest(segmentDir, manifest, key) {
|
|
4451
4482
|
mkdirSync3(segmentDir, { recursive: true });
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4483
|
+
replaceFileAtomically(
|
|
4484
|
+
join10(segmentDir, MANIFEST_FILENAME),
|
|
4485
|
+
JSON.stringify(signSegmentManifest(manifest, key), null, 2),
|
|
4486
|
+
384
|
|
4487
|
+
);
|
|
4455
4488
|
}
|
|
4456
4489
|
async function probeSegmentFrameCount(path, probe) {
|
|
4457
4490
|
try {
|
|
@@ -4471,19 +4504,27 @@ function plannedSlice(entry, plan) {
|
|
|
4471
4504
|
}
|
|
4472
4505
|
return slice;
|
|
4473
4506
|
}
|
|
4474
|
-
function
|
|
4475
|
-
|
|
4476
|
-
|
|
4507
|
+
async function matchesSegmentFile(path, entry) {
|
|
4508
|
+
try {
|
|
4509
|
+
const stat = lstatSync3(path, { throwIfNoEntry: false });
|
|
4510
|
+
if (!stat?.isFile() || stat.nlink !== 1 || stat.size <= 0 || stat.size !== entry.bytes) {
|
|
4511
|
+
return false;
|
|
4512
|
+
}
|
|
4513
|
+
return await hashSegmentFile(path) === entry.sha256;
|
|
4514
|
+
} catch {
|
|
4515
|
+
return false;
|
|
4516
|
+
}
|
|
4477
4517
|
}
|
|
4478
4518
|
async function validateCompletedSegments(manifest, check) {
|
|
4479
4519
|
const ok = /* @__PURE__ */ new Set();
|
|
4480
|
-
if (manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key))
|
|
4520
|
+
if (manifest.totalFrames !== check.totalFrames || manifest.segmentFrames !== check.segmentFrames || manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key))
|
|
4521
|
+
return ok;
|
|
4522
|
+
const plan = planSegments(check.totalFrames, check.segmentFrames);
|
|
4481
4523
|
for (const entry of manifest.completed) {
|
|
4482
|
-
const slice = plannedSlice(entry,
|
|
4524
|
+
const slice = plannedSlice(entry, plan);
|
|
4483
4525
|
if (!slice) continue;
|
|
4484
4526
|
const path = segmentOutputPath(check.segmentDir, slice.index);
|
|
4485
|
-
if (!
|
|
4486
|
-
if (await hashSegmentFile(path) !== entry.sha256) continue;
|
|
4527
|
+
if (entry.path !== path || !await matchesSegmentFile(path, entry)) continue;
|
|
4487
4528
|
const frames = await check.probeFrames(path);
|
|
4488
4529
|
if (frames !== slice.endFrame - slice.startFrame) continue;
|
|
4489
4530
|
ok.add(slice.index);
|
|
@@ -5374,6 +5415,7 @@ async function captureSegment(ctx, segment) {
|
|
|
5374
5415
|
}
|
|
5375
5416
|
async function captureSegmentToEncoder(ctx, segment) {
|
|
5376
5417
|
const segmentPath = segmentOutputPath(ctx.segmentDir, segment.index);
|
|
5418
|
+
rmSync6(segmentPath, { force: true });
|
|
5377
5419
|
let encoder;
|
|
5378
5420
|
try {
|
|
5379
5421
|
encoder = await ctx.spawnEncoder(
|
|
@@ -5402,8 +5444,8 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
5402
5444
|
path: segmentPath,
|
|
5403
5445
|
// Recorded so resume can prove the file on disk is the one that
|
|
5404
5446
|
// finished; absent only in unit tests, whose fake encoder writes none.
|
|
5405
|
-
bytes:
|
|
5406
|
-
sha256:
|
|
5447
|
+
bytes: existsSync7(segmentPath) ? statSync4(segmentPath).size : 0,
|
|
5448
|
+
sha256: existsSync7(segmentPath) ? await hashSegmentFile(segmentPath) : ""
|
|
5407
5449
|
});
|
|
5408
5450
|
return encodeResult;
|
|
5409
5451
|
} finally {
|
|
@@ -7066,7 +7108,7 @@ function countAuthoredTimedClips(html) {
|
|
|
7066
7108
|
}
|
|
7067
7109
|
|
|
7068
7110
|
// src/services/render/stages/compileStage.ts
|
|
7069
|
-
import { existsSync as
|
|
7111
|
+
import { existsSync as existsSync12, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7070
7112
|
import { join as join22, relative as relative4 } from "node:path";
|
|
7071
7113
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
7072
7114
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
@@ -7078,7 +7120,7 @@ import { statSync as statSync6 } from "node:fs";
|
|
|
7078
7120
|
var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
|
|
7079
7121
|
var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
|
|
7080
7122
|
var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
7081
|
-
var MAX_EXPANDED_COMPOSITION_BYTES =
|
|
7123
|
+
var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
|
|
7082
7124
|
var MAX_COMPOSITION_MOUNTS = 1e4;
|
|
7083
7125
|
var CompositionTooLargeError = class extends Error {
|
|
7084
7126
|
constructor(message, publicMetadata) {
|
|
@@ -7175,12 +7217,12 @@ import {
|
|
|
7175
7217
|
stylesheetLinkMatches
|
|
7176
7218
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7177
7219
|
import { createHash as createHash6 } from "node:crypto";
|
|
7178
|
-
import { createReadStream as createReadStream3, existsSync as
|
|
7220
|
+
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
7179
7221
|
import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7180
7222
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7181
7223
|
|
|
7182
7224
|
// src/services/bundledScripts.ts
|
|
7183
|
-
import { existsSync as
|
|
7225
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
|
|
7184
7226
|
import { join as join17 } from "node:path";
|
|
7185
7227
|
import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
|
|
7186
7228
|
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
@@ -7188,7 +7230,7 @@ function bundledScript(url) {
|
|
|
7188
7230
|
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
7189
7231
|
if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
|
|
7190
7232
|
const file = join17(dir, "gsap.min.js");
|
|
7191
|
-
return
|
|
7233
|
+
return existsSync8(file) ? readFileSync5(file) : null;
|
|
7192
7234
|
}
|
|
7193
7235
|
|
|
7194
7236
|
// src/services/htmlCompiler.ts
|
|
@@ -7227,6 +7269,7 @@ import {
|
|
|
7227
7269
|
isJavaScriptType,
|
|
7228
7270
|
prepareFlattenedInnerRoot,
|
|
7229
7271
|
emitRootCompositionVariableStyles,
|
|
7272
|
+
dropAuthoredSvgReferenceAliases,
|
|
7230
7273
|
readDeclaredDefaults,
|
|
7231
7274
|
parseHostVariableValues,
|
|
7232
7275
|
boundMediaSrc,
|
|
@@ -7446,7 +7489,7 @@ import {
|
|
|
7446
7489
|
|
|
7447
7490
|
// src/services/animatedGifPrep.ts
|
|
7448
7491
|
import { createHash as createHash4 } from "node:crypto";
|
|
7449
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
7492
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
|
|
7450
7493
|
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7451
7494
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7452
7495
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
@@ -7454,7 +7497,7 @@ import {
|
|
|
7454
7497
|
DEFAULT_VP9_CPU_USED,
|
|
7455
7498
|
isPrivateUnderAssetRoots,
|
|
7456
7499
|
runFfmpeg as runFfmpeg2,
|
|
7457
|
-
renameWithRetry as
|
|
7500
|
+
renameWithRetry as renameWithRetry2,
|
|
7458
7501
|
urlInputArgs as urlInputArgs2
|
|
7459
7502
|
} from "@hyperframes/engine";
|
|
7460
7503
|
import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
|
|
@@ -7492,7 +7535,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7492
7535
|
const { basePath } = splitUrlSuffix(trimmed);
|
|
7493
7536
|
const normalizedBase = normalizeRelPath(basePath);
|
|
7494
7537
|
const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
|
|
7495
|
-
if (mapped &&
|
|
7538
|
+
if (mapped && existsSync9(mapped)) return mapped;
|
|
7496
7539
|
if (isHttpUrl(trimmed)) return null;
|
|
7497
7540
|
const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
|
|
7498
7541
|
const candidates = [
|
|
@@ -7501,7 +7544,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7501
7544
|
];
|
|
7502
7545
|
const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
|
|
7503
7546
|
const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
|
|
7504
|
-
return candidates.find((candidate) => allowed(candidate) &&
|
|
7547
|
+
return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
|
|
7505
7548
|
}
|
|
7506
7549
|
function isUsableFile(path) {
|
|
7507
7550
|
try {
|
|
@@ -7613,10 +7656,10 @@ async function runAnimatedGifTranscode(request) {
|
|
|
7613
7656
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
7614
7657
|
}
|
|
7615
7658
|
async function ensurePreparedWebm(input) {
|
|
7616
|
-
if (!
|
|
7659
|
+
if (!existsSync9(dirname6(input.cachePath))) {
|
|
7617
7660
|
mkdirSync7(dirname6(input.cachePath), { recursive: true });
|
|
7618
7661
|
}
|
|
7619
|
-
if (!
|
|
7662
|
+
if (!existsSync9(dirname6(input.outputPath))) {
|
|
7620
7663
|
mkdirSync7(dirname6(input.outputPath), { recursive: true });
|
|
7621
7664
|
}
|
|
7622
7665
|
if (!isUsableFile(input.cachePath)) {
|
|
@@ -7639,7 +7682,7 @@ async function ensurePreparedWebm(input) {
|
|
|
7639
7682
|
throw new Error("Animated GIF transcode produced an empty output");
|
|
7640
7683
|
}
|
|
7641
7684
|
if (!isUsableFile(input.cachePath)) {
|
|
7642
|
-
|
|
7685
|
+
renameWithRetry2(tmpPath, input.cachePath);
|
|
7643
7686
|
} else {
|
|
7644
7687
|
rmSync9(tmpPath, { force: true });
|
|
7645
7688
|
}
|
|
@@ -7763,19 +7806,19 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7763
7806
|
// src/services/heifImagePrep.ts
|
|
7764
7807
|
import { createHash as createHash5 } from "node:crypto";
|
|
7765
7808
|
import {
|
|
7766
|
-
closeSync as
|
|
7809
|
+
closeSync as closeSync5,
|
|
7767
7810
|
copyFileSync as copyFileSync3,
|
|
7768
7811
|
mkdirSync as mkdirSync8,
|
|
7769
|
-
openSync as
|
|
7812
|
+
openSync as openSync5,
|
|
7770
7813
|
readFileSync as readFileSync7,
|
|
7771
7814
|
readSync as readSync3,
|
|
7772
7815
|
rmSync as rmSync10,
|
|
7773
7816
|
statSync as statSync8,
|
|
7774
|
-
writeFileSync as
|
|
7817
|
+
writeFileSync as writeFileSync3
|
|
7775
7818
|
} from "node:fs";
|
|
7776
7819
|
import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
|
|
7777
7820
|
import { parseHTML as parseHTML4 } from "linkedom";
|
|
7778
|
-
import { renameWithRetry as
|
|
7821
|
+
import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
|
|
7779
7822
|
|
|
7780
7823
|
// src/services/heifRotation.ts
|
|
7781
7824
|
function* boxes(buf, start, end) {
|
|
@@ -7922,13 +7965,13 @@ function isHeifBytes(head) {
|
|
|
7922
7965
|
function readHead(path) {
|
|
7923
7966
|
let fd;
|
|
7924
7967
|
try {
|
|
7925
|
-
fd =
|
|
7968
|
+
fd = openSync5(path, "r");
|
|
7926
7969
|
const buf = Buffer.alloc(4096);
|
|
7927
7970
|
return buf.subarray(0, readSync3(fd, buf, 0, buf.length, 0));
|
|
7928
7971
|
} catch {
|
|
7929
7972
|
return null;
|
|
7930
7973
|
} finally {
|
|
7931
|
-
if (fd !== void 0)
|
|
7974
|
+
if (fd !== void 0) closeSync5(fd);
|
|
7932
7975
|
}
|
|
7933
7976
|
}
|
|
7934
7977
|
async function probeJson(path, withGroups) {
|
|
@@ -8027,14 +8070,14 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
|
8027
8070
|
const inlinePath = `${tmpPath}.heic`;
|
|
8028
8071
|
const inputPath = source.path ?? inlinePath;
|
|
8029
8072
|
try {
|
|
8030
|
-
if (!source.path)
|
|
8073
|
+
if (!source.path) writeFileSync3(inlinePath, source.bytes);
|
|
8031
8074
|
await (options.transcode ?? convertHeifToJpeg)({
|
|
8032
8075
|
inputPath,
|
|
8033
8076
|
outputPath: tmpPath,
|
|
8034
8077
|
timeoutMs: options.timeoutMs
|
|
8035
8078
|
});
|
|
8036
8079
|
if (!isUsableFile2(tmpPath)) throw new Error("conversion produced an empty file");
|
|
8037
|
-
|
|
8080
|
+
renameWithRetry3(tmpPath, cachePath);
|
|
8038
8081
|
} catch (error) {
|
|
8039
8082
|
const reason = error instanceof Error ? error.message : String(error);
|
|
8040
8083
|
throw TOOL_FAILURE_RE.test(reason) ? new HeifToolUnavailableError(source.label, reason) : new HeifImageConversionError(source.label, reason);
|
|
@@ -8095,7 +8138,7 @@ import {
|
|
|
8095
8138
|
import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
|
|
8096
8139
|
|
|
8097
8140
|
// src/services/assetMediaType.ts
|
|
8098
|
-
import { existsSync as
|
|
8141
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
8099
8142
|
import { dirname as dirname8, join as join20 } from "node:path";
|
|
8100
8143
|
import {
|
|
8101
8144
|
fingerprintElementId,
|
|
@@ -8208,7 +8251,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
8208
8251
|
input.projectDir,
|
|
8209
8252
|
input.compiledDir
|
|
8210
8253
|
);
|
|
8211
|
-
if (!
|
|
8254
|
+
if (!existsSync10(resolvedPath)) continue;
|
|
8212
8255
|
byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
|
|
8213
8256
|
}
|
|
8214
8257
|
const mismatches = [];
|
|
@@ -8505,7 +8548,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8505
8548
|
let filePath = src;
|
|
8506
8549
|
if (isHttpUrl(src)) {
|
|
8507
8550
|
const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8508
|
-
if (!
|
|
8551
|
+
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8509
8552
|
try {
|
|
8510
8553
|
filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
|
|
8511
8554
|
onTelemetry: logRemoteDownloadTelemetry
|
|
@@ -8524,7 +8567,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8524
8567
|
return { duration: null, resolvedPath: filePath };
|
|
8525
8568
|
}
|
|
8526
8569
|
}
|
|
8527
|
-
if (!isHttpUrl(filePath) && !
|
|
8570
|
+
if (!isHttpUrl(filePath) && !existsSync11(filePath)) {
|
|
8528
8571
|
return { duration: null, resolvedPath: filePath };
|
|
8529
8572
|
}
|
|
8530
8573
|
const withSrcContext = (error) => {
|
|
@@ -8850,13 +8893,14 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8850
8893
|
const body = document2.querySelector("body");
|
|
8851
8894
|
const hosts = Array.from(document2.querySelectorAll("[data-composition-src]"));
|
|
8852
8895
|
if (!hosts.length) {
|
|
8896
|
+
const dropped = dropAuthoredSvgReferenceAliases(document2);
|
|
8853
8897
|
const emitted = emitRootCompositionVariableStyles(
|
|
8854
8898
|
document2,
|
|
8855
8899
|
{},
|
|
8856
8900
|
variableOverrides,
|
|
8857
8901
|
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
8858
8902
|
);
|
|
8859
|
-
return { html: emitted ? document2.toString() : html, variablesByComp: {} };
|
|
8903
|
+
return { html: emitted || dropped ? document2.toString() : html, variablesByComp: {} };
|
|
8860
8904
|
}
|
|
8861
8905
|
const readOnce = /* @__PURE__ */ new Map();
|
|
8862
8906
|
const readMountHtml = (srcPath) => {
|
|
@@ -9048,18 +9092,31 @@ function operatorGsapMirror() {
|
|
|
9048
9092
|
return void 0;
|
|
9049
9093
|
}
|
|
9050
9094
|
}
|
|
9051
|
-
async function downloadScript(src, mirror) {
|
|
9095
|
+
async function downloadScript(src, mirror, signal) {
|
|
9052
9096
|
if (mirror && new URL(src).href.startsWith(mirror)) {
|
|
9053
|
-
const response = await fetch(src, {
|
|
9097
|
+
const response = await fetch(src, {
|
|
9098
|
+
redirect: "error",
|
|
9099
|
+
signal: AbortSignal.any([AbortSignal.timeout(15e3), signal])
|
|
9100
|
+
});
|
|
9054
9101
|
if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
|
|
9055
9102
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
9056
9103
|
if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
|
|
9057
9104
|
return bytes;
|
|
9058
9105
|
}
|
|
9059
|
-
return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
|
|
9106
|
+
return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3, signal });
|
|
9060
9107
|
}
|
|
9061
9108
|
var MAX_CONCURRENT_SCRIPT_FETCHES = 4;
|
|
9062
|
-
|
|
9109
|
+
var MAX_REMOTE_FETCHES = 32;
|
|
9110
|
+
var REMOTE_FETCH_DEADLINE_MS = 6e4;
|
|
9111
|
+
var fetchSignalOf = (signal) => typeof signal === "function" ? signal() : signal;
|
|
9112
|
+
function assertRemoteFetchCount(kind, count) {
|
|
9113
|
+
if (count > MAX_REMOTE_FETCHES) {
|
|
9114
|
+
throw new Error(
|
|
9115
|
+
`The composition links ${count} remote ${kind}; at most ${MAX_REMOTE_FETCHES} are downloaded at compile time`
|
|
9116
|
+
);
|
|
9117
|
+
}
|
|
9118
|
+
}
|
|
9119
|
+
async function inlineExternalScripts(html, budget = new CompositionExpansionBudget(), signal) {
|
|
9063
9120
|
const fullHtml = ensureFullDocument(html);
|
|
9064
9121
|
const wrappedFragment = fullHtml !== html;
|
|
9065
9122
|
const { document: document2 } = parseHTML5(fullHtml);
|
|
@@ -9072,9 +9129,19 @@ async function inlineExternalScripts(html, budget = new CompositionExpansionBudg
|
|
|
9072
9129
|
}
|
|
9073
9130
|
}
|
|
9074
9131
|
if (externalScripts.length === 0) return html;
|
|
9132
|
+
const bundled = /* @__PURE__ */ new Map();
|
|
9133
|
+
const local = externalScripts.map(({ el, src }) => {
|
|
9134
|
+
if (!bundled.has(src)) bundled.set(src, bundledScript(src));
|
|
9135
|
+
const bytes = bundled.get(src);
|
|
9136
|
+
return bytes && matchesScriptIntegrity(bytes, el.getAttribute("integrity") || "") ? bytes : null;
|
|
9137
|
+
});
|
|
9138
|
+
const remote = new Set(externalScripts.filter((_, i) => !local[i]).map(({ src }) => src));
|
|
9139
|
+
assertRemoteFetchCount("scripts", remote.size);
|
|
9075
9140
|
const mirror = operatorGsapMirror();
|
|
9076
9141
|
const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
|
|
9077
9142
|
const stop = new AbortController();
|
|
9143
|
+
const shared = remote.size > 0 ? fetchSignalOf(signal) : void 0;
|
|
9144
|
+
const fetchSignal = shared ? AbortSignal.any([stop.signal, shared]) : stop.signal;
|
|
9078
9145
|
const fail = (error) => {
|
|
9079
9146
|
stop.abort(error);
|
|
9080
9147
|
throw error;
|
|
@@ -9091,21 +9158,21 @@ async function inlineExternalScripts(html, budget = new CompositionExpansionBudg
|
|
|
9091
9158
|
let bytes = fetches.get(src);
|
|
9092
9159
|
if (!bytes) {
|
|
9093
9160
|
bytes = limit(async () => {
|
|
9094
|
-
|
|
9095
|
-
const downloaded = await downloadScript(src, mirror);
|
|
9161
|
+
fetchSignal.throwIfAborted();
|
|
9162
|
+
const downloaded = await downloadScript(src, mirror, fetchSignal);
|
|
9096
9163
|
charge(downloaded.byteLength);
|
|
9097
9164
|
return downloaded;
|
|
9098
|
-
},
|
|
9165
|
+
}, fetchSignal);
|
|
9099
9166
|
fetches.set(src, bytes);
|
|
9100
9167
|
}
|
|
9101
9168
|
return bytes;
|
|
9102
9169
|
};
|
|
9103
9170
|
const placed = /* @__PURE__ */ new Set();
|
|
9104
9171
|
const downloads = await Promise.allSettled(
|
|
9105
|
-
externalScripts.map(async ({ el, src }) => {
|
|
9172
|
+
externalScripts.map(async ({ el, src }, i) => {
|
|
9106
9173
|
const integrity = el.getAttribute("integrity") || "";
|
|
9107
|
-
let bytes =
|
|
9108
|
-
if (bytes
|
|
9174
|
+
let bytes = local[i];
|
|
9175
|
+
if (bytes) {
|
|
9109
9176
|
charge(bytes.byteLength);
|
|
9110
9177
|
} else {
|
|
9111
9178
|
bytes = await fetchOnce(src);
|
|
@@ -9156,7 +9223,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
9156
9223
|
return null;
|
|
9157
9224
|
}
|
|
9158
9225
|
const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
|
|
9159
|
-
if (!onShare && !
|
|
9226
|
+
if (!onShare && !existsSync11(absPath)) return null;
|
|
9160
9227
|
const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
|
|
9161
9228
|
if (refusal) {
|
|
9162
9229
|
if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
|
|
@@ -9209,7 +9276,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
9209
9276
|
var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
9210
9277
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
9211
9278
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
9212
|
-
if (!
|
|
9279
|
+
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
9213
9280
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
9214
9281
|
await Promise.all(
|
|
9215
9282
|
[...urlSet].map(async (url) => {
|
|
@@ -9302,12 +9369,13 @@ function isGoogleFontsUrl(href) {
|
|
|
9302
9369
|
}
|
|
9303
9370
|
}
|
|
9304
9371
|
var MAX_STYLESHEET_BYTES = 2 * 1024 * 1024;
|
|
9305
|
-
async function fetchExternalStylesheetCss(href) {
|
|
9372
|
+
async function fetchExternalStylesheetCss(href, signal) {
|
|
9306
9373
|
const identity = safeDownloadUrlIdentity(href);
|
|
9307
9374
|
try {
|
|
9308
9375
|
return await fetchPublicHttpsText(href, {
|
|
9309
9376
|
maxBytes: MAX_STYLESHEET_BYTES,
|
|
9310
|
-
timeoutMs: 15e3
|
|
9377
|
+
timeoutMs: 15e3,
|
|
9378
|
+
signal
|
|
9311
9379
|
});
|
|
9312
9380
|
} catch (err) {
|
|
9313
9381
|
defaultLogger.warn("[Compiler] External stylesheet fetch failed, preserving link tag.", {
|
|
@@ -9347,36 +9415,42 @@ function remoteFontStylesheetHref(tag) {
|
|
|
9347
9415
|
if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
|
|
9348
9416
|
return href;
|
|
9349
9417
|
}
|
|
9350
|
-
async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget()) {
|
|
9418
|
+
async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget(), signal) {
|
|
9351
9419
|
const hrefs = /* @__PURE__ */ new Set();
|
|
9352
9420
|
for (const { parts } of stylesheetLinkMatches(html)) {
|
|
9353
9421
|
const href = remoteFontStylesheetHref(parts[0]);
|
|
9354
9422
|
if (href) hrefs.add(href);
|
|
9355
9423
|
}
|
|
9356
9424
|
if (hrefs.size === 0) return html;
|
|
9357
|
-
|
|
9425
|
+
assertRemoteFetchCount("stylesheets", hrefs.size);
|
|
9426
|
+
const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
|
|
9427
|
+
const stop = new AbortController();
|
|
9428
|
+
const shared = fetchSignalOf(signal);
|
|
9429
|
+
const fetchSignal = shared ? AbortSignal.any([stop.signal, shared]) : stop.signal;
|
|
9358
9430
|
const inlineByHref = /* @__PURE__ */ new Map();
|
|
9359
|
-
const
|
|
9360
|
-
|
|
9361
|
-
const
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
const css = sheets[index];
|
|
9365
|
-
const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
|
|
9366
|
-
if (fontFaceBlocks.length === 0) return;
|
|
9367
|
-
const inlineStyle = `<style>/* Inlined external font stylesheet */
|
|
9431
|
+
const inlineSheet = async (href) => {
|
|
9432
|
+
const css = await fetchExternalStylesheetCss(href, fetchSignal);
|
|
9433
|
+
const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
|
|
9434
|
+
if (fontFaceBlocks.length === 0) return;
|
|
9435
|
+
const inlineStyle = `<style>/* Inlined external font stylesheet */
|
|
9368
9436
|
${fontFaceBlocks.join("\n")}
|
|
9369
9437
|
</style>`;
|
|
9438
|
+
try {
|
|
9370
9439
|
budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9440
|
+
} catch (error) {
|
|
9441
|
+
stop.abort(error);
|
|
9442
|
+
throw error;
|
|
9443
|
+
}
|
|
9444
|
+
inlineByHref.set(href, inlineStyle);
|
|
9445
|
+
const identity = safeDownloadUrlIdentity(href);
|
|
9446
|
+
defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
|
|
9447
|
+
count: fontFaceBlocks.length,
|
|
9448
|
+
urlFingerprint: identity.urlFingerprint,
|
|
9449
|
+
host: identity.host
|
|
9378
9450
|
});
|
|
9379
|
-
}
|
|
9451
|
+
};
|
|
9452
|
+
await Promise.allSettled([...hrefs].map((href) => limit(() => inlineSheet(href), fetchSignal)));
|
|
9453
|
+
if (stop.signal.aborted) throw stop.signal.reason;
|
|
9380
9454
|
const placed = /* @__PURE__ */ new Set();
|
|
9381
9455
|
return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
|
|
9382
9456
|
const href = remoteFontStylesheetHref(tag);
|
|
@@ -9395,13 +9469,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
9395
9469
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
9396
9470
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
9397
9471
|
const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
9398
|
-
if (!isPathInside(sheet, projectDir) || !
|
|
9472
|
+
if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
9399
9473
|
for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
|
|
9400
9474
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
9401
9475
|
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
9402
9476
|
const path = decodedUrlPath(url);
|
|
9403
9477
|
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname9(sheet), path);
|
|
9404
|
-
return isPathInside(file, projectDir) &&
|
|
9478
|
+
return isPathInside(file, projectDir) && existsSync11(file);
|
|
9405
9479
|
});
|
|
9406
9480
|
if (family && shipsFile) families.push(family);
|
|
9407
9481
|
}
|
|
@@ -9550,7 +9624,7 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
|
9550
9624
|
let gsapDist;
|
|
9551
9625
|
const exists = (path) => {
|
|
9552
9626
|
const file = resolve8(projectDir, path);
|
|
9553
|
-
return !namesAnotherNetworkRoot2(projectDir, file) &&
|
|
9627
|
+
return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
|
|
9554
9628
|
};
|
|
9555
9629
|
return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
|
|
9556
9630
|
if (/^https?:\/\//i.test(src)) return full;
|
|
@@ -9686,10 +9760,17 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9686
9760
|
const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
|
|
9687
9761
|
const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
|
|
9688
9762
|
const hasAncestorBackgroundImage = detectAncestorBackgroundImage(sanitizedHtml);
|
|
9763
|
+
let deadline;
|
|
9764
|
+
const remoteFetches = () => deadline ??= AbortSignal.any([
|
|
9765
|
+
AbortSignal.timeout(REMOTE_FETCH_DEADLINE_MS),
|
|
9766
|
+
...options.abortSignal ? [options.abortSignal] : []
|
|
9767
|
+
]);
|
|
9689
9768
|
const fontSheetHtml = await inlineExternalFontStylesheets(
|
|
9690
9769
|
promoteCssImportsToLinkTags(sanitizedHtml),
|
|
9691
|
-
budget
|
|
9770
|
+
budget,
|
|
9771
|
+
remoteFetches
|
|
9692
9772
|
);
|
|
9773
|
+
options.abortSignal?.throwIfAborted();
|
|
9693
9774
|
const normalizedFontHtml = normalizeSystemFontPrimaryFamilies(
|
|
9694
9775
|
injectTextRenderingRule(coalesceHeadStylesAndBodyScripts(fontSheetHtml))
|
|
9695
9776
|
);
|
|
@@ -9700,7 +9781,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9700
9781
|
projectFontFamilies: projectStylesheetFontFamilies(fontSheetHtml, projectDir),
|
|
9701
9782
|
abortSignal: options.abortSignal
|
|
9702
9783
|
});
|
|
9703
|
-
const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
|
|
9784
|
+
const assembledHtml = await inlineExternalScripts(coalescedHtml, budget, remoteFetches);
|
|
9785
|
+
options.abortSignal?.throwIfAborted();
|
|
9704
9786
|
const htmlWithPositionScript = htmlHasStudioPositionEdits(assembledHtml) ? insertBeforeCloseTag(
|
|
9705
9787
|
assembledHtml,
|
|
9706
9788
|
"body",
|
|
@@ -9786,7 +9868,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9786
9868
|
for (const video of videos) {
|
|
9787
9869
|
if (isHttpUrl(video.src)) continue;
|
|
9788
9870
|
const videoPath = resolve8(projectDir, video.src);
|
|
9789
|
-
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !
|
|
9871
|
+
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
|
|
9790
9872
|
continue;
|
|
9791
9873
|
advised.add(videoPath);
|
|
9792
9874
|
const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
|
|
@@ -10233,7 +10315,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10233
10315
|
const rawEntry = readEntry(htmlPath);
|
|
10234
10316
|
if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
|
|
10235
10317
|
const projectIndexPath = join22(projectDir, "index.html");
|
|
10236
|
-
if (!
|
|
10318
|
+
if (!existsSync12(projectIndexPath)) {
|
|
10237
10319
|
throw new Error(
|
|
10238
10320
|
`Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
|
|
10239
10321
|
);
|
|
@@ -10249,7 +10331,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10249
10331
|
);
|
|
10250
10332
|
}
|
|
10251
10333
|
const wrapperPath = join22(workDir, "standalone-entry.html");
|
|
10252
|
-
|
|
10334
|
+
writeFileSync4(wrapperPath, standaloneHtml, "utf-8");
|
|
10253
10335
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
10254
10336
|
return wrapperPath;
|
|
10255
10337
|
}
|
|
@@ -11210,7 +11292,7 @@ function validateRenderDuration(input) {
|
|
|
11210
11292
|
}
|
|
11211
11293
|
|
|
11212
11294
|
// src/services/render/stages/extractVideosStage.ts
|
|
11213
|
-
import { existsSync as
|
|
11295
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
11214
11296
|
import { join as join24 } from "node:path";
|
|
11215
11297
|
import {
|
|
11216
11298
|
classifyVideoExtractionError,
|
|
@@ -11658,7 +11740,7 @@ function isPublicHttpsUrl(url) {
|
|
|
11658
11740
|
}
|
|
11659
11741
|
}
|
|
11660
11742
|
function opensLocally(path, assetRoots) {
|
|
11661
|
-
return
|
|
11743
|
+
return existsSync13(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
|
|
11662
11744
|
}
|
|
11663
11745
|
function localProbeSource(src, input) {
|
|
11664
11746
|
const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
|
|
@@ -11711,7 +11793,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
11711
11793
|
}
|
|
11712
11794
|
|
|
11713
11795
|
// src/services/render/videoLayerPassthroughPlan.ts
|
|
11714
|
-
import { existsSync as
|
|
11796
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
11715
11797
|
import {
|
|
11716
11798
|
buildVideoLayerInput,
|
|
11717
11799
|
isHttpUrl as isHttpUrl4,
|
|
@@ -11779,7 +11861,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
11779
11861
|
const { video } = q;
|
|
11780
11862
|
if (isHttpUrl4(video.src)) return { reason: "remote_source" };
|
|
11781
11863
|
const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
|
|
11782
|
-
if (!
|
|
11864
|
+
if (!existsSync14(path)) return { reason: "source_missing" };
|
|
11783
11865
|
const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
|
|
11784
11866
|
if ("reason" in layout) return layout;
|
|
11785
11867
|
const layer = await buildVideoLayerInput(
|
|
@@ -11794,7 +11876,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
11794
11876
|
}
|
|
11795
11877
|
|
|
11796
11878
|
// src/services/render/stages/audioStage.ts
|
|
11797
|
-
import { existsSync as
|
|
11879
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
11798
11880
|
import { join as join27 } from "node:path";
|
|
11799
11881
|
import {
|
|
11800
11882
|
MIXED_AUDIO_FILENAME,
|
|
@@ -11806,16 +11888,17 @@ import {
|
|
|
11806
11888
|
} from "@hyperframes/engine";
|
|
11807
11889
|
|
|
11808
11890
|
// src/services/render/audioDeliveryLimit.ts
|
|
11809
|
-
import { existsSync as
|
|
11891
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
11810
11892
|
import { dirname as dirname11, join as join26 } from "node:path";
|
|
11811
11893
|
import {
|
|
11812
11894
|
applyAudioFxChain,
|
|
11813
11895
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
11814
11896
|
encodeAac as encodeAac2,
|
|
11815
|
-
renameWithRetry as
|
|
11897
|
+
renameWithRetry as renameWithRetry5
|
|
11816
11898
|
} from "@hyperframes/engine";
|
|
11817
11899
|
|
|
11818
11900
|
// src/services/render/audioPadTrim.ts
|
|
11901
|
+
import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
11819
11902
|
import { spawn } from "node:child_process";
|
|
11820
11903
|
import { dirname as dirname10, join as join25 } from "node:path";
|
|
11821
11904
|
import {
|
|
@@ -11826,7 +11909,7 @@ import {
|
|
|
11826
11909
|
getFfprobeBinary,
|
|
11827
11910
|
ManagedChildProcess,
|
|
11828
11911
|
removeScratch,
|
|
11829
|
-
renameWithRetry as
|
|
11912
|
+
renameWithRetry as renameWithRetry4,
|
|
11830
11913
|
runFfmpeg as runFfmpeg5,
|
|
11831
11914
|
trackChildProcess,
|
|
11832
11915
|
withPublicOnlyProxy
|
|
@@ -11967,10 +12050,10 @@ function sanitizeProbeFailure(reason, paths) {
|
|
|
11967
12050
|
}
|
|
11968
12051
|
async function padOrTrimAudioToVideoFrameCount(input) {
|
|
11969
12052
|
const probeVideo = input.probeVideoFrameInfo ?? ((videoPath) => defaultProbeVideoFrameInfo(videoPath, input.signal));
|
|
11970
|
-
const probeAudio = input.probeAudioInfo ?? defaultProbeAudioInfo;
|
|
12053
|
+
const probeAudio = input.probeAudioInfo ?? ((path, signal) => defaultProbeAudioInfo(path, signal, input.audioContainer));
|
|
11971
12054
|
const timeoutMs = input.timeoutMs ?? DEFAULT_CONFIG.ffmpegProcessTimeout;
|
|
11972
12055
|
const runner = input.runFfmpeg ?? ((args) => defaultRunFfmpeg(args, timeoutMs, input.signal));
|
|
11973
|
-
const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath);
|
|
12056
|
+
const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath, input.audioContainer);
|
|
11974
12057
|
const probeTruePeak = input.probeAudioTruePeakDbfs ?? (input.runFfmpeg || input.encodeAac ? void 0 : (audioPath, signal) => measureTruePeakDbfs(audioPath, { timeoutMs, signal }));
|
|
11975
12058
|
const [videoResult, audioResult] = await Promise.allSettled([
|
|
11976
12059
|
probeVideo(input.videoPath),
|
|
@@ -12018,7 +12101,7 @@ async function padOrTrimAudioToVideoFrameCount(input) {
|
|
|
12018
12101
|
);
|
|
12019
12102
|
try {
|
|
12020
12103
|
for (const step of plan.steps) {
|
|
12021
|
-
const ffmpegResult = step.kind === "copy" ? await runner(step.args) : await encode(
|
|
12104
|
+
const ffmpegResult = step.kind === "copy" ? await runner([...localContainerInputArgs(input.audioContainer), ...step.args]) : await encode(
|
|
12022
12105
|
input.sourcePath ?? input.audioPath,
|
|
12023
12106
|
input.outputPath,
|
|
12024
12107
|
targetDurationSeconds,
|
|
@@ -12102,7 +12185,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
|
|
|
12102
12185
|
try {
|
|
12103
12186
|
const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
|
|
12104
12187
|
if (!result.success) throw new Error(result.error);
|
|
12105
|
-
|
|
12188
|
+
renameWithRetry4(cutPath, input.sourcePath, { copyFallback: true });
|
|
12106
12189
|
return true;
|
|
12107
12190
|
} catch {
|
|
12108
12191
|
removeScratch(input.sourcePath);
|
|
@@ -12129,7 +12212,7 @@ async function enforceAacTruePeak(input) {
|
|
|
12129
12212
|
if (truePeakDbfs <= AAC_DELIVERY_TRUE_PEAK_DBFS) {
|
|
12130
12213
|
if (measuredPath !== correctedPath) return { success: true };
|
|
12131
12214
|
const sourceCut = await cutSource(input, scratchDir, attenuationDb);
|
|
12132
|
-
|
|
12215
|
+
renameWithRetry4(correctedPath, input.audioPath, { copyFallback: true });
|
|
12133
12216
|
const loweredDb = Number((-attenuationDb).toFixed(2));
|
|
12134
12217
|
return sourceCut ? { success: true, loweredDb } : { success: true, loweredDb, sourceStale: true };
|
|
12135
12218
|
}
|
|
@@ -12184,7 +12267,8 @@ function failResult(outputPath, target, source, error) {
|
|
|
12184
12267
|
error
|
|
12185
12268
|
};
|
|
12186
12269
|
}
|
|
12187
|
-
async function defaultProbeVideoFrameInfo(videoPath, signal) {
|
|
12270
|
+
async function defaultProbeVideoFrameInfo(videoPath, signal, container) {
|
|
12271
|
+
const inputArgs = localContainerInputArgs(container);
|
|
12188
12272
|
const fastInfo = await runFfprobeJson(
|
|
12189
12273
|
[
|
|
12190
12274
|
"-v",
|
|
@@ -12195,6 +12279,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
|
|
|
12195
12279
|
"stream=nb_frames,r_frame_rate",
|
|
12196
12280
|
"-of",
|
|
12197
12281
|
"json",
|
|
12282
|
+
...inputArgs,
|
|
12198
12283
|
"--",
|
|
12199
12284
|
videoPath
|
|
12200
12285
|
],
|
|
@@ -12216,6 +12301,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
|
|
|
12216
12301
|
"stream=nb_read_packets,r_frame_rate",
|
|
12217
12302
|
"-of",
|
|
12218
12303
|
"json",
|
|
12304
|
+
...inputArgs,
|
|
12219
12305
|
"--",
|
|
12220
12306
|
videoPath
|
|
12221
12307
|
],
|
|
@@ -12238,8 +12324,8 @@ function parseFrameRate(rate) {
|
|
|
12238
12324
|
}
|
|
12239
12325
|
return { fpsNum, fpsDen };
|
|
12240
12326
|
}
|
|
12241
|
-
async function defaultProbeAudioInfo(audioPath, signal) {
|
|
12242
|
-
const metadata = await extractAudioMetadata3(audioPath, { signal });
|
|
12327
|
+
async function defaultProbeAudioInfo(audioPath, signal, inputContainer) {
|
|
12328
|
+
const metadata = await extractAudioMetadata3(audioPath, { signal, inputContainer });
|
|
12243
12329
|
return {
|
|
12244
12330
|
durationSeconds: metadata.durationSeconds,
|
|
12245
12331
|
sampleRate: metadata.sampleRate,
|
|
@@ -12250,9 +12336,9 @@ async function defaultProbeAudioInfo(audioPath, signal) {
|
|
|
12250
12336
|
async function defaultRunFfmpeg(args, timeoutMs, signal) {
|
|
12251
12337
|
return toStepResult(await runFfmpeg5(args, { signal, timeout: timeoutMs }), timeoutMs);
|
|
12252
12338
|
}
|
|
12253
|
-
function defaultAacEncoder(timeoutMs, signal, pcmSourcePath) {
|
|
12339
|
+
function defaultAacEncoder(timeoutMs, signal, pcmSourcePath, inputContainer) {
|
|
12254
12340
|
return async (inputPath, outputPath, durationSeconds, filter) => {
|
|
12255
|
-
const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1 };
|
|
12341
|
+
const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1, inputContainer };
|
|
12256
12342
|
return toStepResult(
|
|
12257
12343
|
await encodeAac(pcmSourcePath ?? inputPath, outputPath, durationSeconds, options),
|
|
12258
12344
|
timeoutMs
|
|
@@ -12325,8 +12411,8 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
12325
12411
|
measure: measureTruePeakDbfs,
|
|
12326
12412
|
applyChain: applyAudioFxChain,
|
|
12327
12413
|
encode: encodeAac2,
|
|
12328
|
-
rename:
|
|
12329
|
-
sourceExists:
|
|
12414
|
+
rename: renameWithRetry5,
|
|
12415
|
+
sourceExists: existsSync15
|
|
12330
12416
|
}) {
|
|
12331
12417
|
const { audioPath, sourcePath, signal, timeoutMs } = input;
|
|
12332
12418
|
if (!deps.sourceExists(sourcePath)) return { success: true };
|
|
@@ -12422,7 +12508,7 @@ async function runAudioStageScoped(input) {
|
|
|
12422
12508
|
);
|
|
12423
12509
|
audioLoweredDb = guard.loweredDb;
|
|
12424
12510
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
12425
|
-
if (input.keepDeliverySource && !guard.sourceStale &&
|
|
12511
|
+
if (input.keepDeliverySource && !guard.sourceStale && existsSync16(pcmSourcePath)) {
|
|
12426
12512
|
deliverySourcePath = pcmSourcePath;
|
|
12427
12513
|
}
|
|
12428
12514
|
}
|
|
@@ -12551,7 +12637,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
12551
12637
|
}
|
|
12552
12638
|
|
|
12553
12639
|
// src/services/render/stages/captureStage.ts
|
|
12554
|
-
import { existsSync as
|
|
12640
|
+
import { existsSync as existsSync17, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
12555
12641
|
import { join as join28 } from "node:path";
|
|
12556
12642
|
import {
|
|
12557
12643
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
@@ -12622,7 +12708,7 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
|
|
|
12622
12708
|
}
|
|
12623
12709
|
function measureCaptureFrameBytes(workDir, framesDir) {
|
|
12624
12710
|
let total = sampleDirectoryBytes(framesDir);
|
|
12625
|
-
if (!
|
|
12711
|
+
if (!existsSync17(workDir)) return total;
|
|
12626
12712
|
for (const attempt of readdirSync4(workDir)) {
|
|
12627
12713
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
12628
12714
|
total += sampleDirectoryBytes(join28(workDir, attempt));
|
|
@@ -12929,7 +13015,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
12929
13015
|
}
|
|
12930
13016
|
|
|
12931
13017
|
// src/services/render/stages/captureHdrStage.ts
|
|
12932
|
-
import { existsSync as
|
|
13018
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync10 } from "node:fs";
|
|
12933
13019
|
import { join as join32 } from "node:path";
|
|
12934
13020
|
import {
|
|
12935
13021
|
closeCaptureSession as closeCaptureSession7,
|
|
@@ -13176,7 +13262,7 @@ import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
|
13176
13262
|
import { dirname as dirname12, join as join30 } from "node:path";
|
|
13177
13263
|
import { createRequire } from "node:module";
|
|
13178
13264
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
13179
|
-
import { existsSync as
|
|
13265
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
13180
13266
|
function resolveWorkerEntry(explicit) {
|
|
13181
13267
|
if (explicit && explicit.length > 0) {
|
|
13182
13268
|
return { path: explicit, isTs: explicit.endsWith(".ts") };
|
|
@@ -13188,7 +13274,7 @@ function resolveWorkerEntry(explicit) {
|
|
|
13188
13274
|
}
|
|
13189
13275
|
const moduleDir = dirname12(fileURLToPath3(import.meta.url));
|
|
13190
13276
|
const jsPath = join30(moduleDir, "shaderTransitionWorker.js");
|
|
13191
|
-
if (
|
|
13277
|
+
if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
|
|
13192
13278
|
const tsPath = join30(moduleDir, "shaderTransitionWorker.ts");
|
|
13193
13279
|
return { path: tsPath, isTs: true };
|
|
13194
13280
|
}
|
|
@@ -13754,7 +13840,7 @@ async function runCaptureHdrStage(input) {
|
|
|
13754
13840
|
}
|
|
13755
13841
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
13756
13842
|
const debugDumpDir = debugDumpEnabled ? join32(framesDir, "debug-composite") : null;
|
|
13757
|
-
if (debugDumpDir && !
|
|
13843
|
+
if (debugDumpDir && !existsSync19(debugDumpDir)) {
|
|
13758
13844
|
mkdirSync10(debugDumpDir, { recursive: true });
|
|
13759
13845
|
}
|
|
13760
13846
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
@@ -13913,13 +13999,13 @@ async function runCaptureHdrStage(input) {
|
|
|
13913
13999
|
// src/services/render/stages/encodeStage.ts
|
|
13914
14000
|
import {
|
|
13915
14001
|
copyFileSync as copyFileSync4,
|
|
13916
|
-
existsSync as
|
|
14002
|
+
existsSync as existsSync20,
|
|
13917
14003
|
mkdirSync as mkdirSync11,
|
|
13918
14004
|
readdirSync as readdirSync5,
|
|
13919
14005
|
readFileSync as readFileSync9,
|
|
13920
14006
|
rmSync as rmSync11,
|
|
13921
14007
|
statSync as statSync9,
|
|
13922
|
-
writeFileSync as
|
|
14008
|
+
writeFileSync as writeFileSync5
|
|
13923
14009
|
} from "node:fs";
|
|
13924
14010
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
13925
14011
|
import { dirname as dirname13, join as join33 } from "node:path";
|
|
@@ -14015,7 +14101,7 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
|
|
|
14015
14101
|
const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
|
|
14016
14102
|
return gifEncodeFailure(startTime, outputPath, error);
|
|
14017
14103
|
}
|
|
14018
|
-
|
|
14104
|
+
writeFileSync5(outputPath, gif);
|
|
14019
14105
|
return null;
|
|
14020
14106
|
}
|
|
14021
14107
|
async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
@@ -14047,7 +14133,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
14047
14133
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
14048
14134
|
if (failure) return failure;
|
|
14049
14135
|
}
|
|
14050
|
-
const fileSize =
|
|
14136
|
+
const fileSize = existsSync20(outputPath) ? statSync9(outputPath).size : 0;
|
|
14051
14137
|
return {
|
|
14052
14138
|
success: true,
|
|
14053
14139
|
outputPath,
|
|
@@ -14216,7 +14302,7 @@ async function runEncodeStage(input) {
|
|
|
14216
14302
|
const stage5Start = Date.now();
|
|
14217
14303
|
if (isPngSequence) {
|
|
14218
14304
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
14219
|
-
if (!
|
|
14305
|
+
if (!existsSync20(outputPath)) mkdirSync11(outputPath, { recursive: true });
|
|
14220
14306
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
14221
14307
|
if (captured.length === 0) {
|
|
14222
14308
|
throw new Error(
|
|
@@ -14227,7 +14313,7 @@ async function runEncodeStage(input) {
|
|
|
14227
14313
|
const dst = join33(outputPath, formatExportFrameName(i, "png"));
|
|
14228
14314
|
copyFileSync4(join33(framesDir, name), dst);
|
|
14229
14315
|
});
|
|
14230
|
-
if (hasAudio && audioOutputPath &&
|
|
14316
|
+
if (hasAudio && audioOutputPath && existsSync20(audioOutputPath)) {
|
|
14231
14317
|
copyFileSync4(audioOutputPath, join33(outputPath, MIXED_AUDIO_FILENAME2));
|
|
14232
14318
|
log.info(
|
|
14233
14319
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
@@ -14618,7 +14704,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
14618
14704
|
let rangeStart = null;
|
|
14619
14705
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14620
14706
|
const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
14621
|
-
const missing = !
|
|
14707
|
+
const missing = !existsSync21(framePath) || statSync10(framePath).size <= 8;
|
|
14622
14708
|
if (missing && rangeStart === null) {
|
|
14623
14709
|
rangeStart = frameIndex;
|
|
14624
14710
|
} else if (!missing && rangeStart !== null) {
|
|
@@ -14751,7 +14837,7 @@ function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
|
14751
14837
|
let captured = 0;
|
|
14752
14838
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14753
14839
|
const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
14754
|
-
if (
|
|
14840
|
+
if (existsSync21(framePath)) captured++;
|
|
14755
14841
|
}
|
|
14756
14842
|
return captured;
|
|
14757
14843
|
}
|
|
@@ -15432,7 +15518,7 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
|
|
|
15432
15518
|
validateChromaSubsamplingConfig(job.config);
|
|
15433
15519
|
const debugDir = resolveRenderDebugDir();
|
|
15434
15520
|
const outputDir = dirname14(outputPath);
|
|
15435
|
-
if (!
|
|
15521
|
+
if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
15436
15522
|
const workDir = job.config.debug ? join34(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
15437
15523
|
const pipelineStart = Date.now();
|
|
15438
15524
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
@@ -15589,7 +15675,7 @@ async function executeRenderPipeline(input) {
|
|
|
15589
15675
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
15590
15676
|
assertNotAborted();
|
|
15591
15677
|
assertConfiguredFfmpegBinariesExist();
|
|
15592
|
-
if (!
|
|
15678
|
+
if (!existsSync21(workDir)) mkdirSync12(workDir, { recursive: true });
|
|
15593
15679
|
if (job.config.debug) {
|
|
15594
15680
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
15595
15681
|
}
|
|
@@ -15619,7 +15705,7 @@ async function executeRenderPipeline(input) {
|
|
|
15619
15705
|
});
|
|
15620
15706
|
const entryFile = job.config.entryFile || "index.html";
|
|
15621
15707
|
const htmlPath = join34(projectDir, entryFile);
|
|
15622
|
-
if (!
|
|
15708
|
+
if (!existsSync21(htmlPath)) {
|
|
15623
15709
|
throw new Error(`Entry file not found: ${htmlPath}`);
|
|
15624
15710
|
}
|
|
15625
15711
|
assertNotAborted();
|
|
@@ -15640,6 +15726,7 @@ async function executeRenderPipeline(input) {
|
|
|
15640
15726
|
needsAlpha,
|
|
15641
15727
|
log,
|
|
15642
15728
|
assertNotAborted,
|
|
15729
|
+
abortSignal: executionSignal,
|
|
15643
15730
|
variables: job.config.variables,
|
|
15644
15731
|
pageMotionBlur: job.config.pageMotionBlur
|
|
15645
15732
|
})
|
|
@@ -15987,7 +16074,7 @@ async function executeRenderPipeline(input) {
|
|
|
15987
16074
|
throw new Error("File server failed to initialize before frame capture");
|
|
15988
16075
|
}
|
|
15989
16076
|
const framesDir = join34(workDir, "captured-frames");
|
|
15990
|
-
if (!
|
|
16077
|
+
if (!existsSync21(framesDir)) mkdirSync12(framesDir, { recursive: true });
|
|
15991
16078
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
15992
16079
|
code: "start_browsers"
|
|
15993
16080
|
});
|
|
@@ -16884,29 +16971,8 @@ async function executeRenderPipeline(input) {
|
|
|
16884
16971
|
pageMotionBlur: job.config.pageMotionBlur,
|
|
16885
16972
|
captureQuality: captureOptions.quality
|
|
16886
16973
|
});
|
|
16887
|
-
const segmentDir = segmentDirFor(
|
|
16974
|
+
const segmentDir = segmentDirFor(projectDir, segmentPlanHash);
|
|
16888
16975
|
const manifestKey = loadResumeKeyOrWarn(job.config.resumeSegments === true, log);
|
|
16889
|
-
let completedSegments = /* @__PURE__ */ new Set();
|
|
16890
|
-
if (job.config.resumeSegments === true) {
|
|
16891
|
-
const existing = readSegmentManifest(segmentDir);
|
|
16892
|
-
if (existing) {
|
|
16893
|
-
completedSegments = await validateCompletedSegments(existing, {
|
|
16894
|
-
expectedHash: segmentPlanHash,
|
|
16895
|
-
segmentDir,
|
|
16896
|
-
plan: planSegments(totalFrames, segmentFrames),
|
|
16897
|
-
key: manifestKey,
|
|
16898
|
-
probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
|
|
16899
|
-
});
|
|
16900
|
-
log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
|
|
16901
|
-
segmentDir
|
|
16902
|
-
});
|
|
16903
|
-
}
|
|
16904
|
-
if (completedSegments.size === 0) {
|
|
16905
|
-
rmSync12(segmentDir, { recursive: true, force: true });
|
|
16906
|
-
}
|
|
16907
|
-
} else {
|
|
16908
|
-
rmSync12(segmentDir, { recursive: true, force: true });
|
|
16909
|
-
}
|
|
16910
16976
|
const emptySegmentManifest = () => ({
|
|
16911
16977
|
version: 1,
|
|
16912
16978
|
planHash: segmentPlanHash,
|
|
@@ -16914,7 +16980,26 @@ async function executeRenderPipeline(input) {
|
|
|
16914
16980
|
segmentFrames,
|
|
16915
16981
|
completed: []
|
|
16916
16982
|
});
|
|
16917
|
-
let segmentManifest =
|
|
16983
|
+
let segmentManifest = emptySegmentManifest();
|
|
16984
|
+
let completedSegments = /* @__PURE__ */ new Set();
|
|
16985
|
+
const existing = job.config.resumeSegments ? readSegmentManifest(segmentDir) : null;
|
|
16986
|
+
if (existing) {
|
|
16987
|
+
completedSegments = await validateCompletedSegments(existing, {
|
|
16988
|
+
expectedHash: segmentPlanHash,
|
|
16989
|
+
segmentDir,
|
|
16990
|
+
totalFrames,
|
|
16991
|
+
segmentFrames,
|
|
16992
|
+
key: manifestKey,
|
|
16993
|
+
probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
|
|
16994
|
+
});
|
|
16995
|
+
segmentManifest.completed = existing.completed.filter(
|
|
16996
|
+
(entry) => completedSegments.has(entry.index)
|
|
16997
|
+
);
|
|
16998
|
+
log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
|
|
16999
|
+
segmentDir
|
|
17000
|
+
});
|
|
17001
|
+
}
|
|
17002
|
+
if (completedSegments.size === 0) rmSync12(segmentDir, { recursive: true, force: true });
|
|
16918
17003
|
const invokeSegmented = () => {
|
|
16919
17004
|
if (capturePlan.kind !== "sdr_segmented") {
|
|
16920
17005
|
throw new Error(`Cannot invoke segmented stage with ${capturePlan.kind} plan`);
|
|
@@ -17431,7 +17516,7 @@ async function executeRenderPipeline(input) {
|
|
|
17431
17516
|
})
|
|
17432
17517
|
);
|
|
17433
17518
|
const totalElapsed = Date.now() - pipelineStart;
|
|
17434
|
-
const tmpPeakBytes =
|
|
17519
|
+
const tmpPeakBytes = existsSync21(workDir) ? sampleDirectoryBytes(workDir) : 0;
|
|
17435
17520
|
recordTransientRetryObservability();
|
|
17436
17521
|
observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
|
|
17437
17522
|
const observabilitySummary = observability.summary({
|
|
@@ -17503,7 +17588,7 @@ async function executeRenderPipeline(input) {
|
|
|
17503
17588
|
job.perfSummary = perfSummary;
|
|
17504
17589
|
if (job.config.debug) {
|
|
17505
17590
|
try {
|
|
17506
|
-
|
|
17591
|
+
writeFileSync6(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
|
|
17507
17592
|
} catch (err) {
|
|
17508
17593
|
log.debug("Failed to write perf summary", {
|
|
17509
17594
|
perfOutputPath,
|
|
@@ -17512,7 +17597,7 @@ async function executeRenderPipeline(input) {
|
|
|
17512
17597
|
}
|
|
17513
17598
|
}
|
|
17514
17599
|
if (job.config.debug) {
|
|
17515
|
-
if (!isPngSequence && !isHls &&
|
|
17600
|
+
if (!isPngSequence && !isHls && existsSync21(stagedOutputPath)) {
|
|
17516
17601
|
const debugOutput = join34(workDir, `output${videoExt}`);
|
|
17517
17602
|
copyFileSync5(stagedOutputPath, debugOutput);
|
|
17518
17603
|
}
|
|
@@ -17628,13 +17713,13 @@ async function executeRenderPipeline(input) {
|
|
|
17628
17713
|
|
|
17629
17714
|
// src/services/hyperframeLint.ts
|
|
17630
17715
|
import {
|
|
17631
|
-
existsSync as
|
|
17716
|
+
existsSync as existsSync22,
|
|
17632
17717
|
readFileSync as readFileSync10,
|
|
17633
17718
|
statSync as statSync11,
|
|
17634
|
-
openSync as
|
|
17635
|
-
fstatSync as
|
|
17636
|
-
closeSync as
|
|
17637
|
-
constants as
|
|
17719
|
+
openSync as openSync6,
|
|
17720
|
+
fstatSync as fstatSync4,
|
|
17721
|
+
closeSync as closeSync6,
|
|
17722
|
+
constants as constants4
|
|
17638
17723
|
} from "node:fs";
|
|
17639
17724
|
import { resolve as resolve10, join as join35, relative as relative5, isAbsolute as isAbsolute4, sep as sep5, dirname as dirname15 } from "node:path";
|
|
17640
17725
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
@@ -17667,7 +17752,7 @@ function pickEntryFile(files, preferredEntryFile) {
|
|
|
17667
17752
|
function readEntryHtml(filePath) {
|
|
17668
17753
|
let fd;
|
|
17669
17754
|
try {
|
|
17670
|
-
fd =
|
|
17755
|
+
fd = openSync6(filePath, constants4.O_RDONLY | constants4.O_NONBLOCK);
|
|
17671
17756
|
} catch (error) {
|
|
17672
17757
|
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
17673
17758
|
return null;
|
|
@@ -17675,10 +17760,10 @@ function readEntryHtml(filePath) {
|
|
|
17675
17760
|
throw error;
|
|
17676
17761
|
}
|
|
17677
17762
|
try {
|
|
17678
|
-
if (!
|
|
17763
|
+
if (!fstatSync4(fd).isFile()) return null;
|
|
17679
17764
|
return readFileSync10(fd, "utf-8");
|
|
17680
17765
|
} finally {
|
|
17681
|
-
|
|
17766
|
+
closeSync6(fd);
|
|
17682
17767
|
}
|
|
17683
17768
|
}
|
|
17684
17769
|
function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
@@ -17687,7 +17772,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
|
17687
17772
|
}
|
|
17688
17773
|
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
17689
17774
|
const absProjectDir = resolve10(projectDir);
|
|
17690
|
-
if (!
|
|
17775
|
+
if (!existsSync22(absProjectDir) || !statSync11(absProjectDir).isDirectory()) {
|
|
17691
17776
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
17692
17777
|
}
|
|
17693
17778
|
const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
|
|
@@ -17778,7 +17863,7 @@ function resolveLintWorkerEntry() {
|
|
|
17778
17863
|
const here = dirname15(fileURLToPath5(import.meta.url));
|
|
17779
17864
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
17780
17865
|
const candidate = join35(here, name);
|
|
17781
|
-
if (
|
|
17866
|
+
if (existsSync22(candidate)) return candidate;
|
|
17782
17867
|
}
|
|
17783
17868
|
return void 0;
|
|
17784
17869
|
}
|
|
@@ -17849,7 +17934,7 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
17849
17934
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
17850
17935
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
17851
17936
|
import { dirname as dirname16, join as join36 } from "node:path";
|
|
17852
|
-
import { existsSync as
|
|
17937
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
17853
17938
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
17854
17939
|
async function startHealthWorker(options = {}) {
|
|
17855
17940
|
const log = options.logger ?? defaultLogger2();
|
|
@@ -17926,7 +18011,7 @@ function resolveWorkerEntry2() {
|
|
|
17926
18011
|
const here = dirname16(fileURLToPath6(import.meta.url));
|
|
17927
18012
|
const candidates = [join36(here, "healthWorkerThread.js"), join36(here, "healthWorkerThread.ts")];
|
|
17928
18013
|
for (const candidate of candidates) {
|
|
17929
|
-
if (
|
|
18014
|
+
if (existsSync23(candidate)) return candidate;
|
|
17930
18015
|
}
|
|
17931
18016
|
return void 0;
|
|
17932
18017
|
}
|
|
@@ -17971,14 +18056,14 @@ import {
|
|
|
17971
18056
|
fpsToNumber as fpsToNumber9,
|
|
17972
18057
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
17973
18058
|
} from "@hyperframes/core";
|
|
17974
|
-
import { isSafePath as
|
|
18059
|
+
import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
|
|
17975
18060
|
import {
|
|
17976
18061
|
getEncoderPreset as getEncoderPreset4,
|
|
17977
18062
|
keyframeIntervalToGopSize as keyframeIntervalToGopSize3,
|
|
17978
18063
|
normalizeVp9CpuUsed,
|
|
17979
18064
|
resolveConfig as resolveConfig3,
|
|
17980
18065
|
declareContentAddressedUrl,
|
|
17981
|
-
renameWithRetry as
|
|
18066
|
+
renameWithRetry as renameWithRetry7,
|
|
17982
18067
|
declareProbeFactsUrl
|
|
17983
18068
|
} from "@hyperframes/engine";
|
|
17984
18069
|
|
|
@@ -18000,7 +18085,7 @@ import {
|
|
|
18000
18085
|
// src/services/distributed/shared.ts
|
|
18001
18086
|
import { execFile as execFileCallback } from "node:child_process";
|
|
18002
18087
|
import { dirname as dirname17, join as join37 } from "node:path";
|
|
18003
|
-
import { existsSync as
|
|
18088
|
+
import { existsSync as existsSync24, readFileSync as readFileSync11 } from "node:fs";
|
|
18004
18089
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
18005
18090
|
import { promisify as promisify2 } from "node:util";
|
|
18006
18091
|
import {
|
|
@@ -18016,7 +18101,7 @@ function readProducerVersion() {
|
|
|
18016
18101
|
let current = startDir;
|
|
18017
18102
|
for (let i = 0; i < 10; i++) {
|
|
18018
18103
|
const candidate = join37(current, "package.json");
|
|
18019
|
-
if (
|
|
18104
|
+
if (existsSync24(candidate)) {
|
|
18020
18105
|
try {
|
|
18021
18106
|
const pkg = JSON.parse(readFileSync11(candidate, "utf-8"));
|
|
18022
18107
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
@@ -18092,7 +18177,7 @@ var FIELD_DELIMITER = Buffer.from([0]);
|
|
|
18092
18177
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
18093
18178
|
|
|
18094
18179
|
// src/services/distributed/mp4Stitch.ts
|
|
18095
|
-
import { renameWithRetry as
|
|
18180
|
+
import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
|
|
18096
18181
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
18097
18182
|
var SCAN_BYTES = 64 * 1024;
|
|
18098
18183
|
|
|
@@ -18538,12 +18623,12 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
18538
18623
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
|
|
18539
18624
|
if (confineOutput) {
|
|
18540
18625
|
mkdirSync13(rendersDir, { recursive: true });
|
|
18541
|
-
if (!
|
|
18626
|
+
if (!isSafePath4(rendersDir, absoluteOutputPath)) {
|
|
18542
18627
|
throw new Error("outputPath must be inside the renders directory");
|
|
18543
18628
|
}
|
|
18544
18629
|
}
|
|
18545
18630
|
const outputDir = dirname18(absoluteOutputPath);
|
|
18546
|
-
if (!
|
|
18631
|
+
if (!existsSync25(outputDir)) mkdirSync13(outputDir, { recursive: true });
|
|
18547
18632
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
18548
18633
|
}
|
|
18549
18634
|
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
@@ -18611,22 +18696,22 @@ function resolveRenderRequestPolicy(options) {
|
|
|
18611
18696
|
};
|
|
18612
18697
|
}
|
|
18613
18698
|
function isAllowedProjectPath(projectsDir, path) {
|
|
18614
|
-
return
|
|
18699
|
+
return isSafePath4(projectsDir, path) && !isSafePath4(resolveRenderDebugDir(), path);
|
|
18615
18700
|
}
|
|
18616
18701
|
function isAllowedEntryPath(policy, projectDir, path) {
|
|
18617
|
-
return
|
|
18702
|
+
return isSafePath4(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
|
|
18618
18703
|
}
|
|
18619
18704
|
function prepareProjectDirectory(projectDir, options, policy) {
|
|
18620
18705
|
const candidate = nonEmptyString(projectDir);
|
|
18621
18706
|
if (!candidate) return null;
|
|
18622
18707
|
const absProjectDir = policy ? resolve11(policy.projectsDir, candidate) : resolve11(candidate);
|
|
18623
18708
|
const shown = policy ? candidate : absProjectDir;
|
|
18624
|
-
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !
|
|
18709
|
+
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync25(absProjectDir) || !statSync12(absProjectDir).isDirectory()) {
|
|
18625
18710
|
return { error: `Project directory not found: ${shown}` };
|
|
18626
18711
|
}
|
|
18627
18712
|
const entry = options.entryFile || "index.html";
|
|
18628
18713
|
const entryPath = resolve11(absProjectDir, entry);
|
|
18629
|
-
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !
|
|
18714
|
+
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync25(entryPath)) {
|
|
18630
18715
|
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
18631
18716
|
}
|
|
18632
18717
|
return { prepared: { input: { projectDir: absProjectDir, ...options } } };
|
|
@@ -18648,7 +18733,7 @@ async function resolveInlineRenderHtml(body) {
|
|
|
18648
18733
|
function materializeInlineProject(html, options) {
|
|
18649
18734
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir4();
|
|
18650
18735
|
const tempProjectDir = mkdtempSync(join39(tempRoot, "producer-project-"));
|
|
18651
|
-
|
|
18736
|
+
writeFileSync7(join39(tempProjectDir, "index.html"), html, "utf-8");
|
|
18652
18737
|
return {
|
|
18653
18738
|
prepared: {
|
|
18654
18739
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -18724,7 +18809,7 @@ function publicPerfSummary(job) {
|
|
|
18724
18809
|
return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
|
|
18725
18810
|
}
|
|
18726
18811
|
function outputFileSize(path) {
|
|
18727
|
-
return
|
|
18812
|
+
return existsSync25(path) ? statSync12(path).size : 0;
|
|
18728
18813
|
}
|
|
18729
18814
|
function createBlockingProgressReporter(log, requestId) {
|
|
18730
18815
|
let lastLoggedPct = -10;
|
|
@@ -19051,7 +19136,7 @@ function createRenderHandlers(options = {}) {
|
|
|
19051
19136
|
if (!artifact) {
|
|
19052
19137
|
return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
|
|
19053
19138
|
}
|
|
19054
|
-
if (!
|
|
19139
|
+
if (!existsSync25(artifact.path)) {
|
|
19055
19140
|
store.delete(token);
|
|
19056
19141
|
return c.json({ success: false, error: "Output artifact file missing" }, 404);
|
|
19057
19142
|
}
|