@hyperframes/producer 0.9.87 → 0.9.89
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 +1 -1
- package/dist/compileWorker.js +75 -15
- package/dist/distributed.js +182 -82
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/index.js +286 -123
- package/dist/public-server.js +238 -77
- package/dist/server.d.ts +1 -1
- package/dist/services/animatedGifPrep.d.ts +2 -0
- package/dist/services/assetMediaType.d.ts +4 -4
- package/dist/services/compileScratch.d.ts +2 -0
- package/dist/services/distributed/chunkFrames.d.ts +1 -0
- package/dist/services/heifImagePrep.d.ts +2 -0
- package/dist/services/render/deferredVideoFrames.d.ts +1 -0
- package/dist/services/render/shared.d.ts +3 -3
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
existsSync as existsSync22,
|
|
13
13
|
mkdirSync as mkdirSync12,
|
|
14
14
|
readdirSync as readdirSync6,
|
|
15
|
-
rmSync as
|
|
15
|
+
rmSync as rmSync13,
|
|
16
16
|
statSync as statSync10,
|
|
17
17
|
writeFileSync as writeFileSync6,
|
|
18
18
|
copyFileSync as copyFileSync5,
|
|
@@ -362,7 +362,7 @@ import {
|
|
|
362
362
|
} from "@hyperframes/engine";
|
|
363
363
|
import { join as join35, dirname as dirname15, resolve as resolve9 } from "path";
|
|
364
364
|
import { totalmem as totalmem2 } from "node:os";
|
|
365
|
-
import { randomUUID } from "crypto";
|
|
365
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
366
366
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
367
367
|
|
|
368
368
|
// src/services/fileServer.ts
|
|
@@ -546,11 +546,11 @@ var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (
|
|
|
546
546
|
nodeResolve(fileURLToPath2(import.meta.url), "../../..", "renders");
|
|
547
547
|
var LEADING_PARENT_SEGMENT_RE = /^\.\.(?:[\\/]|$)/;
|
|
548
548
|
function isPathInside(childPath, parentPath, options = {}) {
|
|
549
|
-
const
|
|
549
|
+
const resolvePath2 = options.pathModule?.resolve ?? nodeResolve;
|
|
550
550
|
const relativePath = options.pathModule?.relative ?? nodeRelative;
|
|
551
551
|
const isPathAbsolute = options.pathModule?.isAbsolute ?? nodeIsAbsolute;
|
|
552
|
-
const absChild =
|
|
553
|
-
const absParent =
|
|
552
|
+
const absChild = resolvePath2(childPath);
|
|
553
|
+
const absParent = resolvePath2(parentPath);
|
|
554
554
|
if (absChild === absParent) return true;
|
|
555
555
|
const rel = relativePath(absParent, absChild);
|
|
556
556
|
return rel !== "" && !LEADING_PARENT_SEGMENT_RE.test(rel) && !isPathAbsolute(rel);
|
|
@@ -1641,12 +1641,12 @@ var workerPhasesByJob = /* @__PURE__ */ new WeakMap();
|
|
|
1641
1641
|
function forgetWorkerPhases(job) {
|
|
1642
1642
|
workerPhasesByJob.delete(job);
|
|
1643
1643
|
}
|
|
1644
|
-
var
|
|
1645
|
-
function
|
|
1646
|
-
|
|
1644
|
+
var captureActivityByJob = /* @__PURE__ */ new WeakMap();
|
|
1645
|
+
function noteCaptureActivity(job) {
|
|
1646
|
+
captureActivityByJob.set(job, (captureActivityByJob.get(job) ?? 0) + 1);
|
|
1647
1647
|
}
|
|
1648
|
-
function
|
|
1649
|
-
return
|
|
1648
|
+
function captureActivity(job) {
|
|
1649
|
+
return captureActivityByJob.get(job) ?? 0;
|
|
1650
1650
|
}
|
|
1651
1651
|
function describeWorkerPhases(job) {
|
|
1652
1652
|
const phases = workerPhasesByJob.get(job);
|
|
@@ -6256,7 +6256,8 @@ async function extractDeferredFrames(input) {
|
|
|
6256
6256
|
outputDir: input.outputRoot,
|
|
6257
6257
|
format: range.format,
|
|
6258
6258
|
frameRanges: contiguousRuns(indexes),
|
|
6259
|
-
shownBox: input.shownBoxes?.get(video.videoId)
|
|
6259
|
+
shownBox: input.shownBoxes?.get(video.videoId),
|
|
6260
|
+
...input.onProgress && { onProgress: input.onProgress }
|
|
6260
6261
|
},
|
|
6261
6262
|
input.signal,
|
|
6262
6263
|
input.cfg
|
|
@@ -7133,7 +7134,7 @@ function requireOutputDimensions(expected, width, height) {
|
|
|
7133
7134
|
|
|
7134
7135
|
// src/services/render/stages/compileStage.ts
|
|
7135
7136
|
import { existsSync as existsSync13, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7136
|
-
import { join as join23, relative as
|
|
7137
|
+
import { join as join23, relative as relative5 } from "node:path";
|
|
7137
7138
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
7138
7139
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
7139
7140
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
@@ -7141,8 +7142,8 @@ import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolu
|
|
|
7141
7142
|
import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperframes/core/compiler";
|
|
7142
7143
|
|
|
7143
7144
|
// src/services/compileInWorker.ts
|
|
7144
|
-
import { existsSync as existsSync12 } from "node:fs";
|
|
7145
|
-
import { dirname as dirname10, join as join22 } from "node:path";
|
|
7145
|
+
import { existsSync as existsSync12, rmSync as rmSync11 } from "node:fs";
|
|
7146
|
+
import { dirname as dirname10, isAbsolute as isAbsolute4, join as join22, relative as relative4, resolve as resolvePath } from "node:path";
|
|
7146
7147
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7147
7148
|
import { Worker } from "node:worker_threads";
|
|
7148
7149
|
|
|
@@ -7448,7 +7449,7 @@ import {
|
|
|
7448
7449
|
} from "@hyperframes/core/fonts/embed";
|
|
7449
7450
|
|
|
7450
7451
|
// src/services/animatedGifPrep.ts
|
|
7451
|
-
import { createHash as createHash4 } from "node:crypto";
|
|
7452
|
+
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
7452
7453
|
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
|
|
7453
7454
|
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7454
7455
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
@@ -7523,6 +7524,8 @@ function resolveLoop(metadata, override) {
|
|
|
7523
7524
|
}
|
|
7524
7525
|
var MAX_LOOP_ITERATIONS = 1e3;
|
|
7525
7526
|
var MAX_PAD_SECONDS = 3600;
|
|
7527
|
+
var FFMPEG_SELF_CPU_SECONDS_CAP = 3600;
|
|
7528
|
+
var FFMPEG_SELF_OUTPUT_BYTES_CAP = 1024 * 1024 * 1024;
|
|
7526
7529
|
function resolveCompositionDurationSeconds(document2) {
|
|
7527
7530
|
let max = null;
|
|
7528
7531
|
for (const el of Array.from(document2.querySelectorAll("[data-composition-id][data-duration]"))) {
|
|
@@ -7565,7 +7568,13 @@ function resolvePreparedPlayback(metadata, loopOverride, windowSeconds) {
|
|
|
7565
7568
|
return { loopIterations, padSeconds: Math.round(padSeconds * 1e3) / 1e3 };
|
|
7566
7569
|
}
|
|
7567
7570
|
function buildAnimatedGifTranscodeArgs(input) {
|
|
7568
|
-
const args = [
|
|
7571
|
+
const args = [
|
|
7572
|
+
"-hide_banner",
|
|
7573
|
+
"-loglevel",
|
|
7574
|
+
"error",
|
|
7575
|
+
"-timelimit",
|
|
7576
|
+
String(FFMPEG_SELF_CPU_SECONDS_CAP)
|
|
7577
|
+
];
|
|
7569
7578
|
if (input.loopIterations > 1) {
|
|
7570
7579
|
args.push("-stream_loop", String(input.loopIterations - 1));
|
|
7571
7580
|
}
|
|
@@ -7593,6 +7602,8 @@ function buildAnimatedGifTranscodeArgs(input) {
|
|
|
7593
7602
|
...input.padSeconds && input.padSeconds > 0 ? ["-vf", `tpad=stop_mode=clone:stop_duration=${input.padSeconds}`] : [],
|
|
7594
7603
|
// Explicit muxer: the transcode writes to a `.tmp-<pid>-<ts>` path whose
|
|
7595
7604
|
// extension ffmpeg cannot infer the container from.
|
|
7605
|
+
"-fs",
|
|
7606
|
+
String(FFMPEG_SELF_OUTPUT_BYTES_CAP),
|
|
7596
7607
|
"-f",
|
|
7597
7608
|
"webm",
|
|
7598
7609
|
"-y",
|
|
@@ -7600,10 +7611,16 @@ function buildAnimatedGifTranscodeArgs(input) {
|
|
|
7600
7611
|
);
|
|
7601
7612
|
return args;
|
|
7602
7613
|
}
|
|
7614
|
+
function abortError() {
|
|
7615
|
+
const error = new Error("Aborted");
|
|
7616
|
+
error.name = "AbortError";
|
|
7617
|
+
return error;
|
|
7618
|
+
}
|
|
7603
7619
|
async function runAnimatedGifTranscode(request) {
|
|
7604
7620
|
const timeout = request.timeoutMs ?? 3e5;
|
|
7605
|
-
const result = await runFfmpeg2(request.args, { timeout });
|
|
7621
|
+
const result = await runFfmpeg2(request.args, { timeout, signal: request.signal });
|
|
7606
7622
|
if (result.success) return;
|
|
7623
|
+
if (request.signal?.aborted) throw abortError();
|
|
7607
7624
|
if (result.failureReason === "external_interruption") {
|
|
7608
7625
|
throw encoderFailureError("Animated GIF transcode failed", {
|
|
7609
7626
|
error: `exit ${result.exitCode}: ${result.stderr.slice(-500)}`,
|
|
@@ -7623,7 +7640,7 @@ async function ensurePreparedWebm(input) {
|
|
|
7623
7640
|
mkdirSync7(dirname6(input.outputPath), { recursive: true });
|
|
7624
7641
|
}
|
|
7625
7642
|
if (!isUsableFile(input.cachePath)) {
|
|
7626
|
-
const tmpPath = `${input.cachePath}.tmp-${process.pid}-${
|
|
7643
|
+
const tmpPath = `${input.cachePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
7627
7644
|
const args = buildAnimatedGifTranscodeArgs({
|
|
7628
7645
|
inputPath: input.sourcePath,
|
|
7629
7646
|
outputPath: tmpPath,
|
|
@@ -7636,11 +7653,15 @@ async function ensurePreparedWebm(input) {
|
|
|
7636
7653
|
inputPath: input.sourcePath,
|
|
7637
7654
|
outputPath: tmpPath,
|
|
7638
7655
|
args,
|
|
7639
|
-
timeoutMs: input.timeoutMs
|
|
7656
|
+
timeoutMs: input.timeoutMs,
|
|
7657
|
+
signal: input.signal
|
|
7640
7658
|
});
|
|
7641
7659
|
if (!isUsableFile(tmpPath)) {
|
|
7642
7660
|
throw new Error("Animated GIF transcode produced an empty output");
|
|
7643
7661
|
}
|
|
7662
|
+
if (statSync6(tmpPath).size >= FFMPEG_SELF_OUTPUT_BYTES_CAP) {
|
|
7663
|
+
throw new Error("Animated GIF transcode reached its output size limit");
|
|
7664
|
+
}
|
|
7644
7665
|
if (!isUsableFile(input.cachePath)) {
|
|
7645
7666
|
renameWithRetry2(tmpPath, input.cachePath);
|
|
7646
7667
|
} else {
|
|
@@ -7740,6 +7761,7 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7740
7761
|
loopIterations,
|
|
7741
7762
|
padSeconds,
|
|
7742
7763
|
timeoutMs: options.timeoutMs,
|
|
7764
|
+
signal: options.signal,
|
|
7743
7765
|
transcode: options.transcode
|
|
7744
7766
|
});
|
|
7745
7767
|
const id = ensureElementId(img, document2, i);
|
|
@@ -7764,7 +7786,7 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7764
7786
|
}
|
|
7765
7787
|
|
|
7766
7788
|
// src/services/heifImagePrep.ts
|
|
7767
|
-
import { createHash as createHash5 } from "node:crypto";
|
|
7789
|
+
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
7768
7790
|
import {
|
|
7769
7791
|
closeSync as closeSync5,
|
|
7770
7792
|
copyFileSync as copyFileSync3,
|
|
@@ -7910,6 +7932,13 @@ var HeifToolUnavailableError = class extends Error {
|
|
|
7910
7932
|
this.name = "HeifToolUnavailableError";
|
|
7911
7933
|
}
|
|
7912
7934
|
};
|
|
7935
|
+
function abortError2() {
|
|
7936
|
+
const error = new Error("Aborted");
|
|
7937
|
+
error.name = "AbortError";
|
|
7938
|
+
return error;
|
|
7939
|
+
}
|
|
7940
|
+
var FFMPEG_SELF_CPU_SECONDS_CAP2 = 300;
|
|
7941
|
+
var FFMPEG_SELF_OUTPUT_BYTES_CAP2 = 256 * 1024 * 1024;
|
|
7913
7942
|
var TOOL_FAILURE_RE = /(?:ffmpeg|ffprobe) not found|ENOENT|Option not found|Unrecognized option|Unknown decoder|Decoder \S+ not found/i;
|
|
7914
7943
|
function isHeifBytes(head) {
|
|
7915
7944
|
const bytes = Buffer.from(head.buffer, head.byteOffset, head.byteLength);
|
|
@@ -7977,6 +8006,8 @@ async function convertHeifToJpeg(request) {
|
|
|
7977
8006
|
"-hide_banner",
|
|
7978
8007
|
"-loglevel",
|
|
7979
8008
|
"error",
|
|
8009
|
+
"-timelimit",
|
|
8010
|
+
String(FFMPEG_SELF_CPU_SECONDS_CAP2),
|
|
7980
8011
|
...urlInputArgs3(request.inputPath),
|
|
7981
8012
|
"-i",
|
|
7982
8013
|
request.inputPath,
|
|
@@ -7985,14 +8016,17 @@ async function convertHeifToJpeg(request) {
|
|
|
7985
8016
|
"1",
|
|
7986
8017
|
"-q:v",
|
|
7987
8018
|
"2",
|
|
8019
|
+
"-fs",
|
|
8020
|
+
String(FFMPEG_SELF_OUTPUT_BYTES_CAP2),
|
|
7988
8021
|
"-f",
|
|
7989
8022
|
"mjpeg",
|
|
7990
8023
|
"-y",
|
|
7991
8024
|
request.outputPath
|
|
7992
8025
|
],
|
|
7993
|
-
{ timeout: request.timeoutMs ?? DEFAULT_TIMEOUT_MS }
|
|
8026
|
+
{ timeout: request.timeoutMs ?? DEFAULT_TIMEOUT_MS, signal: request.signal }
|
|
7994
8027
|
);
|
|
7995
8028
|
if (!result.success) {
|
|
8029
|
+
if (request.signal?.aborted) throw abortError2();
|
|
7996
8030
|
throw result.error ?? new Error(`ffmpeg exited ${result.exitCode}: ${result.stderr.slice(-300)}`);
|
|
7997
8031
|
}
|
|
7998
8032
|
const out = (await probeJson(request.outputPath, false)).streams?.[0];
|
|
@@ -8026,7 +8060,7 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
|
8026
8060
|
mkdirSync8(dirname7(cachePath), { recursive: true });
|
|
8027
8061
|
mkdirSync8(dirname7(outputPath), { recursive: true });
|
|
8028
8062
|
if (!isUsableFile2(cachePath)) {
|
|
8029
|
-
const tmpPath = `${cachePath}.tmp-${process.pid}-${
|
|
8063
|
+
const tmpPath = `${cachePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
8030
8064
|
const inlinePath = `${tmpPath}.heic`;
|
|
8031
8065
|
const inputPath = source.path ?? inlinePath;
|
|
8032
8066
|
try {
|
|
@@ -8034,9 +8068,13 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
|
8034
8068
|
await (options.transcode ?? convertHeifToJpeg)({
|
|
8035
8069
|
inputPath,
|
|
8036
8070
|
outputPath: tmpPath,
|
|
8037
|
-
timeoutMs: options.timeoutMs
|
|
8071
|
+
timeoutMs: options.timeoutMs,
|
|
8072
|
+
signal: options.signal
|
|
8038
8073
|
});
|
|
8039
8074
|
if (!isUsableFile2(tmpPath)) throw new Error("conversion produced an empty file");
|
|
8075
|
+
if (statSync7(tmpPath).size >= FFMPEG_SELF_OUTPUT_BYTES_CAP2) {
|
|
8076
|
+
throw new Error("conversion reached its output size limit");
|
|
8077
|
+
}
|
|
8040
8078
|
renameWithRetry3(tmpPath, cachePath);
|
|
8041
8079
|
} catch (error) {
|
|
8042
8080
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -8107,6 +8145,7 @@ import {
|
|
|
8107
8145
|
isNotImagePayload,
|
|
8108
8146
|
isNotMediaPayload,
|
|
8109
8147
|
isPrivateUnderAssetRoots as isPrivateUnderAssetRoots2,
|
|
8148
|
+
isStructurallyIncompletePngError,
|
|
8110
8149
|
playlistLeavesItsFolder,
|
|
8111
8150
|
NotMediaPayloadError,
|
|
8112
8151
|
probeMediaProfile,
|
|
@@ -8185,6 +8224,13 @@ async function notMediaReferences(path, references) {
|
|
|
8185
8224
|
if (images.length > 0 && await isNotImagePayload(path)) return images;
|
|
8186
8225
|
return await playlistLeavesItsFolder(path) ? references : [];
|
|
8187
8226
|
}
|
|
8227
|
+
function pngCutShort(references) {
|
|
8228
|
+
return references.filter((reference) => reference.expected === "video").map((reference) => ({
|
|
8229
|
+
expected: "video",
|
|
8230
|
+
detected: "image",
|
|
8231
|
+
elementFingerprint: fingerprintElementId(reference.id)
|
|
8232
|
+
}));
|
|
8233
|
+
}
|
|
8188
8234
|
async function preflightCompositionAssetMediaTypes(input) {
|
|
8189
8235
|
const references = [
|
|
8190
8236
|
...input.composition.videos.map((asset) => ({
|
|
@@ -8230,6 +8276,8 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
8230
8276
|
profile = await probeMediaProfile(resolvedPath, { signal: input.signal });
|
|
8231
8277
|
} catch (error) {
|
|
8232
8278
|
if (input.signal?.aborted) throw input.signal.reason ?? error;
|
|
8279
|
+
if (isStructurallyIncompletePngError(error))
|
|
8280
|
+
mismatches.push(...pngCutShort(pathReferences));
|
|
8233
8281
|
return;
|
|
8234
8282
|
}
|
|
8235
8283
|
for (const reference of pathReferences) {
|
|
@@ -9573,8 +9621,9 @@ async function inlineExternalFontStylesheets(html, budget = new CompositionExpan
|
|
|
9573
9621
|
const css = await fetchExternalStylesheetCss(href, fetchSignal);
|
|
9574
9622
|
const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
|
|
9575
9623
|
if (fontFaceBlocks.length === 0) return;
|
|
9624
|
+
const fontCssWithLtAsCssEscape = fontFaceBlocks.join("\n").replace(/</g, "\\3c ");
|
|
9576
9625
|
const inlineStyle = `<style>/* Inlined external font stylesheet */
|
|
9577
|
-
${
|
|
9626
|
+
${fontCssWithLtAsCssEscape}
|
|
9578
9627
|
</style>`;
|
|
9579
9628
|
try {
|
|
9580
9629
|
budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
|
|
@@ -9990,6 +10039,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
|
|
|
9990
10039
|
cacheDir: options.animatedGifCacheDir,
|
|
9991
10040
|
sourceAssets: remoteImageAssets,
|
|
9992
10041
|
timeoutMs: options.ffmpegProcessTimeout,
|
|
10042
|
+
signal: options.abortSignal,
|
|
9993
10043
|
allowOutsideFiles: assetRoot === void 0
|
|
9994
10044
|
});
|
|
9995
10045
|
if (preparedHeifImages.length > 0) {
|
|
@@ -10006,6 +10056,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
|
|
|
10006
10056
|
cacheDir: options.animatedGifCacheDir,
|
|
10007
10057
|
sourceAssets: gifSourceAssets,
|
|
10008
10058
|
timeoutMs: options.ffmpegProcessTimeout,
|
|
10059
|
+
signal: options.abortSignal,
|
|
10009
10060
|
allowOutsideFiles: assetRoot === void 0
|
|
10010
10061
|
});
|
|
10011
10062
|
if (preparedGifs.length > 0) {
|
|
@@ -10484,6 +10535,24 @@ function compileTimeoutMs() {
|
|
|
10484
10535
|
return Number.isInteger(fromEnv) && fromEnv > 0 ? Math.min(fromEnv, MAX_TIMER_MS) : DEFAULT_COMPILE_TIMEOUT_MS;
|
|
10485
10536
|
}
|
|
10486
10537
|
var warnedMissingEntry = false;
|
|
10538
|
+
var endOnProcessExit = /* @__PURE__ */ new Set();
|
|
10539
|
+
var processExitHooked = false;
|
|
10540
|
+
function onProcessExit(end) {
|
|
10541
|
+
if (!processExitHooked) {
|
|
10542
|
+
processExitHooked = true;
|
|
10543
|
+
process.on("exit", () => {
|
|
10544
|
+
for (const each of endOnProcessExit) each();
|
|
10545
|
+
});
|
|
10546
|
+
}
|
|
10547
|
+
endOnProcessExit.add(end);
|
|
10548
|
+
return () => endOnProcessExit.delete(end);
|
|
10549
|
+
}
|
|
10550
|
+
function tryQuietly(action) {
|
|
10551
|
+
try {
|
|
10552
|
+
action();
|
|
10553
|
+
} catch {
|
|
10554
|
+
}
|
|
10555
|
+
}
|
|
10487
10556
|
function resolveCompileWorkerEntry(explicit, log) {
|
|
10488
10557
|
if (explicit) return explicit;
|
|
10489
10558
|
const fromEnv = process.env.HF_COMPILE_WORKER_ENTRY;
|
|
@@ -10517,6 +10586,26 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10517
10586
|
const thread = new Worker(entry, {
|
|
10518
10587
|
workerData: { projectDir, htmlPath, downloadDir, options: cloneable }
|
|
10519
10588
|
});
|
|
10589
|
+
const children = /* @__PURE__ */ new Map();
|
|
10590
|
+
const scratchRoots = [downloadDir, options.animatedGifCacheDir].flatMap(
|
|
10591
|
+
(dir) => dir ? [resolvePath(dir)] : []
|
|
10592
|
+
);
|
|
10593
|
+
const isScratch = (path) => scratchRoots.some((root) => {
|
|
10594
|
+
const rel = relative4(root, resolvePath(path));
|
|
10595
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute4(rel);
|
|
10596
|
+
});
|
|
10597
|
+
const endChildren = (signal) => {
|
|
10598
|
+
for (const [pid, output] of children) {
|
|
10599
|
+
if (signal) tryQuietly(() => process.kill(pid, "SIGKILL"));
|
|
10600
|
+
if (output) tryQuietly(() => rmSync11(output, { force: true }));
|
|
10601
|
+
}
|
|
10602
|
+
children.clear();
|
|
10603
|
+
};
|
|
10604
|
+
const offProcessExit = onProcessExit(() => endChildren(true));
|
|
10605
|
+
const endThread = () => {
|
|
10606
|
+
endChildren(true);
|
|
10607
|
+
void thread.terminate();
|
|
10608
|
+
};
|
|
10520
10609
|
let settled = false;
|
|
10521
10610
|
const settle = (finish) => {
|
|
10522
10611
|
if (settled) return;
|
|
@@ -10527,7 +10616,7 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10527
10616
|
};
|
|
10528
10617
|
const stop = () => {
|
|
10529
10618
|
thread.postMessage({ type: "abort" });
|
|
10530
|
-
setTimeout(
|
|
10619
|
+
setTimeout(endThread, TERMINATE_GRACE_MS).unref();
|
|
10531
10620
|
};
|
|
10532
10621
|
const timer = setTimeout(() => {
|
|
10533
10622
|
stop();
|
|
@@ -10540,7 +10629,7 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10540
10629
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
10541
10630
|
const retire = (graceMs) => {
|
|
10542
10631
|
thread.unref();
|
|
10543
|
-
setTimeout(
|
|
10632
|
+
setTimeout(endThread, graceMs).unref();
|
|
10544
10633
|
};
|
|
10545
10634
|
thread.on(
|
|
10546
10635
|
"message",
|
|
@@ -10559,13 +10648,22 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10559
10648
|
}
|
|
10560
10649
|
}
|
|
10561
10650
|
);
|
|
10562
|
-
thread.on("error", (error) => settle(() => reject(error)));
|
|
10563
10651
|
thread.on(
|
|
10564
|
-
"
|
|
10565
|
-
(
|
|
10566
|
-
|
|
10567
|
-
|
|
10652
|
+
"message",
|
|
10653
|
+
({ type, pid, output }) => {
|
|
10654
|
+
if (pid === void 0) return;
|
|
10655
|
+
if (type === "child") children.set(pid, output && isScratch(output) ? output : void 0);
|
|
10656
|
+
else if (type === "childExit") children.delete(pid);
|
|
10657
|
+
}
|
|
10568
10658
|
);
|
|
10659
|
+
thread.on("error", (error) => settle(() => reject(error)));
|
|
10660
|
+
thread.on("exit", (code) => {
|
|
10661
|
+
offProcessExit();
|
|
10662
|
+
endChildren(false);
|
|
10663
|
+
settle(
|
|
10664
|
+
() => reject(new Error(`The compile worker exited with code ${code} before answering`))
|
|
10665
|
+
);
|
|
10666
|
+
});
|
|
10569
10667
|
});
|
|
10570
10668
|
}
|
|
10571
10669
|
|
|
@@ -10595,10 +10693,10 @@ function resolveEntryHtmlPath(input) {
|
|
|
10595
10693
|
const readEntry = (path) => {
|
|
10596
10694
|
if (escapesAssetRoot(path, input.assetRoot)) {
|
|
10597
10695
|
throw new Error(
|
|
10598
|
-
`Entry file "${
|
|
10696
|
+
`Entry file "${relative5(projectDir, path)}" leads outside the project folder`
|
|
10599
10697
|
);
|
|
10600
10698
|
}
|
|
10601
|
-
assertCompositionFileSize2(path,
|
|
10699
|
+
assertCompositionFileSize2(path, relative5(projectDir, path));
|
|
10602
10700
|
return readTextFile2(path);
|
|
10603
10701
|
};
|
|
10604
10702
|
const htmlPath = join23(projectDir, entryFile);
|
|
@@ -11166,7 +11264,7 @@ async function runProbeStage(input) {
|
|
|
11166
11264
|
staticDedupMemo,
|
|
11167
11265
|
compositionHash: computeCompositionObservabilityHash(compiled.html),
|
|
11168
11266
|
deferStaticDedup: true,
|
|
11169
|
-
onStaticDedupActivity: () =>
|
|
11267
|
+
onStaticDedupActivity: () => noteCaptureActivity(job)
|
|
11170
11268
|
};
|
|
11171
11269
|
const PROBE_MAX_ATTEMPTS = 2;
|
|
11172
11270
|
for (let attempt = 1; attempt <= PROBE_MAX_ATTEMPTS; attempt++) {
|
|
@@ -14400,7 +14498,7 @@ import {
|
|
|
14400
14498
|
mkdirSync as mkdirSync11,
|
|
14401
14499
|
readdirSync as readdirSync5,
|
|
14402
14500
|
readFileSync as readFileSync9,
|
|
14403
|
-
rmSync as
|
|
14501
|
+
rmSync as rmSync12,
|
|
14404
14502
|
statSync as statSync9,
|
|
14405
14503
|
writeFileSync as writeFileSync5
|
|
14406
14504
|
} from "node:fs";
|
|
@@ -14539,7 +14637,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
14539
14637
|
fileSize
|
|
14540
14638
|
};
|
|
14541
14639
|
} finally {
|
|
14542
|
-
|
|
14640
|
+
rmSync12(input.palettePath, { force: true });
|
|
14543
14641
|
}
|
|
14544
14642
|
}
|
|
14545
14643
|
function startEncodeProgress(job, stage, onProgress) {
|
|
@@ -15209,7 +15307,7 @@ function frameStallRule(job, totalFrames, probeStartupMs) {
|
|
|
15209
15307
|
tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
|
|
15210
15308
|
detail: () => describeWorkerPhases(job),
|
|
15211
15309
|
attemptOpened: () => forgetWorkerPhases(job),
|
|
15212
|
-
activity: () =>
|
|
15310
|
+
activity: () => captureActivity(job)
|
|
15213
15311
|
};
|
|
15214
15312
|
}
|
|
15215
15313
|
function isRecoverableParallelCaptureError(error) {
|
|
@@ -15418,7 +15516,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15418
15516
|
function createRenderJob(config) {
|
|
15419
15517
|
return {
|
|
15420
15518
|
...referenceBackgroundResult(void 0),
|
|
15421
|
-
id:
|
|
15519
|
+
id: randomUUID3(),
|
|
15422
15520
|
config: {
|
|
15423
15521
|
...config,
|
|
15424
15522
|
fps: toFps2(config.fps),
|
|
@@ -15933,7 +16031,7 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
|
|
|
15933
16031
|
log.info("KEEP_TEMP=1, leaving workDir on disk for inspection", { workDir });
|
|
15934
16032
|
return;
|
|
15935
16033
|
}
|
|
15936
|
-
|
|
16034
|
+
rmSync13(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
15937
16035
|
});
|
|
15938
16036
|
try {
|
|
15939
16037
|
await executeRenderPipeline({
|
|
@@ -16537,7 +16635,7 @@ async function executeRenderPipeline(input) {
|
|
|
16537
16635
|
subTimelineWaitMemo,
|
|
16538
16636
|
staticDedupMemo,
|
|
16539
16637
|
compositionHash,
|
|
16540
|
-
onStaticDedupActivity: () =>
|
|
16638
|
+
onStaticDedupActivity: () => noteCaptureActivity(job),
|
|
16541
16639
|
// Probe-resolved duration: drawElement self-verification derives its
|
|
16542
16640
|
// sample frame indices from this so they land inside the drained range.
|
|
16543
16641
|
compositionDurationSeconds: job.duration,
|
|
@@ -17401,7 +17499,7 @@ async function executeRenderPipeline(input) {
|
|
|
17401
17499
|
segmentDir
|
|
17402
17500
|
});
|
|
17403
17501
|
}
|
|
17404
|
-
if (completedSegments.size === 0)
|
|
17502
|
+
if (completedSegments.size === 0) rmSync13(segmentDir, { recursive: true, force: true });
|
|
17405
17503
|
const invokeSegmented = () => {
|
|
17406
17504
|
if (capturePlan.kind !== "sdr_segmented") {
|
|
17407
17505
|
throw new Error(`Cannot invoke segmented stage with ${capturePlan.kind} plan`);
|
|
@@ -17494,7 +17592,7 @@ async function executeRenderPipeline(input) {
|
|
|
17494
17592
|
probeSession = null;
|
|
17495
17593
|
await closeOrphanedProbeForRetry(orphaned, closeCaptureSession8, log, "segmented");
|
|
17496
17594
|
}
|
|
17497
|
-
|
|
17595
|
+
rmSync13(segmentDir, { recursive: true, force: true });
|
|
17498
17596
|
completedSegments = /* @__PURE__ */ new Set();
|
|
17499
17597
|
segmentManifest = emptySegmentManifest();
|
|
17500
17598
|
dedupPerfs.length = 0;
|
|
@@ -17533,7 +17631,7 @@ async function executeRenderPipeline(input) {
|
|
|
17533
17631
|
);
|
|
17534
17632
|
updateCaptureObservability({ segmentRetries: segmentedRes.segmentRetries });
|
|
17535
17633
|
if (job.config.keepSegments !== true) {
|
|
17536
|
-
|
|
17634
|
+
rmSync13(segmentDir, { recursive: true, force: true });
|
|
17537
17635
|
}
|
|
17538
17636
|
} else {
|
|
17539
17637
|
capturePlan = replanAfterFailure(capturePlan, { kind: "streaming_unavailable" });
|
|
@@ -17810,7 +17908,7 @@ async function executeRenderPipeline(input) {
|
|
|
17810
17908
|
"capture_disk",
|
|
17811
17909
|
"drawElement capture failed; retrying with a fresh screenshot session"
|
|
17812
17910
|
);
|
|
17813
|
-
|
|
17911
|
+
rmSync13(framesDir, { recursive: true, force: true });
|
|
17814
17912
|
mkdirSync12(framesDir, { recursive: true });
|
|
17815
17913
|
resetCaptureAttemptProgress(job);
|
|
17816
17914
|
dedupPerfs.length = 0;
|
|
@@ -18118,12 +18216,12 @@ import {
|
|
|
18118
18216
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD4,
|
|
18119
18217
|
referenceBackgroundResult as referenceBackgroundResult6
|
|
18120
18218
|
} from "@hyperframes/engine";
|
|
18121
|
-
import { mkdirSync as mkdirSync20, mkdtempSync, readFileSync as readFileSync15, rmSync as
|
|
18219
|
+
import { mkdirSync as mkdirSync20, mkdtempSync, readFileSync as readFileSync15, rmSync as rmSync19 } from "node:fs";
|
|
18122
18220
|
import { join as join49 } from "node:path";
|
|
18123
18221
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
18124
18222
|
|
|
18125
18223
|
// src/services/distributed/mp4Stitch.ts
|
|
18126
|
-
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync13, rmSync as
|
|
18224
|
+
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync14 } from "node:fs";
|
|
18127
18225
|
import { open } from "node:fs/promises";
|
|
18128
18226
|
import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
|
|
18129
18227
|
import { basename as basename8, dirname as dirname16, join as join36 } from "node:path";
|
|
@@ -18502,7 +18600,7 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
18502
18600
|
renameWithRetry6(join36(workDir, "out.mp4"), outputPath);
|
|
18503
18601
|
} finally {
|
|
18504
18602
|
out.destroy();
|
|
18505
|
-
|
|
18603
|
+
rmSync14(workDir, { recursive: true, force: true });
|
|
18506
18604
|
}
|
|
18507
18605
|
}
|
|
18508
18606
|
|
|
@@ -18519,10 +18617,10 @@ import {
|
|
|
18519
18617
|
existsSync as existsSync27,
|
|
18520
18618
|
linkSync,
|
|
18521
18619
|
mkdirSync as mkdirSync16,
|
|
18522
|
-
rmSync as
|
|
18620
|
+
rmSync as rmSync15,
|
|
18523
18621
|
writeFileSync as writeFileSync9
|
|
18524
18622
|
} from "node:fs";
|
|
18525
|
-
import { extname as extname6, isAbsolute as
|
|
18623
|
+
import { extname as extname6, isAbsolute as isAbsolute5, join as join44, relative as relative8, sep as sep5 } from "node:path";
|
|
18526
18624
|
import {
|
|
18527
18625
|
fpsToNumber as fpsToNumber9,
|
|
18528
18626
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
@@ -18990,6 +19088,7 @@ async function extractDeferredVideoFramesForChunk(input) {
|
|
|
18990
19088
|
outputRoot: input.outputRoot,
|
|
18991
19089
|
cfg: input.cfg,
|
|
18992
19090
|
shownBoxes: input.shownBoxes,
|
|
19091
|
+
...input.onProgress && { onProgress: input.onProgress },
|
|
18993
19092
|
sourceOf: (video) => {
|
|
18994
19093
|
const range = planned.get(video.videoId).deferredRange;
|
|
18995
19094
|
const remoteUrl = remoteSources[range.sourcePath];
|
|
@@ -19195,7 +19294,7 @@ async function readPlanReferenceBackground(input) {
|
|
|
19195
19294
|
|
|
19196
19295
|
// src/services/render/stages/freezePlan.ts
|
|
19197
19296
|
import { existsSync as existsSync25, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync7 } from "node:fs";
|
|
19198
|
-
import { join as join41, relative as
|
|
19297
|
+
import { join as join41, relative as relative6, resolve as resolve10 } from "node:path";
|
|
19199
19298
|
import {
|
|
19200
19299
|
REFERENCE_BACKGROUND_FIELD,
|
|
19201
19300
|
referenceBackgroundResult as referenceBackgroundResult3
|
|
@@ -19418,7 +19517,7 @@ function listPlanFiles(planDir) {
|
|
|
19418
19517
|
walk(full);
|
|
19419
19518
|
} else if (entry.isFile()) {
|
|
19420
19519
|
results.push({
|
|
19421
|
-
planRelativePath:
|
|
19520
|
+
planRelativePath: relative6(rootResolved, full).split(/[\\/]+/).join("/"),
|
|
19422
19521
|
absolutePath: full
|
|
19423
19522
|
});
|
|
19424
19523
|
}
|
|
@@ -19754,7 +19853,7 @@ async function muxChunkWithAudio(input) {
|
|
|
19754
19853
|
// src/services/distributed/planSize.ts
|
|
19755
19854
|
import { createHash as createHash9 } from "node:crypto";
|
|
19756
19855
|
import { lstatSync as lstatSync4, readdirSync as readdirSync9 } from "node:fs";
|
|
19757
|
-
import { extname as extname5, join as join43, relative as
|
|
19856
|
+
import { extname as extname5, join as join43, relative as relative7 } from "node:path";
|
|
19758
19857
|
var MAX_TOP_COMPONENTS = 10;
|
|
19759
19858
|
var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
19760
19859
|
".aac",
|
|
@@ -19843,7 +19942,7 @@ function recordFile(result, components, rootDir, rootKind, filePath) {
|
|
|
19843
19942
|
} catch {
|
|
19844
19943
|
return;
|
|
19845
19944
|
}
|
|
19846
|
-
const rel =
|
|
19945
|
+
const rel = relative7(rootDir, filePath);
|
|
19847
19946
|
const segments = rel.split(/[\\/]+/).filter(Boolean);
|
|
19848
19947
|
const classified = classifyFile(segments, rootKind);
|
|
19849
19948
|
result.totalBytes += sizeBytes;
|
|
@@ -20088,7 +20187,7 @@ var FREEZE_OWNED_PLAN_FILES = [
|
|
|
20088
20187
|
];
|
|
20089
20188
|
function removeFreezeOwnedPlanFiles(planDir) {
|
|
20090
20189
|
for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
|
|
20091
|
-
|
|
20190
|
+
rmSync15(join44(planDir, relativePath), { force: true });
|
|
20092
20191
|
}
|
|
20093
20192
|
}
|
|
20094
20193
|
function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
|
|
@@ -20227,10 +20326,10 @@ function resolveDistributedEngineConfig(config) {
|
|
|
20227
20326
|
};
|
|
20228
20327
|
}
|
|
20229
20328
|
function leavesRoot(rel) {
|
|
20230
|
-
return rel === ".." || rel.startsWith(`..${sep5}`) ||
|
|
20329
|
+
return rel === ".." || rel.startsWith(`..${sep5}`) || isAbsolute5(rel);
|
|
20231
20330
|
}
|
|
20232
20331
|
function pathInside(root, path) {
|
|
20233
|
-
const rel =
|
|
20332
|
+
const rel = relative8(root, path);
|
|
20234
20333
|
return rel === "" || leavesRoot(rel) ? null : rel;
|
|
20235
20334
|
}
|
|
20236
20335
|
function stableSourcePath(roots, srcPath) {
|
|
@@ -20317,7 +20416,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20317
20416
|
throw new Error(`[plan] entry file not found: ${htmlPath}`);
|
|
20318
20417
|
}
|
|
20319
20418
|
const workDir = join44(planDir, ".plan-work");
|
|
20320
|
-
|
|
20419
|
+
rmSync15(workDir, { recursive: true, force: true });
|
|
20321
20420
|
mkdirSync16(workDir, { recursive: true });
|
|
20322
20421
|
const compiledDir = join44(workDir, "compiled");
|
|
20323
20422
|
mkdirSync16(compiledDir, { recursive: true });
|
|
@@ -20326,7 +20425,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20326
20425
|
recursive: true,
|
|
20327
20426
|
dereference: true,
|
|
20328
20427
|
filter: (src) => {
|
|
20329
|
-
const rel =
|
|
20428
|
+
const rel = relative8(projectDir, src);
|
|
20330
20429
|
if (rel === "") return true;
|
|
20331
20430
|
if (leavesRoot(rel)) return false;
|
|
20332
20431
|
if (job.config.allowOutsideProjectAssets) {
|
|
@@ -20549,15 +20648,15 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20549
20648
|
logPlanStage(log, "extract", stageStarted);
|
|
20550
20649
|
const stagedVideoFrames = join44(compiledDir, "__hyperframes_video_frames");
|
|
20551
20650
|
const videoFramesDst = join44(planDir, "video-frames");
|
|
20552
|
-
if (existsSync27(videoFramesDst))
|
|
20651
|
+
if (existsSync27(videoFramesDst)) rmSync15(videoFramesDst, { recursive: true, force: true });
|
|
20553
20652
|
const videoSourcesDir = join44(planDir, "video-sources");
|
|
20554
|
-
|
|
20653
|
+
rmSync15(videoSourcesDir, { recursive: true, force: true });
|
|
20555
20654
|
if (existsSync27(stagedVideoFrames)) {
|
|
20556
20655
|
renameWithRetry7(stagedVideoFrames, videoFramesDst);
|
|
20557
20656
|
} else {
|
|
20558
20657
|
mkdirSync16(videoFramesDst, { recursive: true });
|
|
20559
20658
|
}
|
|
20560
|
-
if (existsSync27(finalCompiledDir))
|
|
20659
|
+
if (existsSync27(finalCompiledDir)) rmSync15(finalCompiledDir, { recursive: true, force: true });
|
|
20561
20660
|
renameWithRetry7(compiledDir, finalCompiledDir);
|
|
20562
20661
|
const shipVideoSource = createVideoSourceShipper({
|
|
20563
20662
|
planDir,
|
|
@@ -20727,7 +20826,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20727
20826
|
format: config.format
|
|
20728
20827
|
};
|
|
20729
20828
|
try {
|
|
20730
|
-
|
|
20829
|
+
rmSync15(workDir, { recursive: true, force: true });
|
|
20731
20830
|
} catch (err) {
|
|
20732
20831
|
log.warn("[plan] failed to remove temp work dir", {
|
|
20733
20832
|
workDir,
|
|
@@ -20803,7 +20902,7 @@ async function plan(projectDir, config, planDir, options = {}) {
|
|
|
20803
20902
|
|
|
20804
20903
|
// src/services/distributed/renderChunk.ts
|
|
20805
20904
|
import { randomBytes } from "node:crypto";
|
|
20806
|
-
import { existsSync as existsSync30, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as
|
|
20905
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync18, writeFileSync as writeFileSync12 } from "node:fs";
|
|
20807
20906
|
import { join as join48 } from "node:path";
|
|
20808
20907
|
import {
|
|
20809
20908
|
assertSwiftShader,
|
|
@@ -20835,12 +20934,12 @@ import {
|
|
|
20835
20934
|
mkdirSync as mkdirSync18,
|
|
20836
20935
|
readFileSync as readFileSync13,
|
|
20837
20936
|
readdirSync as readdirSync10,
|
|
20838
|
-
rmSync as
|
|
20937
|
+
rmSync as rmSync17,
|
|
20839
20938
|
statSync as statSync12,
|
|
20840
20939
|
writeFileSync as writeFileSync11
|
|
20841
20940
|
} from "node:fs";
|
|
20842
20941
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
20843
|
-
import { dirname as dirname19, isAbsolute as
|
|
20942
|
+
import { dirname as dirname19, isAbsolute as isAbsolute6, join as join47, relative as relative9, resolve as resolve11, sep as sep6 } from "node:path";
|
|
20844
20943
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
20845
20944
|
import {
|
|
20846
20945
|
createFrameLookupTable as createFrameLookupTable5,
|
|
@@ -20854,7 +20953,7 @@ import {
|
|
|
20854
20953
|
existsSync as existsSync28,
|
|
20855
20954
|
linkSync as linkSync2,
|
|
20856
20955
|
mkdirSync as mkdirSync17,
|
|
20857
|
-
rmSync as
|
|
20956
|
+
rmSync as rmSync16,
|
|
20858
20957
|
statSync as statSync11,
|
|
20859
20958
|
writeFileSync as writeFileSync10
|
|
20860
20959
|
} from "node:fs";
|
|
@@ -20945,7 +21044,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20945
21044
|
}
|
|
20946
21045
|
renameWithRetry8(temporaryPath, destinationPath);
|
|
20947
21046
|
} finally {
|
|
20948
|
-
|
|
21047
|
+
rmSync16(stagingDir, { recursive: true, force: true });
|
|
20949
21048
|
}
|
|
20950
21049
|
}
|
|
20951
21050
|
async commitManifest(manifestBytes) {
|
|
@@ -20962,7 +21061,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20962
21061
|
}
|
|
20963
21062
|
async abort() {
|
|
20964
21063
|
if (!this.#committed) {
|
|
20965
|
-
|
|
21064
|
+
rmSync16(this.temporaryDir, { recursive: true, force: true });
|
|
20966
21065
|
}
|
|
20967
21066
|
}
|
|
20968
21067
|
};
|
|
@@ -20993,7 +21092,7 @@ function readJsonFile(path, label) {
|
|
|
20993
21092
|
}
|
|
20994
21093
|
function assertSafeRelativePath(path) {
|
|
20995
21094
|
const normalized = path.split(/[\\/]+/);
|
|
20996
|
-
if (path.length === 0 ||
|
|
21095
|
+
if (path.length === 0 || isAbsolute6(path) || normalized.some((part) => part === "" || part === "." || part === "..")) {
|
|
20997
21096
|
throw new PlanV2IntegrityError(`unsafe artifact path: ${JSON.stringify(path)}`);
|
|
20998
21097
|
}
|
|
20999
21098
|
}
|
|
@@ -21007,7 +21106,7 @@ function listFiles(root) {
|
|
|
21007
21106
|
walk(absolutePath);
|
|
21008
21107
|
} else if (entry.isFile()) {
|
|
21009
21108
|
files.push({
|
|
21010
|
-
path:
|
|
21109
|
+
path: relative9(rootResolved, absolutePath).split(sep6).join("/"),
|
|
21011
21110
|
absolutePath
|
|
21012
21111
|
});
|
|
21013
21112
|
} else {
|
|
@@ -21207,7 +21306,7 @@ function collectChunkVideoDependencies(input) {
|
|
|
21207
21306
|
for (let frame = chunk.startFrame; frame < chunk.endFrame; frame++) {
|
|
21208
21307
|
const globalTime = frame * input.fpsDen / input.fpsNum;
|
|
21209
21308
|
for (const [videoId, payload] of input.table.getActiveFramePayloads(globalTime)) {
|
|
21210
|
-
const path = input.deferredSources.get(videoId) ??
|
|
21309
|
+
const path = input.deferredSources.get(videoId) ?? relative9(resolve11(input.executionPlanDir), payload.framePath).split(sep6).join("/");
|
|
21211
21310
|
assertSafeRelativePath(path);
|
|
21212
21311
|
const indexes = mutable.get(path) ?? /* @__PURE__ */ new Set();
|
|
21213
21312
|
indexes.add(chunk.index);
|
|
@@ -21232,7 +21331,7 @@ function writeBlob(sourcePath, destinationPath) {
|
|
|
21232
21331
|
copyFileSync8(sourcePath, temporaryPath);
|
|
21233
21332
|
renameWithRetry9(temporaryPath, destinationPath);
|
|
21234
21333
|
} finally {
|
|
21235
|
-
|
|
21334
|
+
rmSync17(temporaryDir, { recursive: true, force: true });
|
|
21236
21335
|
}
|
|
21237
21336
|
}
|
|
21238
21337
|
function publishBlobFor(absolutePath, digests) {
|
|
@@ -21365,7 +21464,7 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
|
21365
21464
|
renameWithRetry9(tempDir, planV2Dir);
|
|
21366
21465
|
return resultFromManifest(planV2Dir, publication.manifest);
|
|
21367
21466
|
} catch (error) {
|
|
21368
|
-
|
|
21467
|
+
rmSync17(tempDir, { recursive: true, force: true });
|
|
21369
21468
|
throw error;
|
|
21370
21469
|
}
|
|
21371
21470
|
}
|
|
@@ -21430,7 +21529,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
21430
21529
|
}
|
|
21431
21530
|
throw error;
|
|
21432
21531
|
} finally {
|
|
21433
|
-
|
|
21532
|
+
rmSync17(stagingRoot, { recursive: true, force: true });
|
|
21434
21533
|
}
|
|
21435
21534
|
}
|
|
21436
21535
|
async function planV2(projectDir, config, planV2Dir) {
|
|
@@ -21652,7 +21751,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
21652
21751
|
);
|
|
21653
21752
|
renameWithRetry9(tempDir, destinationDir);
|
|
21654
21753
|
} catch (error) {
|
|
21655
|
-
|
|
21754
|
+
rmSync17(tempDir, { recursive: true, force: true });
|
|
21656
21755
|
throw error;
|
|
21657
21756
|
}
|
|
21658
21757
|
return {
|
|
@@ -22004,7 +22103,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22004
22103
|
deferredVideos.filter((video) => remoteVideoIds.has(video.videoId))
|
|
22005
22104
|
)
|
|
22006
22105
|
});
|
|
22007
|
-
captureOptions.onStaticDedupActivity = () =>
|
|
22106
|
+
captureOptions.onStaticDedupActivity = () => noteCaptureActivity(job);
|
|
22008
22107
|
const captureFrames = effectiveChunkFrames(framesInChunk, slice.captureCost);
|
|
22009
22108
|
const chunkWorkerCount = resolveChunkCaptureWorkers(
|
|
22010
22109
|
captureFrames,
|
|
@@ -22121,7 +22220,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22121
22220
|
outputRoot: videoFramesDir,
|
|
22122
22221
|
cfg,
|
|
22123
22222
|
remoteSources,
|
|
22124
|
-
shownBoxes
|
|
22223
|
+
shownBoxes,
|
|
22224
|
+
onProgress: () => noteCaptureActivity(job)
|
|
22125
22225
|
}).then((frames) => {
|
|
22126
22226
|
videoExtractMs = Date.now() - extractStarted;
|
|
22127
22227
|
return frames;
|
|
@@ -22286,7 +22386,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22286
22386
|
return observedChunkCaptureMode(capturePerfs);
|
|
22287
22387
|
},
|
|
22288
22388
|
resetForScreenshotRetry: () => {
|
|
22289
|
-
|
|
22389
|
+
rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
22290
22390
|
boxesMeasured();
|
|
22291
22391
|
mkdirSync19(framesDir, { recursive: true });
|
|
22292
22392
|
capturePerfs.length = 0;
|
|
@@ -22332,8 +22432,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22332
22432
|
fps: { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen },
|
|
22333
22433
|
timeoutMs: cfg.ffmpegProcessTimeout
|
|
22334
22434
|
});
|
|
22335
|
-
|
|
22336
|
-
|
|
22435
|
+
rmSync18(videoOnlyPath, { force: true });
|
|
22436
|
+
rmSync18(audioScratchPath, { force: true });
|
|
22337
22437
|
}
|
|
22338
22438
|
encodeStageMs = Date.now() - encodeStarted;
|
|
22339
22439
|
} finally {
|
|
@@ -22383,8 +22483,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22383
22483
|
writeFileSync12(perfPath, `${JSON.stringify(perfPayload, null, 2)}
|
|
22384
22484
|
`, "utf-8");
|
|
22385
22485
|
try {
|
|
22386
|
-
|
|
22387
|
-
|
|
22486
|
+
rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
22487
|
+
rmSync18(videoFramesDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
22388
22488
|
} catch (err) {
|
|
22389
22489
|
log.warn("[renderChunk] failed to remove work dir", {
|
|
22390
22490
|
workDir,
|
|
@@ -22488,7 +22588,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22488
22588
|
framesEncoded: endFrame - startFrame
|
|
22489
22589
|
};
|
|
22490
22590
|
} finally {
|
|
22491
|
-
|
|
22591
|
+
rmSync19(workDir, { recursive: true, force: true });
|
|
22492
22592
|
}
|
|
22493
22593
|
}
|
|
22494
22594
|
|
|
@@ -23132,15 +23232,20 @@ import {
|
|
|
23132
23232
|
|
|
23133
23233
|
// src/server.ts
|
|
23134
23234
|
import {
|
|
23235
|
+
closeSync as closeSync9,
|
|
23236
|
+
constants as fsConstants,
|
|
23135
23237
|
existsSync as existsSync33,
|
|
23238
|
+
fstatSync as fstatSync5,
|
|
23239
|
+
lstatSync as lstatSync6,
|
|
23136
23240
|
mkdirSync as mkdirSync21,
|
|
23241
|
+
openSync as openSync9,
|
|
23137
23242
|
statSync as statSync14,
|
|
23138
23243
|
mkdtempSync as mkdtempSync2,
|
|
23139
23244
|
writeFileSync as writeFileSync13,
|
|
23140
|
-
rmSync as
|
|
23245
|
+
rmSync as rmSync20,
|
|
23141
23246
|
createReadStream as createReadStream6
|
|
23142
23247
|
} from "node:fs";
|
|
23143
|
-
import { resolve as resolve13, dirname as dirname22, join as join52 } from "node:path";
|
|
23248
|
+
import { basename as basename9, resolve as resolve13, dirname as dirname22, join as join52 } from "node:path";
|
|
23144
23249
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
23145
23250
|
import { parseArgs } from "node:util";
|
|
23146
23251
|
import { isIP } from "node:net";
|
|
@@ -23154,6 +23259,7 @@ import {
|
|
|
23154
23259
|
referenceBackgroundResult as referenceBackgroundResult7
|
|
23155
23260
|
} from "@hyperframes/engine";
|
|
23156
23261
|
import { isSafePath as isSafePath4 } from "@hyperframes/core/safe-path";
|
|
23262
|
+
import { foreignWritablePath } from "@hyperframes/core/cache-dir";
|
|
23157
23263
|
|
|
23158
23264
|
// src/services/hyperframeLint.ts
|
|
23159
23265
|
import {
|
|
@@ -23165,7 +23271,7 @@ import {
|
|
|
23165
23271
|
closeSync as closeSync8,
|
|
23166
23272
|
constants as constants4
|
|
23167
23273
|
} from "node:fs";
|
|
23168
|
-
import { resolve as resolve12, join as join50, relative as
|
|
23274
|
+
import { resolve as resolve12, join as join50, relative as relative10, isAbsolute as isAbsolute7, sep as sep7, dirname as dirname20 } from "node:path";
|
|
23169
23275
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
23170
23276
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
23171
23277
|
function isStringRecord(value) {
|
|
@@ -23211,8 +23317,8 @@ function readEntryHtml(filePath) {
|
|
|
23211
23317
|
}
|
|
23212
23318
|
}
|
|
23213
23319
|
function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
23214
|
-
const entryRelativePath =
|
|
23215
|
-
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep7}`) ||
|
|
23320
|
+
const entryRelativePath = relative10(absProjectDir, absoluteEntryPath);
|
|
23321
|
+
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep7}`) || isAbsolute7(entryRelativePath) || isAllowedEntry !== void 0 && !isAllowedEntry(absoluteEntryPath);
|
|
23216
23322
|
}
|
|
23217
23323
|
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
23218
23324
|
const absProjectDir = resolve12(projectDir);
|
|
@@ -23617,16 +23723,31 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
23617
23723
|
}
|
|
23618
23724
|
function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
23619
23725
|
const { input, cleanupProjectDir } = prepared;
|
|
23620
|
-
const
|
|
23726
|
+
const serverNamed = input.outputPath == null;
|
|
23727
|
+
const outputCandidate = input.outputPath ?? join52(rendersDir, `${basename9(resolve13(input.projectDir))}-${crypto.randomUUID()}.mp4`);
|
|
23728
|
+
const absoluteOutputPath = resolveOutputPath(input.projectDir, outputCandidate, rendersDir, log);
|
|
23729
|
+
const outputDir = dirname22(absoluteOutputPath);
|
|
23621
23730
|
if (confineOutput) {
|
|
23622
|
-
mkdirSync21(rendersDir, { recursive: true });
|
|
23731
|
+
mkdirSync21(rendersDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
23623
23732
|
if (!isSafePath4(rendersDir, absoluteOutputPath)) {
|
|
23624
23733
|
throw new Error("outputPath must be inside the renders directory");
|
|
23625
23734
|
}
|
|
23735
|
+
const foreign = folderAnotherAccountCanChange(outputDir, rendersDir);
|
|
23736
|
+
if (foreign) {
|
|
23737
|
+
throw new Error(
|
|
23738
|
+
`outputPath must be in a folder only this server's account can change; another account can change ${foreign}`
|
|
23739
|
+
);
|
|
23740
|
+
}
|
|
23626
23741
|
}
|
|
23627
|
-
|
|
23628
|
-
|
|
23629
|
-
|
|
23742
|
+
if (!existsSync33(outputDir)) mkdirSync21(outputDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
23743
|
+
return { input, cleanupProjectDir, absoluteOutputPath, serverNamed };
|
|
23744
|
+
}
|
|
23745
|
+
var STICKY_BIT = 512;
|
|
23746
|
+
var SERVER_FOLDER_MODE = 493;
|
|
23747
|
+
function folderAnotherAccountCanChange(dir, rendersDir) {
|
|
23748
|
+
const foreign = foreignWritablePath(dir, rendersDir);
|
|
23749
|
+
const stickyRoot = foreign === resolve13(rendersDir) && (lstatSync6(foreign).mode & STICKY_BIT) !== 0;
|
|
23750
|
+
return stickyRoot ? void 0 : foreign;
|
|
23630
23751
|
}
|
|
23631
23752
|
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
23632
23753
|
try {
|
|
@@ -23766,35 +23887,74 @@ function resolveOutputPath(projectDir, outputCandidate, rendersDir, log) {
|
|
|
23766
23887
|
return fallbackPath;
|
|
23767
23888
|
}
|
|
23768
23889
|
}
|
|
23769
|
-
function createArtifactStore(ttlMs) {
|
|
23890
|
+
function createArtifactStore(ttlMs, log) {
|
|
23770
23891
|
const artifacts = /* @__PURE__ */ new Map();
|
|
23892
|
+
const forget = (token) => {
|
|
23893
|
+
const artifact = artifacts.get(token);
|
|
23894
|
+
if (!artifact) return;
|
|
23895
|
+
artifacts.delete(token);
|
|
23896
|
+
if (artifact.pin !== void 0) closeSync9(artifact.pin);
|
|
23897
|
+
if (!artifact.serverNamed) return;
|
|
23898
|
+
try {
|
|
23899
|
+
rmSync20(artifact.path, { force: true });
|
|
23900
|
+
} catch (error) {
|
|
23901
|
+
log.warn("Failed to remove output artifact", {
|
|
23902
|
+
path: artifact.path,
|
|
23903
|
+
error: error instanceof Error ? error.message : String(error)
|
|
23904
|
+
});
|
|
23905
|
+
}
|
|
23906
|
+
};
|
|
23771
23907
|
const cleanup = setInterval(() => {
|
|
23772
23908
|
const now = Date.now();
|
|
23773
23909
|
for (const [token, artifact] of artifacts.entries()) {
|
|
23774
|
-
if (artifact.expiresAtMs <= now)
|
|
23775
|
-
artifacts.delete(token);
|
|
23776
|
-
}
|
|
23910
|
+
if (artifact.expiresAtMs <= now) forget(token);
|
|
23777
23911
|
}
|
|
23778
23912
|
}, 6e4);
|
|
23779
23913
|
cleanup.unref();
|
|
23780
23914
|
return {
|
|
23781
|
-
register(path) {
|
|
23915
|
+
register(path, serverNamed) {
|
|
23916
|
+
const pin = serverNamed ? openNoFollow(path) : void 0;
|
|
23917
|
+
const stat = pin === void 0 ? lstatSync6(path, { bigint: true, throwIfNoEntry: false }) : fstatSync5(pin, { bigint: true });
|
|
23918
|
+
const identity = stat && fileIdentity(stat);
|
|
23782
23919
|
const token = crypto.randomUUID();
|
|
23783
|
-
artifacts.set(token, { path, expiresAtMs: Date.now() + ttlMs });
|
|
23920
|
+
artifacts.set(token, { path, identity, pin, serverNamed, expiresAtMs: Date.now() + ttlMs });
|
|
23784
23921
|
return token;
|
|
23785
23922
|
},
|
|
23786
23923
|
get(token) {
|
|
23787
|
-
|
|
23924
|
+
const artifact = artifacts.get(token);
|
|
23925
|
+
if (artifact && artifact.expiresAtMs <= Date.now()) {
|
|
23926
|
+
forget(token);
|
|
23927
|
+
return void 0;
|
|
23928
|
+
}
|
|
23929
|
+
return artifact;
|
|
23788
23930
|
},
|
|
23789
|
-
|
|
23790
|
-
artifacts.delete(token);
|
|
23791
|
-
}
|
|
23931
|
+
forget
|
|
23792
23932
|
};
|
|
23793
23933
|
}
|
|
23934
|
+
function openArtifact(artifact) {
|
|
23935
|
+
const fd = openNoFollow(artifact.path);
|
|
23936
|
+
if (fd === void 0) return void 0;
|
|
23937
|
+
const stat = fstatSync5(fd, { bigint: true });
|
|
23938
|
+
if (stat.isFile() && fileIdentity(stat) === artifact.identity) return fd;
|
|
23939
|
+
closeSync9(fd);
|
|
23940
|
+
return void 0;
|
|
23941
|
+
}
|
|
23942
|
+
function openNoFollow(path) {
|
|
23943
|
+
try {
|
|
23944
|
+
return openSync9(path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));
|
|
23945
|
+
} catch (error) {
|
|
23946
|
+
const code = error.code;
|
|
23947
|
+
if (code === "ENOENT" || code === "ELOOP" || code === "ENOTDIR") return void 0;
|
|
23948
|
+
throw error;
|
|
23949
|
+
}
|
|
23950
|
+
}
|
|
23951
|
+
function fileIdentity(stat) {
|
|
23952
|
+
return `${stat.dev}:${stat.ino}`;
|
|
23953
|
+
}
|
|
23794
23954
|
function cleanupTempDir(dir, log) {
|
|
23795
23955
|
if (!dir) return;
|
|
23796
23956
|
try {
|
|
23797
|
-
|
|
23957
|
+
rmSync20(dir, { recursive: true, force: true });
|
|
23798
23958
|
} catch (error) {
|
|
23799
23959
|
log.warn("Failed to cleanup temp project dir", {
|
|
23800
23960
|
cleanupProjectDir: dir,
|
|
@@ -23903,10 +24063,10 @@ function createRenderHandlers(options = {}) {
|
|
|
23903
24063
|
const log = options.logger ?? defaultLogger;
|
|
23904
24064
|
const getRequestId = options.getRequestId ?? ((c) => c.req.header("x-request-id") || crypto.randomUUID());
|
|
23905
24065
|
const outputUrlPrefix = options.outputUrlPrefix ?? "/outputs";
|
|
23906
|
-
const rendersDir = options.rendersDir ?? process.env.PRODUCER_RENDERS_DIR ?? "
|
|
24066
|
+
const rendersDir = options.rendersDir ?? process.env.PRODUCER_RENDERS_DIR ?? mkdtempSync2(join52(tmpdir6(), "hyperframes-renders-"));
|
|
23907
24067
|
const policy = options.confineRequests ? resolveRenderRequestPolicy(options) : void 0;
|
|
23908
24068
|
const artifactTtlMs = options.artifactTtlMs ?? Number(process.env.PRODUCER_OUTPUT_ARTIFACT_TTL_MS || 15 * 60 * 1e3);
|
|
23909
|
-
const store = createArtifactStore(artifactTtlMs);
|
|
24069
|
+
const store = createArtifactStore(artifactTtlMs, log);
|
|
23910
24070
|
const maxConcurrentRenders = options.maxConcurrentRenders ?? Number(process.env.PRODUCER_MAX_CONCURRENT_RENDERS || 2);
|
|
23911
24071
|
const renderSemaphore = new Semaphore(maxConcurrentRenders);
|
|
23912
24072
|
const startTime = Date.now();
|
|
@@ -23971,7 +24131,7 @@ function createRenderHandlers(options = {}) {
|
|
|
23971
24131
|
if ("error" in preparedJob) {
|
|
23972
24132
|
return c.json({ success: false, requestId, error: preparedJob.error }, 400);
|
|
23973
24133
|
}
|
|
23974
|
-
const { job, input, cleanupProjectDir, absoluteOutputPath } = preparedJob;
|
|
24134
|
+
const { job, input, cleanupProjectDir, absoluteOutputPath, serverNamed } = preparedJob;
|
|
23975
24135
|
const release = await renderSemaphore.acquire();
|
|
23976
24136
|
log.info("render started", {
|
|
23977
24137
|
requestId,
|
|
@@ -23988,7 +24148,7 @@ function createRenderHandlers(options = {}) {
|
|
|
23988
24148
|
);
|
|
23989
24149
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
23990
24150
|
const durationMs = Date.now() - t0;
|
|
23991
|
-
const outputToken = store.register(absoluteOutputPath);
|
|
24151
|
+
const outputToken = store.register(absoluteOutputPath, serverNamed);
|
|
23992
24152
|
const outputUrl = `${outputUrlPrefix}/${outputToken}`;
|
|
23993
24153
|
log.info("render completed", {
|
|
23994
24154
|
requestId,
|
|
@@ -24060,7 +24220,7 @@ function createRenderHandlers(options = {}) {
|
|
|
24060
24220
|
});
|
|
24061
24221
|
return;
|
|
24062
24222
|
}
|
|
24063
|
-
const { job, input, cleanupProjectDir, absoluteOutputPath } = preparedJob;
|
|
24223
|
+
const { job, input, cleanupProjectDir, absoluteOutputPath, serverNamed } = preparedJob;
|
|
24064
24224
|
log.info("render-stream started", { requestId, projectDir: input.projectDir });
|
|
24065
24225
|
const abortController = new AbortController();
|
|
24066
24226
|
const onRequestAbort = () => abortController.abort(new RenderCancelledError("request_aborted"));
|
|
@@ -24090,7 +24250,7 @@ function createRenderHandlers(options = {}) {
|
|
|
24090
24250
|
).finally(release);
|
|
24091
24251
|
clearInterval(keepalive);
|
|
24092
24252
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
24093
|
-
const outputToken = store.register(absoluteOutputPath);
|
|
24253
|
+
const outputToken = store.register(absoluteOutputPath, serverNamed);
|
|
24094
24254
|
const outputUrl = `${outputUrlPrefix}/${outputToken}`;
|
|
24095
24255
|
log.info("render-stream completed", { requestId, fileSize, perf: job.perfSummary ?? null });
|
|
24096
24256
|
await stream.writeSSE({
|
|
@@ -24133,15 +24293,18 @@ function createRenderHandlers(options = {}) {
|
|
|
24133
24293
|
if (!artifact) {
|
|
24134
24294
|
return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
|
|
24135
24295
|
}
|
|
24136
|
-
|
|
24137
|
-
|
|
24296
|
+
const fd = openArtifact(artifact);
|
|
24297
|
+
if (fd === void 0) {
|
|
24298
|
+
store.forget(token);
|
|
24138
24299
|
return c.json({ success: false, error: "Output artifact file missing" }, 404);
|
|
24139
24300
|
}
|
|
24140
|
-
const
|
|
24141
|
-
|
|
24301
|
+
const { size } = fstatSync5(fd);
|
|
24302
|
+
const body = createReadStream6("", { fd });
|
|
24303
|
+
if (artifact.serverNamed) body.once("end", () => store.forget(token));
|
|
24304
|
+
return new Response(body, {
|
|
24142
24305
|
headers: {
|
|
24143
24306
|
"content-type": "video/mp4",
|
|
24144
|
-
"content-length": String(
|
|
24307
|
+
"content-length": String(size),
|
|
24145
24308
|
"cache-control": "no-store"
|
|
24146
24309
|
}
|
|
24147
24310
|
});
|
|
@@ -24322,7 +24485,7 @@ import {
|
|
|
24322
24485
|
import { quantizeTimeToFrame, MEDIA_VISUAL_STYLE_PROPERTIES } from "@hyperframes/engine";
|
|
24323
24486
|
|
|
24324
24487
|
// src/services/distributed/planV2Execution.ts
|
|
24325
|
-
import { mkdtempSync as mkdtempSync3, rmSync as
|
|
24488
|
+
import { mkdtempSync as mkdtempSync3, rmSync as rmSync22 } from "node:fs";
|
|
24326
24489
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
24327
24490
|
import { join as join54 } from "node:path";
|
|
24328
24491
|
|
|
@@ -24337,11 +24500,11 @@ import {
|
|
|
24337
24500
|
mkdirSync as mkdirSync22,
|
|
24338
24501
|
readFileSync as readFileSync17,
|
|
24339
24502
|
readdirSync as readdirSync12,
|
|
24340
|
-
rmSync as
|
|
24503
|
+
rmSync as rmSync21,
|
|
24341
24504
|
statSync as statSync15
|
|
24342
24505
|
} from "node:fs";
|
|
24343
24506
|
import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
|
|
24344
|
-
import { basename as
|
|
24507
|
+
import { basename as basename10, dirname as dirname23, join as join53 } from "node:path";
|
|
24345
24508
|
import {
|
|
24346
24509
|
appendRateCapArgs as appendRateCapArgs2,
|
|
24347
24510
|
writeVideoConcatList,
|
|
@@ -24393,7 +24556,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24393
24556
|
if (!existsSync34(dirname23(outputPath))) {
|
|
24394
24557
|
mkdirSync22(dirname23(outputPath), { recursive: true });
|
|
24395
24558
|
}
|
|
24396
|
-
const workDir = createStagingDir7(dirname23(outputPath), `${
|
|
24559
|
+
const workDir = createStagingDir7(dirname23(outputPath), `${basename10(outputPath)}.assemble-work-`);
|
|
24397
24560
|
const fps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
24398
24561
|
const stageMs = {};
|
|
24399
24562
|
const ctx = {
|
|
@@ -24424,7 +24587,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24424
24587
|
});
|
|
24425
24588
|
} finally {
|
|
24426
24589
|
try {
|
|
24427
|
-
|
|
24590
|
+
rmSync21(workDir, { recursive: true, force: true });
|
|
24428
24591
|
} catch (err) {
|
|
24429
24592
|
log.warn("[assemble] failed to remove work dir", {
|
|
24430
24593
|
workDir,
|
|
@@ -24627,7 +24790,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
24627
24790
|
return encoderJson;
|
|
24628
24791
|
}
|
|
24629
24792
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
24630
|
-
if (existsSync34(outputPath))
|
|
24793
|
+
if (existsSync34(outputPath)) rmSync21(outputPath, { recursive: true, force: true });
|
|
24631
24794
|
mkdirSync22(outputPath, { recursive: true });
|
|
24632
24795
|
let globalIdx = 0;
|
|
24633
24796
|
for (const chunkDir of chunkPaths) {
|
|
@@ -24678,7 +24841,7 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
|
24678
24841
|
materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
|
|
24679
24842
|
return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
|
|
24680
24843
|
} finally {
|
|
24681
|
-
|
|
24844
|
+
rmSync22(workRoot, { recursive: true, force: true });
|
|
24682
24845
|
}
|
|
24683
24846
|
}
|
|
24684
24847
|
async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
@@ -24698,7 +24861,7 @@ async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
|
24698
24861
|
options
|
|
24699
24862
|
);
|
|
24700
24863
|
} finally {
|
|
24701
|
-
|
|
24864
|
+
rmSync22(workRoot, { recursive: true, force: true });
|
|
24702
24865
|
}
|
|
24703
24866
|
}
|
|
24704
24867
|
|