@hyperframes/producer 0.9.65 → 0.9.67
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 +229 -114
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +72 -71
- package/dist/index.d.ts +1 -0
- package/dist/index.js +785 -585
- package/dist/public-server.js +584 -384
- package/dist/services/compositionSizeLimit.d.ts +3 -0
- package/dist/services/htmlCompiler.d.ts +6 -8
- package/dist/services/render/cleanup.d.ts +2 -0
- package/dist/services/render/missingPath.d.ts +15 -0
- package/dist/services/render/observability.d.ts +1 -0
- package/dist/services/renderOrchestrator.d.ts +2 -0
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
// src/services/renderOrchestrator.ts
|
|
10
10
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
|
|
11
11
|
import {
|
|
12
|
-
existsSync as
|
|
12
|
+
existsSync as existsSync22,
|
|
13
13
|
mkdirSync as mkdirSync12,
|
|
14
14
|
readdirSync as readdirSync6,
|
|
15
15
|
rmSync as rmSync12,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
copyFileSync as copyFileSync5,
|
|
19
19
|
appendFileSync
|
|
20
20
|
} from "fs";
|
|
21
|
-
import { tmpdir as
|
|
21
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
22
22
|
import {
|
|
23
23
|
chainCapture,
|
|
24
24
|
fpsToNumber as fpsToNumber8,
|
|
@@ -360,7 +360,7 @@ import {
|
|
|
360
360
|
referenceBackgroundResult,
|
|
361
361
|
createReferenceBackgroundRecorder
|
|
362
362
|
} from "@hyperframes/engine";
|
|
363
|
-
import { join as
|
|
363
|
+
import { join as join33, dirname as dirname14, resolve as resolve9 } from "path";
|
|
364
364
|
import { totalmem as totalmem2 } from "node:os";
|
|
365
365
|
import { randomUUID } from "crypto";
|
|
366
366
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
@@ -1267,13 +1267,13 @@ function createFileServer(options) {
|
|
|
1267
1267
|
if (!streamOwnsFd) closeSync(fd);
|
|
1268
1268
|
}
|
|
1269
1269
|
});
|
|
1270
|
-
return new Promise((
|
|
1270
|
+
return new Promise((resolve14, reject) => {
|
|
1271
1271
|
const connections = /* @__PURE__ */ new Set();
|
|
1272
1272
|
const server = serve({ fetch: app.fetch, port, hostname: "127.0.0.1" }, (info) => {
|
|
1273
1273
|
const bound = port === 0 ? settleOnBrowserSafePort(server, "127.0.0.1") : Promise.resolve(info.port);
|
|
1274
1274
|
bound.then((boundPort) => {
|
|
1275
1275
|
listeningPort = boundPort;
|
|
1276
|
-
|
|
1276
|
+
resolve14({
|
|
1277
1277
|
url: `http://localhost:${boundPort}`,
|
|
1278
1278
|
port: boundPort,
|
|
1279
1279
|
addPreHeadScript: (script) => {
|
|
@@ -1839,10 +1839,96 @@ function buildRenderErrorDetails(input) {
|
|
|
1839
1839
|
perfStages: Object.keys(input.perfStages).length > 0 ? { ...input.perfStages } : void 0,
|
|
1840
1840
|
hdrDiagnostics: input.hdrDiagnostics.videoExtractionFailures > 0 || input.hdrDiagnostics.imageDecodeFailures > 0 ? { ...input.hdrDiagnostics } : void 0,
|
|
1841
1841
|
observability: input.observability,
|
|
1842
|
-
subTimelineWait: input.subTimelineWait
|
|
1842
|
+
subTimelineWait: input.subTimelineWait,
|
|
1843
|
+
missingPath: input.missingPath
|
|
1843
1844
|
};
|
|
1844
1845
|
}
|
|
1845
1846
|
|
|
1847
|
+
// src/services/render/missingPath.ts
|
|
1848
|
+
import { existsSync as existsSync4, lstatSync, readlinkSync } from "node:fs";
|
|
1849
|
+
import { tmpdir } from "node:os";
|
|
1850
|
+
import { basename as basename3, join as join4, relative as relative2, resolve as resolve4, isAbsolute as isAbsolute2, sep as sep3 } from "node:path";
|
|
1851
|
+
import { errnoMissingPathOf } from "@hyperframes/core/missing-path";
|
|
1852
|
+
var SYNCED = /onedrive|dropbox|icloud|mobile documents|clouddocs|google ?drive|cloudstorage/i;
|
|
1853
|
+
var inside = (path, folder) => {
|
|
1854
|
+
const rel = relative2(resolve4(folder), resolve4(path));
|
|
1855
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
1856
|
+
};
|
|
1857
|
+
function lstatOrNull(path) {
|
|
1858
|
+
try {
|
|
1859
|
+
return lstatSync(path);
|
|
1860
|
+
} catch {
|
|
1861
|
+
return null;
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
var ROOT_SCOPES = [
|
|
1865
|
+
["tempRoot", "temp_root"],
|
|
1866
|
+
["cacheDir", "cache_root"],
|
|
1867
|
+
["workDir", "work_dir"]
|
|
1868
|
+
];
|
|
1869
|
+
var NAME_SCOPES = [
|
|
1870
|
+
[/\.partial/, "cache_partial"],
|
|
1871
|
+
[/^hfcache-/, "cache_entry"],
|
|
1872
|
+
[/^hyperframes-extract-cache/, "cache_root"],
|
|
1873
|
+
[/^(hf-render-|work-[0-9a-f]{8}-)/, "work_dir"]
|
|
1874
|
+
];
|
|
1875
|
+
function scopeOfGone(path, where, throughLink) {
|
|
1876
|
+
const root = ROOT_SCOPES.find(([key]) => {
|
|
1877
|
+
const dir = where[key];
|
|
1878
|
+
return !!dir && resolve4(path) === resolve4(dir);
|
|
1879
|
+
});
|
|
1880
|
+
if (root) return root[1];
|
|
1881
|
+
const name = basename3(path);
|
|
1882
|
+
return NAME_SCOPES.find(([pattern]) => pattern.test(name))?.[1] ?? (throughLink ? "link_target" : "other");
|
|
1883
|
+
}
|
|
1884
|
+
var MAX_LINK_HOPS = 4;
|
|
1885
|
+
function rootOf(path, where) {
|
|
1886
|
+
if (inside(path, where.tempRoot)) return "system_temp";
|
|
1887
|
+
if (where.cacheDir && inside(path, where.cacheDir)) return "cache_dir";
|
|
1888
|
+
return "other";
|
|
1889
|
+
}
|
|
1890
|
+
var ownerOf = (path, where) => [where.tempRoot, where.cacheDir, where.workDir].filter((root) => !!root && inside(path, root)).sort((a, b) => resolve4(a).length - resolve4(b).length)[0];
|
|
1891
|
+
var linkTarget = (link, folder) => resolve4(folder, readlinkSync(link).replace(/^\\\\\?\\/, ""));
|
|
1892
|
+
function goneAt(path, last, where, hops) {
|
|
1893
|
+
const scope = scopeOfGone(path, where, hops > 0);
|
|
1894
|
+
return last && scope === "other" ? "file" : scope;
|
|
1895
|
+
}
|
|
1896
|
+
function highestGone(path, where, hops = 0) {
|
|
1897
|
+
const root = ownerOf(path, where);
|
|
1898
|
+
if (!root || hops > MAX_LINK_HOPS) return "link_target";
|
|
1899
|
+
if (!existsSync4(root)) return scopeOfGone(root, where, hops > 0);
|
|
1900
|
+
const parts = relative2(resolve4(root), resolve4(path)).split(sep3).filter(Boolean);
|
|
1901
|
+
let at = resolve4(root);
|
|
1902
|
+
for (const [index, part] of parts.entries()) {
|
|
1903
|
+
const next = join4(at, part);
|
|
1904
|
+
const stat = lstatOrNull(next);
|
|
1905
|
+
if (!stat) return goneAt(next, index === parts.length - 1, where, hops);
|
|
1906
|
+
at = stat.isSymbolicLink() ? linkTarget(next, at) : next;
|
|
1907
|
+
const gone = at === next ? void 0 : highestGone(at, where, hops + 1);
|
|
1908
|
+
if (gone) return gone;
|
|
1909
|
+
}
|
|
1910
|
+
return void 0;
|
|
1911
|
+
}
|
|
1912
|
+
var isSpawnFailure = (error) => !!error?.syscall?.startsWith("spawn");
|
|
1913
|
+
function describeMissingPath(error, {
|
|
1914
|
+
cacheDir,
|
|
1915
|
+
workDir,
|
|
1916
|
+
tempRoot = tmpdir()
|
|
1917
|
+
} = {}) {
|
|
1918
|
+
try {
|
|
1919
|
+
const path = errnoMissingPathOf(error);
|
|
1920
|
+
if (!path || isSpawnFailure(error)) return void 0;
|
|
1921
|
+
const where = { tempRoot, cacheDir, workDir };
|
|
1922
|
+
return {
|
|
1923
|
+
scope: ownerOf(path, where) ? highestGone(path, where) ?? "other" : scopeOfGone(path, where, false),
|
|
1924
|
+
synced: SYNCED.test(path),
|
|
1925
|
+
root: rootOf(path, where)
|
|
1926
|
+
};
|
|
1927
|
+
} catch {
|
|
1928
|
+
return void 0;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1846
1932
|
// src/services/render/renderEventPublisher.ts
|
|
1847
1933
|
import { cloneCaptureWarnings } from "@hyperframes/engine";
|
|
1848
1934
|
var FLUSH_TIMEOUT_MS = 1e4;
|
|
@@ -1878,8 +1964,8 @@ var OrderedRenderEventPublisher = class {
|
|
|
1878
1964
|
let timer;
|
|
1879
1965
|
const drained = await Promise.race([
|
|
1880
1966
|
this.tail.then(() => true),
|
|
1881
|
-
new Promise((
|
|
1882
|
-
timer = setTimeout(() =>
|
|
1967
|
+
new Promise((resolve14) => {
|
|
1968
|
+
timer = setTimeout(() => resolve14(false), FLUSH_TIMEOUT_MS);
|
|
1883
1969
|
})
|
|
1884
1970
|
]);
|
|
1885
1971
|
clearTimeout(timer);
|
|
@@ -1983,8 +2069,8 @@ var RenderExecutionContext = class {
|
|
|
1983
2069
|
};
|
|
1984
2070
|
|
|
1985
2071
|
// src/services/render/artifactTransaction.ts
|
|
1986
|
-
import { closeSync as closeSync2, existsSync as
|
|
1987
|
-
import { basename as
|
|
2072
|
+
import { closeSync as closeSync2, existsSync as existsSync6, fstatSync as fstatSync2, openSync as openSync2, readSync, readdirSync as readdirSync2, rmSync as rmSync3 } from "node:fs";
|
|
2073
|
+
import { basename as basename5, dirname as dirname4, extname as extname2, join as join6, resolve as resolve5 } from "node:path";
|
|
1988
2074
|
import { HLS_MASTER_PLAYLIST, HLS_VIDEO_PLAYLIST, renameWithRetry } from "@hyperframes/engine";
|
|
1989
2075
|
|
|
1990
2076
|
// src/utils/ffprobe.ts
|
|
@@ -1996,16 +2082,16 @@ import {
|
|
|
1996
2082
|
|
|
1997
2083
|
// src/services/render/renderDirOwner.ts
|
|
1998
2084
|
import {
|
|
1999
|
-
existsSync as
|
|
2000
|
-
lstatSync,
|
|
2085
|
+
existsSync as existsSync5,
|
|
2086
|
+
lstatSync as lstatSync2,
|
|
2001
2087
|
readFileSync as readFileSync2,
|
|
2002
2088
|
readdirSync,
|
|
2003
|
-
readlinkSync,
|
|
2089
|
+
readlinkSync as readlinkSync2,
|
|
2004
2090
|
rmSync as rmSync2,
|
|
2005
2091
|
writeFileSync as writeFileSync2
|
|
2006
2092
|
} from "node:fs";
|
|
2007
2093
|
import { hostname, uptime } from "node:os";
|
|
2008
|
-
import { basename as
|
|
2094
|
+
import { basename as basename4, dirname as dirname3, join as join5 } from "node:path";
|
|
2009
2095
|
import { RENDER_TEMP_DIR } from "@hyperframes/core/project-folders";
|
|
2010
2096
|
import { createStagingDir } from "@hyperframes/core/atomic-file";
|
|
2011
2097
|
var OWNER_FILE = "owner.json";
|
|
@@ -2023,13 +2109,13 @@ function pidScope() {
|
|
|
2023
2109
|
host: hostname(),
|
|
2024
2110
|
// Without /proc (macOS, Windows) the boot time, to the minute, stands in for the boot id.
|
|
2025
2111
|
boot: attempt(() => readFileSync2("/proc/sys/kernel/random/boot_id", "utf-8").trim()) ?? attempt(() => String(Math.round(Date.now() / 6e4 - uptime() / 60))),
|
|
2026
|
-
pidns: attempt(() =>
|
|
2112
|
+
pidns: attempt(() => readlinkSync2("/proc/self/ns/pid"))
|
|
2027
2113
|
};
|
|
2028
2114
|
}
|
|
2029
2115
|
function createOwnedRenderDir(prefix) {
|
|
2030
|
-
const dir = createStagingDir(dirname3(prefix),
|
|
2116
|
+
const dir = createStagingDir(dirname3(prefix), basename4(prefix));
|
|
2031
2117
|
const owner = { pid: process.pid, ...pidScope() };
|
|
2032
|
-
writeFileSync2(
|
|
2118
|
+
writeFileSync2(join5(dir, OWNER_FILE), JSON.stringify(owner));
|
|
2033
2119
|
return dir;
|
|
2034
2120
|
}
|
|
2035
2121
|
function alive(pid) {
|
|
@@ -2052,7 +2138,7 @@ function inThisPidScope(owner) {
|
|
|
2052
2138
|
function ownerState(dir) {
|
|
2053
2139
|
let owner;
|
|
2054
2140
|
try {
|
|
2055
|
-
owner = JSON.parse(readFileSync2(
|
|
2141
|
+
owner = JSON.parse(readFileSync2(join5(dir, OWNER_FILE), "utf-8"));
|
|
2056
2142
|
} catch (error) {
|
|
2057
2143
|
return error.code === "ENOENT" ? "none" : "unknown";
|
|
2058
2144
|
}
|
|
@@ -2063,16 +2149,16 @@ function ownerState(dir) {
|
|
|
2063
2149
|
return alive(pid) ? "live" : "gone";
|
|
2064
2150
|
}
|
|
2065
2151
|
function newestWriteMs(path) {
|
|
2066
|
-
const stat =
|
|
2152
|
+
const stat = lstatSync2(path);
|
|
2067
2153
|
if (!stat.isDirectory()) return stat.mtimeMs;
|
|
2068
2154
|
return readdirSync(path).reduce(
|
|
2069
|
-
(newest, name) => Math.max(newest, newestWriteMs(
|
|
2155
|
+
(newest, name) => Math.max(newest, newestWriteMs(join5(path, name))),
|
|
2070
2156
|
stat.mtimeMs
|
|
2071
2157
|
);
|
|
2072
2158
|
}
|
|
2073
2159
|
function isAbandoned(dir, ownerlessIdleMs, now) {
|
|
2074
2160
|
try {
|
|
2075
|
-
if (!
|
|
2161
|
+
if (!lstatSync2(dir).isDirectory() || existsSync5(join5(dir, TRANSACTION_BACKUP))) return false;
|
|
2076
2162
|
const owner = ownerState(dir);
|
|
2077
2163
|
if (owner === "gone") return true;
|
|
2078
2164
|
return owner === "none" && ownerlessIdleMs !== void 0 && now - newestWriteMs(dir) >= ownerlessIdleMs;
|
|
@@ -2088,7 +2174,7 @@ function listAbandonedRenderDirs(parent, options = {}) {
|
|
|
2088
2174
|
return [];
|
|
2089
2175
|
}
|
|
2090
2176
|
const now = Date.now();
|
|
2091
|
-
return names.filter((name) => (options.names ?? RENDER_TEMP_DIR).test(name)).map((name) =>
|
|
2177
|
+
return names.filter((name) => (options.names ?? RENDER_TEMP_DIR).test(name)).map((name) => join5(parent, name)).filter((dir) => isAbandoned(dir, options.ownerlessIdleMs, now));
|
|
2092
2178
|
}
|
|
2093
2179
|
function createRenderWorkDir(prefix, outputDir) {
|
|
2094
2180
|
for (const parent of /* @__PURE__ */ new Set([outputDir, dirname3(prefix)])) {
|
|
@@ -2104,7 +2190,7 @@ function createRenderWorkDir(prefix, outputDir) {
|
|
|
2104
2190
|
|
|
2105
2191
|
// src/services/render/artifactTransaction.ts
|
|
2106
2192
|
var defaultFileSystem = {
|
|
2107
|
-
existsSync:
|
|
2193
|
+
existsSync: existsSync6,
|
|
2108
2194
|
renameSync: (source, destination) => renameWithRetry(source, destination),
|
|
2109
2195
|
rmSync: rmSync3
|
|
2110
2196
|
};
|
|
@@ -2137,8 +2223,8 @@ function buildArtifactExpectation(input) {
|
|
|
2137
2223
|
function createSiblingTransactionDirectory(destination) {
|
|
2138
2224
|
const parent = dirname4(destination);
|
|
2139
2225
|
const extension = extname2(destination);
|
|
2140
|
-
const stem = extension ?
|
|
2141
|
-
return createOwnedRenderDir(
|
|
2226
|
+
const stem = extension ? basename5(destination, extension) : basename5(destination);
|
|
2227
|
+
return createOwnedRenderDir(join6(parent, `.${stem}.hf-transaction-`));
|
|
2142
2228
|
}
|
|
2143
2229
|
function assertReadableNonEmptyFile(path) {
|
|
2144
2230
|
const fd = openSync2(path, "r");
|
|
@@ -2156,7 +2242,7 @@ function collectDirectoryFiles(root) {
|
|
|
2156
2242
|
const files = [];
|
|
2157
2243
|
const visit = (directory) => {
|
|
2158
2244
|
for (const entry of readdirSync2(directory, { withFileTypes: true })) {
|
|
2159
|
-
const path =
|
|
2245
|
+
const path = join6(directory, entry.name);
|
|
2160
2246
|
if (entry.isDirectory()) visit(path);
|
|
2161
2247
|
else if (entry.isFile()) files.push(path);
|
|
2162
2248
|
}
|
|
@@ -2211,10 +2297,10 @@ var ArtifactTransaction = class {
|
|
|
2211
2297
|
this.kind = kind;
|
|
2212
2298
|
this.fileSystem = fileSystem;
|
|
2213
2299
|
this.logger = logger;
|
|
2214
|
-
this.destinationPath =
|
|
2300
|
+
this.destinationPath = resolve5(destinationPath);
|
|
2215
2301
|
this.transactionDirectory = createSiblingTransactionDirectory(this.destinationPath);
|
|
2216
|
-
this.stagingPath =
|
|
2217
|
-
this.backupPath =
|
|
2302
|
+
this.stagingPath = join6(this.transactionDirectory, basename5(this.destinationPath));
|
|
2303
|
+
this.backupPath = join6(this.transactionDirectory, TRANSACTION_BACKUP);
|
|
2218
2304
|
this.durationProbe = durationProbe;
|
|
2219
2305
|
}
|
|
2220
2306
|
kind;
|
|
@@ -2257,19 +2343,19 @@ var ArtifactTransaction = class {
|
|
|
2257
2343
|
*/
|
|
2258
2344
|
async assertDirectoryExpectation(expected, files) {
|
|
2259
2345
|
for (const required of expected.requiredFiles ?? []) {
|
|
2260
|
-
const path =
|
|
2261
|
-
if (!
|
|
2346
|
+
const path = join6(this.stagingPath, required);
|
|
2347
|
+
if (!existsSync6(path)) {
|
|
2262
2348
|
throw new Error(`Render artifact directory is missing ${required}: ${this.stagingPath}`);
|
|
2263
2349
|
}
|
|
2264
2350
|
assertReadableNonEmptyFile(path);
|
|
2265
2351
|
}
|
|
2266
2352
|
if (expected.probeTarget !== void 0) {
|
|
2267
|
-
await this.assertArtifactDuration(expected,
|
|
2353
|
+
await this.assertArtifactDuration(expected, join6(this.stagingPath, expected.probeTarget));
|
|
2268
2354
|
return;
|
|
2269
2355
|
}
|
|
2270
2356
|
if (expected.expectedFrames === void 0) return;
|
|
2271
2357
|
const frameCount = files.filter(
|
|
2272
|
-
(file) => dirname4(file) === this.stagingPath && /^frame_\d+\.png$/.test(
|
|
2358
|
+
(file) => dirname4(file) === this.stagingPath && /^frame_\d+\.png$/.test(basename5(file))
|
|
2273
2359
|
).length;
|
|
2274
2360
|
if (frameCount === 0) {
|
|
2275
2361
|
throw new Error(
|
|
@@ -2507,8 +2593,8 @@ function replanAfterFailure(plan2, failure) {
|
|
|
2507
2593
|
}
|
|
2508
2594
|
|
|
2509
2595
|
// src/services/render/stages/captureSegmentedStage.ts
|
|
2510
|
-
import { existsSync as
|
|
2511
|
-
import { join as
|
|
2596
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync3, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
|
|
2597
|
+
import { join as join10 } from "node:path";
|
|
2512
2598
|
import {
|
|
2513
2599
|
captureFrameToBuffer as captureFrameToBuffer2,
|
|
2514
2600
|
closeCaptureSession as closeCaptureSession2,
|
|
@@ -2929,7 +3015,7 @@ import {
|
|
|
2929
3015
|
|
|
2930
3016
|
// src/services/hdrCompositor.ts
|
|
2931
3017
|
import { readSync as readSync2 } from "fs";
|
|
2932
|
-
import { join as
|
|
3018
|
+
import { join as join7 } from "path";
|
|
2933
3019
|
import {
|
|
2934
3020
|
captureAlphaPng,
|
|
2935
3021
|
applyDomLayerMask,
|
|
@@ -3369,7 +3455,7 @@ async function compositeHdrFrame(ctx, canvas, time, fullStacking, elementFilter,
|
|
|
3369
3455
|
if (shouldLog && debugDumpDir) {
|
|
3370
3456
|
const after = countNonZeroRgb48(canvas);
|
|
3371
3457
|
const dumpName = `frame_${String(debugFrameIndex).padStart(4, "0")}_layer_${String(layerIdx).padStart(2, "0")}_dom.png`;
|
|
3372
|
-
const dumpPath =
|
|
3458
|
+
const dumpPath = join7(debugDumpDir, dumpName);
|
|
3373
3459
|
writeFileExclusiveSync(dumpPath, domPng);
|
|
3374
3460
|
log.info("[diag] dom layer blit", {
|
|
3375
3461
|
frame: debugFrameIndex,
|
|
@@ -3424,7 +3510,7 @@ import { fpsToFfmpegArg, fpsToNumber as fpsToNumber3 } from "@hyperframes/core";
|
|
|
3424
3510
|
|
|
3425
3511
|
// src/services/hdrFrameWindows.ts
|
|
3426
3512
|
import { closeSync as closeSync3, constants as constants2, openSync as openSync3, rmSync as rmSync4 } from "node:fs";
|
|
3427
|
-
import { join as
|
|
3513
|
+
import { join as join8 } from "node:path";
|
|
3428
3514
|
function createHdrFrameWindows(opts) {
|
|
3429
3515
|
const { dir, frameSize, windowFrames, maxResident, extract } = opts;
|
|
3430
3516
|
let totalFrames = opts.totalFrames;
|
|
@@ -3448,7 +3534,7 @@ function createHdrFrameWindows(opts) {
|
|
|
3448
3534
|
const firstFrame = index * windowFrames;
|
|
3449
3535
|
const w = {
|
|
3450
3536
|
firstFrame,
|
|
3451
|
-
path:
|
|
3537
|
+
path: join8(dir, `window-${index}.rgb48le`),
|
|
3452
3538
|
frames: 0,
|
|
3453
3539
|
fd: -1,
|
|
3454
3540
|
pins: 0,
|
|
@@ -4248,8 +4334,8 @@ function isTargetLossError(error) {
|
|
|
4248
4334
|
|
|
4249
4335
|
// src/services/render/stages/captureStreamingStage.ts
|
|
4250
4336
|
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
4251
|
-
import { tmpdir } from "node:os";
|
|
4252
|
-
import { join as
|
|
4337
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
4338
|
+
import { join as join9 } from "node:path";
|
|
4253
4339
|
import {
|
|
4254
4340
|
DrawElementVerificationError,
|
|
4255
4341
|
captureFrameToBuffer,
|
|
@@ -4343,7 +4429,7 @@ var SequentialCaptureStallError = class extends Error {
|
|
|
4343
4429
|
}
|
|
4344
4430
|
};
|
|
4345
4431
|
function raceAgainstStall(promise, deadlineMs, input, signal) {
|
|
4346
|
-
return new Promise((
|
|
4432
|
+
return new Promise((resolve14, reject) => {
|
|
4347
4433
|
const clock = createStallClock();
|
|
4348
4434
|
const trip = () => reject(
|
|
4349
4435
|
signal?.aborted ? new Error(
|
|
@@ -4368,7 +4454,7 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
|
|
|
4368
4454
|
promise.then(
|
|
4369
4455
|
(value) => {
|
|
4370
4456
|
clearTimeout(timer);
|
|
4371
|
-
|
|
4457
|
+
resolve14(value);
|
|
4372
4458
|
},
|
|
4373
4459
|
(error) => {
|
|
4374
4460
|
clearTimeout(timer);
|
|
@@ -4472,11 +4558,11 @@ async function verifyDrawElementSample(session, idx, buf, ctx) {
|
|
|
4472
4558
|
return;
|
|
4473
4559
|
}
|
|
4474
4560
|
if (db < verifyMinDb) {
|
|
4475
|
-
const dumpDir = await mkdtemp(
|
|
4561
|
+
const dumpDir = await mkdtemp(join9(tmpdir2(), "hf-de-verify-fail-")).catch(() => null);
|
|
4476
4562
|
if (dumpDir) {
|
|
4477
4563
|
await Promise.all([
|
|
4478
|
-
writeFile(
|
|
4479
|
-
writeFile(
|
|
4564
|
+
writeFile(join9(dumpDir, `frame-${idx}-de.jpg`), buf),
|
|
4565
|
+
writeFile(join9(dumpDir, `frame-${idx}-truth.jpg`), truth)
|
|
4480
4566
|
]).catch(() => {
|
|
4481
4567
|
});
|
|
4482
4568
|
}
|
|
@@ -5047,7 +5133,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5047
5133
|
|
|
5048
5134
|
// src/services/render/stages/captureSegmentedStage.ts
|
|
5049
5135
|
function segmentOutputPath(segmentDir, index) {
|
|
5050
|
-
return
|
|
5136
|
+
return join10(segmentDir, `segment_${String(index).padStart(5, "0")}.mp4`);
|
|
5051
5137
|
}
|
|
5052
5138
|
function segmentEncoderOptions(base, segment) {
|
|
5053
5139
|
return {
|
|
@@ -5146,7 +5232,7 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
5146
5232
|
path: segmentPath,
|
|
5147
5233
|
// Recorded so resume can prove the file on disk is the one that
|
|
5148
5234
|
// finished; absent only in unit tests, whose fake encoder writes none.
|
|
5149
|
-
bytes:
|
|
5235
|
+
bytes: existsSync7(segmentPath) ? statSync4(segmentPath).size : 0
|
|
5150
5236
|
});
|
|
5151
5237
|
return encodeResult;
|
|
5152
5238
|
} finally {
|
|
@@ -5380,7 +5466,7 @@ async function runCaptureSegmentedStage(input) {
|
|
|
5380
5466
|
const { log, dedupPerfs, assertNotAborted } = input;
|
|
5381
5467
|
const deps = { ...DEFAULT_DEPS, ...input.deps };
|
|
5382
5468
|
const segments = planSegments(input.totalFrames, input.segmentFrames);
|
|
5383
|
-
const segmentDir = input.segmentDir ??
|
|
5469
|
+
const segmentDir = input.segmentDir ?? join10(input.workDir, "segments");
|
|
5384
5470
|
mkdirSync3(segmentDir, { recursive: true });
|
|
5385
5471
|
const skip = input.completedSegments ?? /* @__PURE__ */ new Set();
|
|
5386
5472
|
const pending = segments.filter((s) => !skip.has(s.index));
|
|
@@ -5536,7 +5622,7 @@ function startRenderEtaGuard(options) {
|
|
|
5536
5622
|
}
|
|
5537
5623
|
|
|
5538
5624
|
// src/services/render/captureCost.ts
|
|
5539
|
-
import { join as
|
|
5625
|
+
import { join as join11 } from "node:path";
|
|
5540
5626
|
import { fpsToNumber as fpsToNumber4 } from "@hyperframes/core";
|
|
5541
5627
|
import {
|
|
5542
5628
|
calculateOptimalWorkers,
|
|
@@ -5789,7 +5875,7 @@ async function runCaptureCalibration(input) {
|
|
|
5789
5875
|
});
|
|
5790
5876
|
let calibration;
|
|
5791
5877
|
try {
|
|
5792
|
-
calibration = await runOneCalibration(
|
|
5878
|
+
calibration = await runOneCalibration(join11(workDir, "capture-calibration"), calibrationCfg);
|
|
5793
5879
|
} catch (error) {
|
|
5794
5880
|
const shouldFallback = !forceScreenshot && shouldFallbackToScreenshotAfterCalibrationError(error);
|
|
5795
5881
|
if (!shouldFallback) {
|
|
@@ -5823,7 +5909,7 @@ async function runCaptureCalibration(input) {
|
|
|
5823
5909
|
const screenshotCfg = createCaptureCalibrationConfig({ ...cfg, forceScreenshot: true });
|
|
5824
5910
|
try {
|
|
5825
5911
|
calibration = await runOneCalibration(
|
|
5826
|
-
|
|
5912
|
+
join11(workDir, "capture-calibration-screenshot"),
|
|
5827
5913
|
screenshotCfg
|
|
5828
5914
|
);
|
|
5829
5915
|
} catch (fallbackError) {
|
|
@@ -5888,7 +5974,7 @@ function checkPageNeverReady(input) {
|
|
|
5888
5974
|
|
|
5889
5975
|
// src/services/render/deferredVideoFrames.ts
|
|
5890
5976
|
import { mkdirSync as mkdirSync4, rmSync as rmSync7 } from "node:fs";
|
|
5891
|
-
import { dirname as dirname5, join as
|
|
5977
|
+
import { dirname as dirname5, join as join12 } from "node:path";
|
|
5892
5978
|
import {
|
|
5893
5979
|
createFrameLookupTable,
|
|
5894
5980
|
extractVideoFramesRange,
|
|
@@ -5933,7 +6019,7 @@ async function extractDeferredFrames(input) {
|
|
|
5933
6019
|
const shown = shownDeferredFrameIndexes(input, input.frames, input.fps);
|
|
5934
6020
|
return Promise.all(
|
|
5935
6021
|
deferred.map(async (video) => {
|
|
5936
|
-
const outputDir =
|
|
6022
|
+
const outputDir = join12(input.outputRoot, mediaIdPathSegment2(video.videoId));
|
|
5937
6023
|
const indexes = [...shown.get(video.videoId) ?? []].sort((a, b) => a - b);
|
|
5938
6024
|
if (indexes.length === 0) {
|
|
5939
6025
|
return { ...video, outputDir, framePaths: /* @__PURE__ */ new Map(), ownedByLookup: false };
|
|
@@ -6081,13 +6167,13 @@ async function measureLocalShownBoxes(page, videos, fps, duration, log) {
|
|
|
6081
6167
|
|
|
6082
6168
|
// src/services/render/segmentVideoFrames.ts
|
|
6083
6169
|
import { mkdirSync as mkdirSync5, rmSync as rmSync8 } from "node:fs";
|
|
6084
|
-
import { join as
|
|
6170
|
+
import { join as join13 } from "node:path";
|
|
6085
6171
|
import {
|
|
6086
6172
|
createFrameLookupTable as createFrameLookupTable2,
|
|
6087
6173
|
createVideoFrameInjector
|
|
6088
6174
|
} from "@hyperframes/engine";
|
|
6089
6175
|
function segmentFramesDir(rootDir, index) {
|
|
6090
|
-
return
|
|
6176
|
+
return join13(rootDir, "segment-frames", `segment_${String(index).padStart(5, "0")}`);
|
|
6091
6177
|
}
|
|
6092
6178
|
function createSegmentVideoFrames(input) {
|
|
6093
6179
|
const extractFrames = input.extractFrames ?? extractDeferredFrames;
|
|
@@ -6118,7 +6204,7 @@ function createSegmentVideoFrames(input) {
|
|
|
6118
6204
|
let onDemandCalls = 0;
|
|
6119
6205
|
const onDemandHook = () => Object.assign(
|
|
6120
6206
|
async (page, time, heldVideoTime) => {
|
|
6121
|
-
const dir =
|
|
6207
|
+
const dir = join13(
|
|
6122
6208
|
input.rootDir,
|
|
6123
6209
|
"segment-frames",
|
|
6124
6210
|
`on-demand_${String(onDemandCalls++).padStart(5, "0")}`
|
|
@@ -6135,7 +6221,7 @@ function createSegmentVideoFrames(input) {
|
|
|
6135
6221
|
);
|
|
6136
6222
|
return {
|
|
6137
6223
|
async forFrames(frames, name) {
|
|
6138
|
-
const dir =
|
|
6224
|
+
const dir = join13(input.rootDir, "segment-frames", name);
|
|
6139
6225
|
const release = () => rmSync8(dir, { recursive: true, force: true });
|
|
6140
6226
|
try {
|
|
6141
6227
|
release();
|
|
@@ -6188,7 +6274,7 @@ function createSegmentVideoFrames(input) {
|
|
|
6188
6274
|
|
|
6189
6275
|
// src/services/render/videoFrameWindow.ts
|
|
6190
6276
|
import { readdirSync as readdirSync3, statSync as statSync5 } from "node:fs";
|
|
6191
|
-
import { join as
|
|
6277
|
+
import { join as join14 } from "node:path";
|
|
6192
6278
|
function shouldWindowVideoFrames(args) {
|
|
6193
6279
|
return args.segmented && args.env.HF_VIDEO_FRAME_WINDOW?.trim().toLowerCase() === "true";
|
|
6194
6280
|
}
|
|
@@ -6201,7 +6287,7 @@ function directoryBytes(path) {
|
|
|
6201
6287
|
return 0;
|
|
6202
6288
|
}
|
|
6203
6289
|
for (const entry of entries) {
|
|
6204
|
-
const child3 =
|
|
6290
|
+
const child3 = join14(path, entry.name);
|
|
6205
6291
|
try {
|
|
6206
6292
|
bytes += entry.isDirectory() ? directoryBytes(child3) : statSync5(child3).size;
|
|
6207
6293
|
} catch {
|
|
@@ -6219,7 +6305,7 @@ function trackSegmentFramePeak(frames, rootDir, onPeak) {
|
|
|
6219
6305
|
...worker,
|
|
6220
6306
|
async prepare(segment) {
|
|
6221
6307
|
await worker.prepare(segment);
|
|
6222
|
-
const held = directoryBytes(
|
|
6308
|
+
const held = directoryBytes(join14(rootDir, "segment-frames"));
|
|
6223
6309
|
if (held > peak) {
|
|
6224
6310
|
peak = held;
|
|
6225
6311
|
onPeak(peak);
|
|
@@ -6232,8 +6318,8 @@ function trackSegmentFramePeak(frames, rootDir, onPeak) {
|
|
|
6232
6318
|
|
|
6233
6319
|
// src/services/render/segmentManifest.ts
|
|
6234
6320
|
import { createHash as createHash2 } from "node:crypto";
|
|
6235
|
-
import { existsSync as
|
|
6236
|
-
import { join as
|
|
6321
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync4, statSync as statSync6, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6322
|
+
import { join as join15 } from "node:path";
|
|
6237
6323
|
import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
|
|
6238
6324
|
var MANIFEST_FILENAME = "segments.json";
|
|
6239
6325
|
function computeSegmentPlanHash(input) {
|
|
@@ -6261,7 +6347,7 @@ function computeSegmentPlanHash(input) {
|
|
|
6261
6347
|
return createHash2("sha256").update(ordered.join(" ")).digest("hex").slice(0, 16);
|
|
6262
6348
|
}
|
|
6263
6349
|
function segmentDirFor(projectRendersDir, planHash) {
|
|
6264
|
-
return
|
|
6350
|
+
return join15(projectRendersDir, ".hf-segments", planHash);
|
|
6265
6351
|
}
|
|
6266
6352
|
function hasNumber(value, key) {
|
|
6267
6353
|
return key in value && typeof Reflect.get(value, key) === "number";
|
|
@@ -6279,8 +6365,8 @@ function isManifest(value) {
|
|
|
6279
6365
|
return Reflect.get(value, "version") === 1 && hasString(value, "planHash") && hasNumber(value, "totalFrames") && hasNumber(value, "segmentFrames") && Array.isArray(completed) && completed.every(isEntry);
|
|
6280
6366
|
}
|
|
6281
6367
|
function readSegmentManifest(segmentDir) {
|
|
6282
|
-
const path =
|
|
6283
|
-
if (!
|
|
6368
|
+
const path = join15(segmentDir, MANIFEST_FILENAME);
|
|
6369
|
+
if (!existsSync8(path)) return null;
|
|
6284
6370
|
try {
|
|
6285
6371
|
const parsed = JSON.parse(readFileSync4(path, "utf-8"));
|
|
6286
6372
|
return isManifest(parsed) ? parsed : null;
|
|
@@ -6290,9 +6376,9 @@ function readSegmentManifest(segmentDir) {
|
|
|
6290
6376
|
}
|
|
6291
6377
|
function writeSegmentManifest(segmentDir, manifest) {
|
|
6292
6378
|
mkdirSync6(segmentDir, { recursive: true });
|
|
6293
|
-
const tmp =
|
|
6379
|
+
const tmp = join15(segmentDir, `${MANIFEST_FILENAME}.${process.pid}.tmp`);
|
|
6294
6380
|
writeFileSync3(tmp, JSON.stringify(manifest, null, 2), "utf-8");
|
|
6295
|
-
renameWithRetry2(tmp,
|
|
6381
|
+
renameWithRetry2(tmp, join15(segmentDir, MANIFEST_FILENAME));
|
|
6296
6382
|
}
|
|
6297
6383
|
async function probeSegmentFrameCount(path, probe) {
|
|
6298
6384
|
try {
|
|
@@ -6309,7 +6395,7 @@ async function validateCompletedSegments(manifest, expectedHash, probeFrames) {
|
|
|
6309
6395
|
const ok = /* @__PURE__ */ new Set();
|
|
6310
6396
|
if (manifest.planHash !== expectedHash) return ok;
|
|
6311
6397
|
for (const entry of manifest.completed) {
|
|
6312
|
-
if (!
|
|
6398
|
+
if (!existsSync8(entry.path)) continue;
|
|
6313
6399
|
const size = statSync6(entry.path).size;
|
|
6314
6400
|
if (size <= 0 || size !== entry.bytes) continue;
|
|
6315
6401
|
const frames = await probeFrames(entry.path);
|
|
@@ -6914,8 +7000,8 @@ function requireOutputDimensions(expected, width, height) {
|
|
|
6914
7000
|
}
|
|
6915
7001
|
|
|
6916
7002
|
// src/services/render/stages/compileStage.ts
|
|
6917
|
-
import { existsSync as
|
|
6918
|
-
import { join as
|
|
7003
|
+
import { existsSync as existsSync13, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7004
|
+
import { join as join21, relative as relative4 } from "node:path";
|
|
6919
7005
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
6920
7006
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
6921
7007
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
@@ -6944,6 +7030,21 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
|
6944
7030
|
`Composition file "${file}" is ${megabytes(bytes)}, over the ${megabytes(MAX_COMPOSITION_HTML_BYTES)} limit for one composition HTML file. Keep large data such as images, fonts and JSON in separate asset files and reference them by path instead of inlining them.`,
|
|
6945
7031
|
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
6946
7032
|
);
|
|
7033
|
+
var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
7034
|
+
var REMOTE_SCRIPTS = "remote scripts";
|
|
7035
|
+
var REMOTE_STYLESHEETS = "remote stylesheets";
|
|
7036
|
+
function generatedTooLarge(file, bytes) {
|
|
7037
|
+
if (file === "composition variables") {
|
|
7038
|
+
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
7039
|
+
}
|
|
7040
|
+
if (file === "variable media sources") {
|
|
7041
|
+
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
7042
|
+
}
|
|
7043
|
+
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
7044
|
+
return `Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. Bundle scripts and fonts with the project, or link each one once.`;
|
|
7045
|
+
}
|
|
7046
|
+
return `Scripts, styles and rebased asset paths generated for compositions, ending at "${file}", add up to ${megabytes(bytes)}. One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)} for its mounts. Merge small inline scripts and style rules, keep data-composition-id values short, or mount scenes fewer times.`;
|
|
7047
|
+
}
|
|
6947
7048
|
var CompositionExpansionBudget = class {
|
|
6948
7049
|
bytes = 0;
|
|
6949
7050
|
mounts = 0;
|
|
@@ -6952,10 +7053,16 @@ var CompositionExpansionBudget = class {
|
|
|
6952
7053
|
chargeGenerated(file, bytes) {
|
|
6953
7054
|
this.generated += bytes;
|
|
6954
7055
|
if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
|
|
6955
|
-
throw new CompositionTooLargeError(
|
|
6956
|
-
|
|
6957
|
-
|
|
6958
|
-
|
|
7056
|
+
throw new CompositionTooLargeError(generatedTooLarge(file, this.generated), {
|
|
7057
|
+
bytes: this.generated,
|
|
7058
|
+
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
7059
|
+
exceeded: "generated"
|
|
7060
|
+
});
|
|
7061
|
+
}
|
|
7062
|
+
chargeGeneratedIfItFits(bytes) {
|
|
7063
|
+
if (this.generated + bytes > MAX_EXPANDED_COMPOSITION_BYTES) return false;
|
|
7064
|
+
this.generated += bytes;
|
|
7065
|
+
return true;
|
|
6959
7066
|
}
|
|
6960
7067
|
charge(file, bytes) {
|
|
6961
7068
|
this.bytes += bytes;
|
|
@@ -7002,20 +7109,20 @@ import {
|
|
|
7002
7109
|
stylesheetLinkMatches
|
|
7003
7110
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7004
7111
|
import { createHash as createHash6 } from "node:crypto";
|
|
7005
|
-
import { createReadStream as createReadStream2, existsSync as
|
|
7006
|
-
import { join as
|
|
7112
|
+
import { createReadStream as createReadStream2, existsSync as existsSync12, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
7113
|
+
import { join as join20, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7007
7114
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7008
7115
|
|
|
7009
7116
|
// src/services/bundledScripts.ts
|
|
7010
|
-
import { existsSync as
|
|
7011
|
-
import { join as
|
|
7117
|
+
import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
|
|
7118
|
+
import { join as join16 } from "node:path";
|
|
7012
7119
|
import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
|
|
7013
7120
|
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
7014
7121
|
function bundledScript(url) {
|
|
7015
7122
|
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
7016
7123
|
if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
|
|
7017
|
-
const file =
|
|
7018
|
-
return
|
|
7124
|
+
const file = join16(dir, "gsap.min.js");
|
|
7125
|
+
return existsSync9(file) ? readFileSync5(file) : null;
|
|
7019
7126
|
}
|
|
7020
7127
|
|
|
7021
7128
|
// src/services/htmlCompiler.ts
|
|
@@ -7248,6 +7355,7 @@ function placeAudio(audio, window2) {
|
|
|
7248
7355
|
import {
|
|
7249
7356
|
analyzeKeyframeIntervals,
|
|
7250
7357
|
assertMediaPayload,
|
|
7358
|
+
createConcurrencyLimit,
|
|
7251
7359
|
isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
|
|
7252
7360
|
NotMediaPayloadError as NotMediaPayloadError2,
|
|
7253
7361
|
parseMasterFxChain,
|
|
@@ -7272,8 +7380,8 @@ import {
|
|
|
7272
7380
|
|
|
7273
7381
|
// src/services/animatedGifPrep.ts
|
|
7274
7382
|
import { createHash as createHash4 } from "node:crypto";
|
|
7275
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
7276
|
-
import { dirname as dirname6, isAbsolute as
|
|
7383
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync8 } from "node:fs";
|
|
7384
|
+
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join17, resolve as resolve6 } from "node:path";
|
|
7277
7385
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7278
7386
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
7279
7387
|
import {
|
|
@@ -7318,16 +7426,16 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7318
7426
|
const { basePath } = splitUrlSuffix(trimmed);
|
|
7319
7427
|
const normalizedBase = normalizeRelPath(basePath);
|
|
7320
7428
|
const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
|
|
7321
|
-
if (mapped &&
|
|
7429
|
+
if (mapped && existsSync10(mapped)) return mapped;
|
|
7322
7430
|
if (isHttpUrl(trimmed)) return null;
|
|
7323
7431
|
const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
|
|
7324
7432
|
const candidates = [
|
|
7325
|
-
|
|
7326
|
-
|
|
7433
|
+
isAbsolute3(basePath) ? basePath : resolve6(options.projectDir, projectRelative),
|
|
7434
|
+
resolve6(options.downloadDir, normalizedBase)
|
|
7327
7435
|
];
|
|
7328
7436
|
const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
|
|
7329
7437
|
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));
|
|
7330
|
-
return candidates.find((candidate) => allowed(candidate) &&
|
|
7438
|
+
return candidates.find((candidate) => allowed(candidate) && existsSync10(candidate)) ?? null;
|
|
7331
7439
|
}
|
|
7332
7440
|
function isUsableFile(path) {
|
|
7333
7441
|
try {
|
|
@@ -7439,10 +7547,10 @@ async function runAnimatedGifTranscode(request) {
|
|
|
7439
7547
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
7440
7548
|
}
|
|
7441
7549
|
async function ensurePreparedWebm(input) {
|
|
7442
|
-
if (!
|
|
7550
|
+
if (!existsSync10(dirname6(input.cachePath))) {
|
|
7443
7551
|
mkdirSync7(dirname6(input.cachePath), { recursive: true });
|
|
7444
7552
|
}
|
|
7445
|
-
if (!
|
|
7553
|
+
if (!existsSync10(dirname6(input.outputPath))) {
|
|
7446
7554
|
mkdirSync7(dirname6(input.outputPath), { recursive: true });
|
|
7447
7555
|
}
|
|
7448
7556
|
if (!isUsableFile(input.cachePath)) {
|
|
@@ -7474,7 +7582,7 @@ async function ensurePreparedWebm(input) {
|
|
|
7474
7582
|
throw error;
|
|
7475
7583
|
}
|
|
7476
7584
|
}
|
|
7477
|
-
if (
|
|
7585
|
+
if (resolve6(input.outputPath) !== resolve6(input.cachePath) && !isUsableFile(input.outputPath)) {
|
|
7478
7586
|
copyFileSync2(input.cachePath, input.outputPath);
|
|
7479
7587
|
}
|
|
7480
7588
|
}
|
|
@@ -7526,7 +7634,7 @@ function replaceImageWithVideo(input) {
|
|
|
7526
7634
|
return video;
|
|
7527
7635
|
}
|
|
7528
7636
|
async function prepareAnimatedGifInputs(html, options) {
|
|
7529
|
-
const outputDir = options.outputDir ??
|
|
7637
|
+
const outputDir = options.outputDir ?? join17(options.downloadDir, PREPARED_GIF_SUBDIR);
|
|
7530
7638
|
const outputSrcPrefix = normalizeRelPath(options.outputSrcPrefix ?? PREPARED_GIF_SUBDIR);
|
|
7531
7639
|
const cacheDir = options.cacheDir ?? outputDir;
|
|
7532
7640
|
const { document: document2 } = parseHTML3(html);
|
|
@@ -7553,8 +7661,8 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7553
7661
|
);
|
|
7554
7662
|
const hash = computePreparedGifHash(bytes, loopIterations, padSeconds);
|
|
7555
7663
|
const filename = `${CACHE_SCHEMA}-${hash.slice(0, 24)}.webm`;
|
|
7556
|
-
const cachePath =
|
|
7557
|
-
const outputPath =
|
|
7664
|
+
const cachePath = join17(cacheDir, filename);
|
|
7665
|
+
const outputPath = join17(outputDir, filename);
|
|
7558
7666
|
const outputSrc = `${outputSrcPrefix}/${filename}`;
|
|
7559
7667
|
await ensurePreparedWebm({
|
|
7560
7668
|
sourcePath,
|
|
@@ -7599,7 +7707,7 @@ import {
|
|
|
7599
7707
|
statSync as statSync9,
|
|
7600
7708
|
writeFileSync as writeFileSync4
|
|
7601
7709
|
} from "node:fs";
|
|
7602
|
-
import { dirname as dirname7, join as
|
|
7710
|
+
import { dirname as dirname7, join as join18, resolve as resolve7 } from "node:path";
|
|
7603
7711
|
import { parseHTML as parseHTML4 } from "linkedom";
|
|
7604
7712
|
import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
|
|
7605
7713
|
|
|
@@ -7668,10 +7776,10 @@ var Semaphore = class {
|
|
|
7668
7776
|
this.active++;
|
|
7669
7777
|
return () => this.release();
|
|
7670
7778
|
}
|
|
7671
|
-
return new Promise((
|
|
7779
|
+
return new Promise((resolve14) => {
|
|
7672
7780
|
this.queue.push(() => {
|
|
7673
7781
|
this.active++;
|
|
7674
|
-
|
|
7782
|
+
resolve14(() => this.release());
|
|
7675
7783
|
});
|
|
7676
7784
|
});
|
|
7677
7785
|
}
|
|
@@ -7869,12 +7977,12 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
|
7869
7977
|
rmSync10(inlinePath, { force: true });
|
|
7870
7978
|
}
|
|
7871
7979
|
}
|
|
7872
|
-
if (
|
|
7980
|
+
if (resolve7(outputPath) !== resolve7(cachePath) && !isUsableFile2(outputPath)) {
|
|
7873
7981
|
copyFileSync3(cachePath, outputPath);
|
|
7874
7982
|
}
|
|
7875
7983
|
}
|
|
7876
7984
|
async function prepareHeifImageInputs(html, options) {
|
|
7877
|
-
const outputDir = options.outputDir ??
|
|
7985
|
+
const outputDir = options.outputDir ?? join18(options.downloadDir, PREPARED_HEIF_SUBDIR);
|
|
7878
7986
|
const outputSrcPrefix = normalizeRelPath(options.outputSrcPrefix ?? PREPARED_HEIF_SUBDIR);
|
|
7879
7987
|
const cacheDir = options.cacheDir ?? outputDir;
|
|
7880
7988
|
const preparedAssets = /* @__PURE__ */ new Map();
|
|
@@ -7895,7 +8003,7 @@ async function prepareHeifImageInputs(html, options) {
|
|
|
7895
8003
|
await Promise.all(
|
|
7896
8004
|
[...unique].map(
|
|
7897
8005
|
([filename, source]) => withMediaProbeSlot(
|
|
7898
|
-
() => ensurePreparedJpeg(source,
|
|
8006
|
+
() => ensurePreparedJpeg(source, join18(cacheDir, filename), join18(outputDir, filename), options)
|
|
7899
8007
|
).catch((error) => {
|
|
7900
8008
|
if (!options.onFailure) throw error;
|
|
7901
8009
|
failed.add(filename);
|
|
@@ -7907,8 +8015,8 @@ async function prepareHeifImageInputs(html, options) {
|
|
|
7907
8015
|
if (failed.has(filename)) continue;
|
|
7908
8016
|
const outputSrc = `${outputSrcPrefix}/${filename}`;
|
|
7909
8017
|
img.setAttribute("src", outputSrc);
|
|
7910
|
-
preparedAssets.set(outputSrc,
|
|
7911
|
-
preparedImages.push({ sourceSrc: src, outputSrc, outputPath:
|
|
8018
|
+
preparedAssets.set(outputSrc, join18(outputDir, filename));
|
|
8019
|
+
preparedImages.push({ sourceSrc: src, outputSrc, outputPath: join18(outputDir, filename) });
|
|
7912
8020
|
}
|
|
7913
8021
|
return { html: document2.toString(), preparedAssets, preparedImages };
|
|
7914
8022
|
}
|
|
@@ -7918,8 +8026,8 @@ import { createStudioPositionSeekReapplyScript } from "@hyperframes/studio-serve
|
|
|
7918
8026
|
import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
|
|
7919
8027
|
|
|
7920
8028
|
// src/services/assetMediaType.ts
|
|
7921
|
-
import { existsSync as
|
|
7922
|
-
import { dirname as dirname8, join as
|
|
8029
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
8030
|
+
import { dirname as dirname8, join as join19 } from "node:path";
|
|
7923
8031
|
import {
|
|
7924
8032
|
fingerprintElementId,
|
|
7925
8033
|
isHttpUrl as isHttpUrl2,
|
|
@@ -7972,11 +8080,11 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
|
|
|
7972
8080
|
]);
|
|
7973
8081
|
}
|
|
7974
8082
|
function mediaAssetRoots(projectDir, compiledDir) {
|
|
7975
|
-
return [projectDir, compiledDir,
|
|
8083
|
+
return [projectDir, compiledDir, join19(dirname8(compiledDir), "downloads")];
|
|
7976
8084
|
}
|
|
7977
8085
|
function dropMediaOutsideProject(input) {
|
|
7978
8086
|
const { projectDir, workDir, composition, log } = input;
|
|
7979
|
-
const compiledDir =
|
|
8087
|
+
const compiledDir = join19(workDir, "compiled");
|
|
7980
8088
|
const roots = mediaAssetRoots(projectDir, compiledDir);
|
|
7981
8089
|
const staysInside = ({ id, src }) => {
|
|
7982
8090
|
if (!src || isHttpUrl2(src)) return true;
|
|
@@ -8031,7 +8139,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
8031
8139
|
input.projectDir,
|
|
8032
8140
|
input.compiledDir
|
|
8033
8141
|
);
|
|
8034
|
-
if (!
|
|
8142
|
+
if (!existsSync11(resolvedPath)) continue;
|
|
8035
8143
|
byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
|
|
8036
8144
|
}
|
|
8037
8145
|
const mismatches = [];
|
|
@@ -8122,7 +8230,7 @@ function normalizeCompositionSrcs(html, projectDir) {
|
|
|
8122
8230
|
if (!value.includes("%") && !/^\.?[\\/]/.test(value)) return whole;
|
|
8123
8231
|
const file = resolveCompositionSrc(projectDir, value);
|
|
8124
8232
|
if (file === null) return whole;
|
|
8125
|
-
return `${name}${quote}${
|
|
8233
|
+
return `${name}${quote}${relative3(projectDir, file).split(sep4).join("/")}${quote}`;
|
|
8126
8234
|
});
|
|
8127
8235
|
}
|
|
8128
8236
|
var COMPOSITION_FILE = /\.html?$/i;
|
|
@@ -8327,8 +8435,8 @@ function detectShaderTransitionUsage(html) {
|
|
|
8327
8435
|
async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, probes, assetRoot) {
|
|
8328
8436
|
let filePath = src;
|
|
8329
8437
|
if (isHttpUrl(src)) {
|
|
8330
|
-
const remoteDir =
|
|
8331
|
-
if (!
|
|
8438
|
+
const remoteDir = join20(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8439
|
+
if (!existsSync12(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8332
8440
|
try {
|
|
8333
8441
|
filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
|
|
8334
8442
|
onTelemetry: logRemoteDownloadTelemetry
|
|
@@ -8338,7 +8446,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8338
8446
|
}
|
|
8339
8447
|
} else {
|
|
8340
8448
|
filePath = decodedUrlPath(src);
|
|
8341
|
-
if (!filePath.startsWith("/")) filePath =
|
|
8449
|
+
if (!filePath.startsWith("/")) filePath = join20(baseDir, filePath);
|
|
8342
8450
|
if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir])) {
|
|
8343
8451
|
return { duration: null, resolvedPath: filePath };
|
|
8344
8452
|
}
|
|
@@ -8347,7 +8455,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8347
8455
|
return { duration: null, resolvedPath: filePath };
|
|
8348
8456
|
}
|
|
8349
8457
|
}
|
|
8350
|
-
if (!isHttpUrl(filePath) && !
|
|
8458
|
+
if (!isHttpUrl(filePath) && !existsSync12(filePath)) {
|
|
8351
8459
|
return { duration: null, resolvedPath: filePath };
|
|
8352
8460
|
}
|
|
8353
8461
|
const withSrcContext = (error) => {
|
|
@@ -8667,7 +8775,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
8667
8775
|
}
|
|
8668
8776
|
return document2.toString();
|
|
8669
8777
|
}
|
|
8670
|
-
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles) {
|
|
8778
|
+
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles, budget) {
|
|
8671
8779
|
const { document: document2 } = parseHTML5(html);
|
|
8672
8780
|
const head = document2.querySelector("head");
|
|
8673
8781
|
const body = document2.querySelector("body");
|
|
@@ -8676,11 +8784,11 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8676
8784
|
const emitted = emitRootCompositionVariableStyles(
|
|
8677
8785
|
document2,
|
|
8678
8786
|
{},
|
|
8679
|
-
variableOverrides
|
|
8787
|
+
variableOverrides,
|
|
8788
|
+
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
8680
8789
|
);
|
|
8681
8790
|
return { html: emitted ? document2.toString() : html, variablesByComp: {} };
|
|
8682
8791
|
}
|
|
8683
|
-
const budget = new CompositionExpansionBudget();
|
|
8684
8792
|
const readOnce = /* @__PURE__ */ new Map();
|
|
8685
8793
|
const readMountHtml = (srcPath) => {
|
|
8686
8794
|
const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
|
|
@@ -8715,6 +8823,10 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8715
8823
|
hostIdentityMap: hostIdentityByElement,
|
|
8716
8824
|
readVariableDefaults: readDeclaredDefaults,
|
|
8717
8825
|
parseHostVariables: parseHostVariableValues,
|
|
8826
|
+
resolveFilePath: (srcPath) => {
|
|
8827
|
+
const file = resolveCompositionFile(projectDir, srcPath, assetRoot);
|
|
8828
|
+
return file && relative3(projectDir, file).split(sep4).join("/");
|
|
8829
|
+
},
|
|
8718
8830
|
resolveHtml: (srcPath) => {
|
|
8719
8831
|
const compHtml = resolveMountHtml(srcPath);
|
|
8720
8832
|
if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
|
|
@@ -8805,7 +8917,8 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8805
8917
|
emitRootCompositionVariableStyles(
|
|
8806
8918
|
document2,
|
|
8807
8919
|
result.variablesByComp,
|
|
8808
|
-
variableOverrides
|
|
8920
|
+
variableOverrides,
|
|
8921
|
+
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
8809
8922
|
);
|
|
8810
8923
|
assignMediaRenderIds(document2);
|
|
8811
8924
|
return { html: document2.toString(), variablesByComp: result.variablesByComp };
|
|
@@ -8876,7 +8989,8 @@ async function downloadScript(src, mirror) {
|
|
|
8876
8989
|
}
|
|
8877
8990
|
return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
|
|
8878
8991
|
}
|
|
8879
|
-
|
|
8992
|
+
var MAX_CONCURRENT_SCRIPT_FETCHES = 4;
|
|
8993
|
+
async function inlineExternalScripts(html, budget = new CompositionExpansionBudget()) {
|
|
8880
8994
|
const fullHtml = ensureFullDocument(html);
|
|
8881
8995
|
const wrappedFragment = fullHtml !== html;
|
|
8882
8996
|
const { document: document2 } = parseHTML5(fullHtml);
|
|
@@ -8890,20 +9004,52 @@ async function inlineExternalScripts(html) {
|
|
|
8890
9004
|
}
|
|
8891
9005
|
if (externalScripts.length === 0) return html;
|
|
8892
9006
|
const mirror = operatorGsapMirror();
|
|
9007
|
+
const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
|
|
9008
|
+
const stop = new AbortController();
|
|
9009
|
+
const fail = (error) => {
|
|
9010
|
+
stop.abort(error);
|
|
9011
|
+
throw error;
|
|
9012
|
+
};
|
|
9013
|
+
const charge = (bytes) => {
|
|
9014
|
+
try {
|
|
9015
|
+
budget.chargeGenerated(REMOTE_SCRIPTS, bytes);
|
|
9016
|
+
} catch (error) {
|
|
9017
|
+
fail(error);
|
|
9018
|
+
}
|
|
9019
|
+
};
|
|
9020
|
+
const fetches = /* @__PURE__ */ new Map();
|
|
9021
|
+
const fetchOnce = (src) => {
|
|
9022
|
+
let bytes = fetches.get(src);
|
|
9023
|
+
if (!bytes) {
|
|
9024
|
+
bytes = limit(async () => {
|
|
9025
|
+
if (stop.signal.aborted) throw stop.signal.reason;
|
|
9026
|
+
const downloaded = await downloadScript(src, mirror);
|
|
9027
|
+
charge(downloaded.byteLength);
|
|
9028
|
+
return downloaded;
|
|
9029
|
+
}, stop.signal);
|
|
9030
|
+
fetches.set(src, bytes);
|
|
9031
|
+
}
|
|
9032
|
+
return bytes;
|
|
9033
|
+
};
|
|
9034
|
+
const placed = /* @__PURE__ */ new Set();
|
|
8893
9035
|
const downloads = await Promise.allSettled(
|
|
8894
9036
|
externalScripts.map(async ({ el, src }) => {
|
|
8895
9037
|
const integrity = el.getAttribute("integrity") || "";
|
|
8896
|
-
|
|
8897
|
-
if (
|
|
8898
|
-
|
|
8899
|
-
}
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
9038
|
+
let bytes = bundledScript(src);
|
|
9039
|
+
if (bytes && matchesScriptIntegrity(bytes, integrity)) {
|
|
9040
|
+
charge(bytes.byteLength);
|
|
9041
|
+
} else {
|
|
9042
|
+
bytes = await fetchOnce(src);
|
|
9043
|
+
if (!matchesScriptIntegrity(bytes, integrity)) {
|
|
9044
|
+
fail(new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`));
|
|
9045
|
+
}
|
|
9046
|
+
if (placed.has(src)) charge(bytes.byteLength);
|
|
9047
|
+
placed.add(src);
|
|
8903
9048
|
}
|
|
8904
9049
|
return { src, text: new TextDecoder().decode(bytes) };
|
|
8905
9050
|
})
|
|
8906
9051
|
);
|
|
9052
|
+
if (stop.signal.aborted) throw stop.signal.reason;
|
|
8907
9053
|
for (let i = 0; i < downloads.length; i++) {
|
|
8908
9054
|
const download = downloads[i];
|
|
8909
9055
|
const { el, src } = externalScripts[i];
|
|
@@ -8930,18 +9076,18 @@ ${safeText}
|
|
|
8930
9076
|
return wrappedFragment ? document2.body.innerHTML || "" : document2.toString();
|
|
8931
9077
|
}
|
|
8932
9078
|
function collectExternalAssets(html, projectDir, log = defaultLogger, file = "index.html", policy = {}) {
|
|
8933
|
-
const absProjectDir =
|
|
9079
|
+
const absProjectDir = resolve8(projectDir);
|
|
8934
9080
|
const externalAssets = /* @__PURE__ */ new Map();
|
|
8935
9081
|
const leftOut = /* @__PURE__ */ new Set();
|
|
8936
9082
|
function processPath(rawPath) {
|
|
8937
9083
|
const trimmed = rawPath.trim();
|
|
8938
9084
|
if (isNonRelativeUrl(trimmed)) return null;
|
|
8939
|
-
const absPath =
|
|
9085
|
+
const absPath = resolve8(absProjectDir, trimmed);
|
|
8940
9086
|
if (isPathInside(absPath, absProjectDir)) {
|
|
8941
9087
|
return null;
|
|
8942
9088
|
}
|
|
8943
9089
|
const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
|
|
8944
|
-
if (!onShare && !
|
|
9090
|
+
if (!onShare && !existsSync12(absPath)) return null;
|
|
8945
9091
|
const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
|
|
8946
9092
|
if (refusal) {
|
|
8947
9093
|
if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
|
|
@@ -8994,7 +9140,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
8994
9140
|
var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
8995
9141
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
8996
9142
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
8997
|
-
if (!
|
|
9143
|
+
if (!existsSync12(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8998
9144
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
8999
9145
|
await Promise.all(
|
|
9000
9146
|
[...urlSet].map(async (url) => {
|
|
@@ -9017,7 +9163,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
9017
9163
|
const remoteMediaAssets = /* @__PURE__ */ new Map();
|
|
9018
9164
|
const urlToRelPath = /* @__PURE__ */ new Map();
|
|
9019
9165
|
for (const [url, absPath] of urlToLocal) {
|
|
9020
|
-
const relPath = `${REMOTE_MEDIA_SUBDIR}/${
|
|
9166
|
+
const relPath = `${REMOTE_MEDIA_SUBDIR}/${basename6(absPath)}`;
|
|
9021
9167
|
remoteMediaAssets.set(relPath, absPath);
|
|
9022
9168
|
urlToRelPath.set(url, relPath);
|
|
9023
9169
|
}
|
|
@@ -9034,7 +9180,7 @@ async function localizeRemoteMediaSources(html, downloadDir) {
|
|
|
9034
9180
|
const localized = await downloadAndRewriteUrls(
|
|
9035
9181
|
urlSet,
|
|
9036
9182
|
html,
|
|
9037
|
-
|
|
9183
|
+
join20(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9038
9184
|
"Remote media download failed",
|
|
9039
9185
|
"Localized remote media source(s)"
|
|
9040
9186
|
);
|
|
@@ -9057,7 +9203,7 @@ async function localizeRemoteImageSources(html, downloadDir) {
|
|
|
9057
9203
|
return downloadAndRewriteUrls(
|
|
9058
9204
|
urlSet,
|
|
9059
9205
|
html,
|
|
9060
|
-
|
|
9206
|
+
join20(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9061
9207
|
"Remote image download failed",
|
|
9062
9208
|
"Localized remote image source(s)"
|
|
9063
9209
|
);
|
|
@@ -9070,7 +9216,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
9070
9216
|
return downloadAndRewriteUrls(
|
|
9071
9217
|
urlSet,
|
|
9072
9218
|
html,
|
|
9073
|
-
|
|
9219
|
+
join20(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9074
9220
|
"Remote background-image download failed",
|
|
9075
9221
|
"Localized remote background-image(s)",
|
|
9076
9222
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
@@ -9127,48 +9273,50 @@ function matchingBraces(css) {
|
|
|
9127
9273
|
}
|
|
9128
9274
|
return closes;
|
|
9129
9275
|
}
|
|
9130
|
-
|
|
9131
|
-
const
|
|
9132
|
-
|
|
9276
|
+
function remoteFontStylesheetHref(tag) {
|
|
9277
|
+
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
9278
|
+
if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
|
|
9279
|
+
return href;
|
|
9280
|
+
}
|
|
9281
|
+
async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget()) {
|
|
9282
|
+
const hrefs = /* @__PURE__ */ new Set();
|
|
9133
9283
|
for (const { parts } of stylesheetLinkMatches(html)) {
|
|
9134
|
-
const
|
|
9135
|
-
|
|
9136
|
-
if (!hrefMatch?.[1]) continue;
|
|
9137
|
-
const href = hrefMatch[1];
|
|
9138
|
-
if (!/^https?:\/\//i.test(href)) continue;
|
|
9139
|
-
if (isGoogleFontsUrl(href)) continue;
|
|
9140
|
-
linkMatches.push({ fullMatch: tag, href });
|
|
9141
|
-
}
|
|
9142
|
-
if (linkMatches.length === 0) return html;
|
|
9143
|
-
const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
|
|
9144
|
-
const fetches = [];
|
|
9145
|
-
for (let i = 0; i < linkMatches.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
|
|
9146
|
-
const batch = linkMatches.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
|
|
9147
|
-
const results = await Promise.all(
|
|
9148
|
-
batch.map(async ({ fullMatch, href }) => {
|
|
9149
|
-
const css = await fetchExternalStylesheetCss(href);
|
|
9150
|
-
return { fullMatch, href, css };
|
|
9151
|
-
})
|
|
9152
|
-
);
|
|
9153
|
-
fetches.push(...results);
|
|
9284
|
+
const href = remoteFontStylesheetHref(parts[0]);
|
|
9285
|
+
if (href) hrefs.add(href);
|
|
9154
9286
|
}
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
const
|
|
9161
|
-
const
|
|
9287
|
+
if (hrefs.size === 0) return html;
|
|
9288
|
+
const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
|
|
9289
|
+
const inlineByHref = /* @__PURE__ */ new Map();
|
|
9290
|
+
const unique = [...hrefs];
|
|
9291
|
+
for (let i = 0; i < unique.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
|
|
9292
|
+
const batch = unique.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
|
|
9293
|
+
const sheets = await Promise.all(batch.map(fetchExternalStylesheetCss));
|
|
9294
|
+
batch.forEach((href, index) => {
|
|
9295
|
+
const css = sheets[index];
|
|
9296
|
+
const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
|
|
9297
|
+
if (fontFaceBlocks.length === 0) return;
|
|
9298
|
+
const inlineStyle = `<style>/* Inlined external font stylesheet */
|
|
9162
9299
|
${fontFaceBlocks.join("\n")}
|
|
9163
9300
|
</style>`;
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9301
|
+
budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
|
|
9302
|
+
inlineByHref.set(href, inlineStyle);
|
|
9303
|
+
const identity = safeDownloadUrlIdentity(href);
|
|
9304
|
+
defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
|
|
9305
|
+
count: fontFaceBlocks.length,
|
|
9306
|
+
urlFingerprint: identity.urlFingerprint,
|
|
9307
|
+
host: identity.host
|
|
9308
|
+
});
|
|
9169
9309
|
});
|
|
9170
9310
|
}
|
|
9171
|
-
|
|
9311
|
+
const placed = /* @__PURE__ */ new Set();
|
|
9312
|
+
return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
|
|
9313
|
+
const href = remoteFontStylesheetHref(tag);
|
|
9314
|
+
const inlineStyle = href ? inlineByHref.get(href) : void 0;
|
|
9315
|
+
if (!href || !inlineStyle) return tag;
|
|
9316
|
+
if (placed.has(href)) budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
|
|
9317
|
+
placed.add(href);
|
|
9318
|
+
return inlineStyle;
|
|
9319
|
+
});
|
|
9172
9320
|
}
|
|
9173
9321
|
function projectStylesheetFontFamilies(html, projectDir) {
|
|
9174
9322
|
const families = [];
|
|
@@ -9177,14 +9325,14 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
9177
9325
|
} of stylesheetLinkMatches(html)) {
|
|
9178
9326
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
9179
9327
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
9180
|
-
const sheet =
|
|
9181
|
-
if (!isPathInside(sheet, projectDir) || !
|
|
9328
|
+
const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
9329
|
+
if (!isPathInside(sheet, projectDir) || !existsSync12(sheet)) continue;
|
|
9182
9330
|
for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
|
|
9183
9331
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
9184
9332
|
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
9185
9333
|
const path = decodedUrlPath(url);
|
|
9186
|
-
const file = path.startsWith("/") ?
|
|
9187
|
-
return isPathInside(file, projectDir) &&
|
|
9334
|
+
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname9(sheet), path);
|
|
9335
|
+
return isPathInside(file, projectDir) && existsSync12(file);
|
|
9188
9336
|
});
|
|
9189
9337
|
if (family && shipsFile) families.push(family);
|
|
9190
9338
|
}
|
|
@@ -9224,16 +9372,12 @@ function localizeFontFaceUrls(html, downloadDir) {
|
|
|
9224
9372
|
return downloadAndRewriteUrls(
|
|
9225
9373
|
collectFontFaceUrls(html),
|
|
9226
9374
|
html,
|
|
9227
|
-
|
|
9375
|
+
join20(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9228
9376
|
"Remote font download failed",
|
|
9229
9377
|
"Localized remote font face(s)",
|
|
9230
9378
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9231
9379
|
);
|
|
9232
9380
|
}
|
|
9233
|
-
function urlOccurrenceRe(localPath) {
|
|
9234
|
-
const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9235
|
-
return new RegExp(`url\\((["']?)${escaped}\\1\\)`, "g");
|
|
9236
|
-
}
|
|
9237
9381
|
var MAX_LOCAL_FONT_DATA_URI_BYTES = 5 * 1024 * 1024;
|
|
9238
9382
|
async function readLocalFont(absPath) {
|
|
9239
9383
|
const chunks = [];
|
|
@@ -9248,59 +9392,83 @@ async function readLocalFont(absPath) {
|
|
|
9248
9392
|
}
|
|
9249
9393
|
return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
|
|
9250
9394
|
}
|
|
9251
|
-
async function
|
|
9252
|
-
const
|
|
9253
|
-
|
|
9254
|
-
|
|
9395
|
+
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log) {
|
|
9396
|
+
const absPath = localPath.startsWith("/") ? localPath : resolve8(projectDir, localPath);
|
|
9397
|
+
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) return void 0;
|
|
9398
|
+
if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
|
|
9399
|
+
return void 0;
|
|
9400
|
+
}
|
|
9401
|
+
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
9402
|
+
if (dataUriByAbsolutePath.has(absPath)) return dataUriByAbsolutePath.get(absPath);
|
|
9403
|
+
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
9404
|
+
try {
|
|
9405
|
+
const font = await readLocalFont(absPath);
|
|
9406
|
+
if (font.kind === "file-backed") {
|
|
9407
|
+
dataUriByAbsolutePath.set(absPath, void 0);
|
|
9408
|
+
defaultLogger.debug(
|
|
9409
|
+
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
9410
|
+
);
|
|
9411
|
+
return void 0;
|
|
9412
|
+
}
|
|
9413
|
+
const { fontToDataUri } = await import("@hyperframes/core/fonts/embed");
|
|
9414
|
+
const dataUri = await fontToDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
9415
|
+
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
9416
|
+
defaultLogger.debug(
|
|
9417
|
+
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
9418
|
+
);
|
|
9419
|
+
return dataUri;
|
|
9420
|
+
} catch (error) {
|
|
9421
|
+
defaultLogger.warn(
|
|
9422
|
+
`[Compiler] Could not embed local font ${localPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
9423
|
+
);
|
|
9424
|
+
return void 0;
|
|
9425
|
+
}
|
|
9426
|
+
}
|
|
9427
|
+
var replaceInner = (whole, inner, tail, next) => whole.slice(0, whole.length - tail - inner.length) + next + whole.slice(whole.length - tail);
|
|
9428
|
+
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger) {
|
|
9429
|
+
const dataUriByPath = /* @__PURE__ */ new Map();
|
|
9255
9430
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
9256
|
-
const fileBackedAbsolutePaths = /* @__PURE__ */ new Set();
|
|
9257
9431
|
for (const { parts: style } of styleBlockMatches(html)) {
|
|
9258
9432
|
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
9259
|
-
const
|
|
9260
|
-
for (const { parts } of localFontFaceUrlMatches(block)) {
|
|
9433
|
+
for (const { parts } of localFontFaceUrlMatches(face[1])) {
|
|
9261
9434
|
const localPath = parts[1];
|
|
9262
|
-
if (!localPath ||
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
continue;
|
|
9268
|
-
}
|
|
9269
|
-
if (isPrivateCompositionFile(projectDir, absPath)) continue;
|
|
9270
|
-
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
9271
|
-
try {
|
|
9272
|
-
if (fileBackedAbsolutePaths.has(absPath)) {
|
|
9273
|
-
embeddedPaths.add(localPath);
|
|
9274
|
-
continue;
|
|
9275
|
-
}
|
|
9276
|
-
let dataUri = dataUriByAbsolutePath.get(absPath);
|
|
9277
|
-
if (!dataUri) {
|
|
9278
|
-
const font = await readLocalFont(absPath);
|
|
9279
|
-
if (font.kind === "file-backed") {
|
|
9280
|
-
fileBackedAbsolutePaths.add(absPath);
|
|
9281
|
-
defaultLogger.debug(
|
|
9282
|
-
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
9283
|
-
);
|
|
9284
|
-
embeddedPaths.add(localPath);
|
|
9285
|
-
continue;
|
|
9286
|
-
}
|
|
9287
|
-
dataUri = await toDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
9288
|
-
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
9289
|
-
defaultLogger.debug(
|
|
9290
|
-
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
9291
|
-
);
|
|
9292
|
-
}
|
|
9293
|
-
result = result.replace(urlOccurrenceRe(localPath), `url("${dataUri}")`);
|
|
9294
|
-
embeddedPaths.add(localPath);
|
|
9295
|
-
} catch (error) {
|
|
9296
|
-
defaultLogger.warn(
|
|
9297
|
-
`[Compiler] Could not embed local font ${localPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
9298
|
-
);
|
|
9299
|
-
}
|
|
9435
|
+
if (!localPath || dataUriByPath.has(localPath)) continue;
|
|
9436
|
+
dataUriByPath.set(
|
|
9437
|
+
localPath,
|
|
9438
|
+
await localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log)
|
|
9439
|
+
);
|
|
9300
9440
|
}
|
|
9301
9441
|
}
|
|
9302
9442
|
}
|
|
9303
|
-
return
|
|
9443
|
+
if (![...dataUriByPath.values()].some(Boolean)) return html;
|
|
9444
|
+
let warned = false;
|
|
9445
|
+
const embed = (source, localPath) => {
|
|
9446
|
+
const dataUri = dataUriByPath.get(localPath);
|
|
9447
|
+
if (!dataUri) return source;
|
|
9448
|
+
const inlined = `url("${dataUri}")`;
|
|
9449
|
+
if (budget.chargeGeneratedIfItFits(inlined.length - source.length)) return inlined;
|
|
9450
|
+
if (!warned) {
|
|
9451
|
+
warned = true;
|
|
9452
|
+
log.warn(
|
|
9453
|
+
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
9454
|
+
);
|
|
9455
|
+
}
|
|
9456
|
+
return source;
|
|
9457
|
+
};
|
|
9458
|
+
return replaceMatches(
|
|
9459
|
+
html,
|
|
9460
|
+
styleBlockMatches(html),
|
|
9461
|
+
(style, css) => replaceInner(
|
|
9462
|
+
style,
|
|
9463
|
+
css,
|
|
9464
|
+
"</style>".length,
|
|
9465
|
+
replaceMatches(
|
|
9466
|
+
css,
|
|
9467
|
+
fontFaceBlockMatches(css),
|
|
9468
|
+
(face, body) => replaceInner(face, body, 1, replaceMatches(body, localFontFaceUrlMatches(body), embed))
|
|
9469
|
+
)
|
|
9470
|
+
)
|
|
9471
|
+
);
|
|
9304
9472
|
}
|
|
9305
9473
|
function renderGsapDist() {
|
|
9306
9474
|
try {
|
|
@@ -9315,8 +9483,8 @@ function renderGsapDist() {
|
|
|
9315
9483
|
function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
9316
9484
|
let gsapDist;
|
|
9317
9485
|
const exists = (path) => {
|
|
9318
|
-
const file =
|
|
9319
|
-
return !namesAnotherNetworkRoot2(projectDir, file) &&
|
|
9486
|
+
const file = resolve8(projectDir, path);
|
|
9487
|
+
return !namesAnotherNetworkRoot2(projectDir, file) && existsSync12(file);
|
|
9320
9488
|
};
|
|
9321
9489
|
return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
|
|
9322
9490
|
if (/^https?:\/\//i.test(src)) return full;
|
|
@@ -9326,32 +9494,42 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
|
9326
9494
|
return `${prefix}${gsapDist}${file}${suffix}`;
|
|
9327
9495
|
});
|
|
9328
9496
|
}
|
|
9329
|
-
function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
|
|
9497
|
+
function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath, budget) {
|
|
9330
9498
|
if (!isPathInside(htmlPath, projectDir)) return html;
|
|
9331
|
-
const entryPath =
|
|
9499
|
+
const entryPath = relative3(projectDir, htmlPath).replace(/\\/g, "/");
|
|
9332
9500
|
if (!entryPath.includes("/")) return html;
|
|
9333
9501
|
const { document: document2 } = parseHTML5(html);
|
|
9334
9502
|
const assetExists = projectAssetExists(projectDir);
|
|
9503
|
+
const charge = (bytes) => budget.chargeGenerated(entryPath, bytes);
|
|
9335
9504
|
rewriteAssetPaths(
|
|
9336
9505
|
document2.querySelectorAll("[src], [href], [srcset]"),
|
|
9337
9506
|
entryPath,
|
|
9338
9507
|
(el, attr) => el.getAttribute(attr),
|
|
9339
9508
|
(el, attr, value) => el.setAttribute(attr, value),
|
|
9340
|
-
assetExists
|
|
9509
|
+
assetExists,
|
|
9510
|
+
charge
|
|
9341
9511
|
);
|
|
9342
9512
|
rewriteInlineStyleAssetUrls(
|
|
9343
9513
|
document2.querySelectorAll("[style]"),
|
|
9344
9514
|
entryPath,
|
|
9345
9515
|
(el) => el.getAttribute("style"),
|
|
9346
9516
|
(el, value) => el.setAttribute("style", value),
|
|
9347
|
-
assetExists
|
|
9517
|
+
assetExists,
|
|
9518
|
+
charge
|
|
9348
9519
|
);
|
|
9349
9520
|
for (const style of document2.querySelectorAll("style")) {
|
|
9350
|
-
style.textContent = rewriteCssAssetUrls(
|
|
9521
|
+
style.textContent = rewriteCssAssetUrls(
|
|
9522
|
+
style.textContent || "",
|
|
9523
|
+
entryPath,
|
|
9524
|
+
assetExists,
|
|
9525
|
+
charge
|
|
9526
|
+
);
|
|
9351
9527
|
}
|
|
9352
9528
|
return document2.toString();
|
|
9353
9529
|
}
|
|
9354
|
-
|
|
9530
|
+
var MAX_VARIABLE_MEDIA_SRC_BYTES = 8 * 1024;
|
|
9531
|
+
var MEDIA_SRC_CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
9532
|
+
function bindVariableMediaSources(html, variables, budget, log) {
|
|
9355
9533
|
if (!html.includes("data-var-src")) return html;
|
|
9356
9534
|
const { document: document2 } = parseHTML5(html);
|
|
9357
9535
|
const declared = {};
|
|
@@ -9362,14 +9540,23 @@ function bindVariableMediaSources(html, variables) {
|
|
|
9362
9540
|
let changed = false;
|
|
9363
9541
|
for (const el of document2.querySelectorAll("video[data-var-src], audio[data-var-src]")) {
|
|
9364
9542
|
if (el.closest("[data-variable-values]")) continue;
|
|
9365
|
-
const
|
|
9366
|
-
if (
|
|
9543
|
+
const bound = boundMediaSrc(el, values);
|
|
9544
|
+
if (bound === null) continue;
|
|
9545
|
+
const src = bound.trim();
|
|
9546
|
+
if (src.length > MAX_VARIABLE_MEDIA_SRC_BYTES || MEDIA_SRC_CONTROL_CHARS.test(src)) {
|
|
9547
|
+
log?.warn("[Compiler] Refused a variable media source that cannot be a URL", {
|
|
9548
|
+
length: src.length
|
|
9549
|
+
});
|
|
9550
|
+
continue;
|
|
9551
|
+
}
|
|
9552
|
+
if (el.getAttribute("src") === src) continue;
|
|
9553
|
+
budget.chargeGenerated("variable media sources", src.length);
|
|
9367
9554
|
el.setAttribute("src", src);
|
|
9368
9555
|
changed = true;
|
|
9369
9556
|
}
|
|
9370
9557
|
return changed ? document2.toString() : html;
|
|
9371
9558
|
}
|
|
9372
|
-
var entryFileName = (projectDir, htmlPath) => isPathInside(htmlPath, projectDir) ?
|
|
9559
|
+
var entryFileName = (projectDir, htmlPath) => isPathInside(htmlPath, projectDir) ? relative3(projectDir, htmlPath).split(sep4).join("/") : basename6(htmlPath);
|
|
9373
9560
|
async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
|
|
9374
9561
|
const assetRoot = options.allowOutsideProjectAssets ? void 0 : projectDir;
|
|
9375
9562
|
const outsideFiles = { includeScripts: options.includeOutsideScripts };
|
|
@@ -9382,11 +9569,19 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9382
9569
|
if (!COMPOSITION_FILE.test(htmlPath)) {
|
|
9383
9570
|
throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
|
|
9384
9571
|
}
|
|
9385
|
-
assertCompositionFileSize(htmlPath,
|
|
9386
|
-
const
|
|
9572
|
+
assertCompositionFileSize(htmlPath, basename6(htmlPath));
|
|
9573
|
+
const budget = new CompositionExpansionBudget();
|
|
9574
|
+
const entryHtml = rebaseDirectEntryAssetPaths(
|
|
9575
|
+
readTextFile(htmlPath),
|
|
9576
|
+
projectDir,
|
|
9577
|
+
htmlPath,
|
|
9578
|
+
budget
|
|
9579
|
+
);
|
|
9387
9580
|
const rawHtml = bindVariableMediaSources(
|
|
9388
9581
|
normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
|
|
9389
|
-
options.variables ?? {}
|
|
9582
|
+
options.variables ?? {},
|
|
9583
|
+
budget,
|
|
9584
|
+
options.log
|
|
9390
9585
|
);
|
|
9391
9586
|
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
|
|
9392
9587
|
const probes = /* @__PURE__ */ new Map();
|
|
@@ -9417,7 +9612,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9417
9612
|
projectDir,
|
|
9418
9613
|
options.variables ?? {},
|
|
9419
9614
|
assetRoot,
|
|
9420
|
-
outsideFiles
|
|
9615
|
+
outsideFiles,
|
|
9616
|
+
budget
|
|
9421
9617
|
);
|
|
9422
9618
|
const sanitizedHtml = stripPreloadNone(inlinedHtml);
|
|
9423
9619
|
const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
|
|
@@ -9425,7 +9621,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9425
9621
|
const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
|
|
9426
9622
|
const hasAncestorBackgroundImage = detectAncestorBackgroundImage(sanitizedHtml);
|
|
9427
9623
|
const fontSheetHtml = await inlineExternalFontStylesheets(
|
|
9428
|
-
promoteCssImportsToLinkTags(sanitizedHtml)
|
|
9624
|
+
promoteCssImportsToLinkTags(sanitizedHtml),
|
|
9625
|
+
budget
|
|
9429
9626
|
);
|
|
9430
9627
|
const normalizedFontHtml = normalizeSystemFontPrimaryFamilies(
|
|
9431
9628
|
injectTextRenderingRule(coalesceHeadStylesAndBodyScripts(fontSheetHtml))
|
|
@@ -9437,7 +9634,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9437
9634
|
projectFontFamilies: projectStylesheetFontFamilies(fontSheetHtml, projectDir),
|
|
9438
9635
|
abortSignal: options.abortSignal
|
|
9439
9636
|
});
|
|
9440
|
-
const assembledHtml = await inlineExternalScripts(coalescedHtml);
|
|
9637
|
+
const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
|
|
9441
9638
|
const HF_POSITION_ATTRS = [
|
|
9442
9639
|
'data-hf-studio-path-offset="true"',
|
|
9443
9640
|
'data-hf-studio-box-size="true"',
|
|
@@ -9496,6 +9693,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9496
9693
|
htmlWithPreparedGifs,
|
|
9497
9694
|
projectDir,
|
|
9498
9695
|
assetRoot,
|
|
9696
|
+
budget,
|
|
9499
9697
|
options.log
|
|
9500
9698
|
);
|
|
9501
9699
|
const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
|
|
@@ -9528,8 +9726,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9528
9726
|
const advised = /* @__PURE__ */ new Set();
|
|
9529
9727
|
for (const video of videos) {
|
|
9530
9728
|
if (isHttpUrl(video.src)) continue;
|
|
9531
|
-
const videoPath =
|
|
9532
|
-
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !
|
|
9729
|
+
const videoPath = resolve8(projectDir, video.src);
|
|
9730
|
+
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync12(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
|
|
9533
9731
|
continue;
|
|
9534
9732
|
advised.add(videoPath);
|
|
9535
9733
|
const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
|
|
@@ -9944,7 +10142,7 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
|
|
|
9944
10142
|
function animatedGifCacheDir(extractCacheDir) {
|
|
9945
10143
|
try {
|
|
9946
10144
|
const root = extractCacheDir && privateCacheRoot(extractCacheDir);
|
|
9947
|
-
return root ?
|
|
10145
|
+
return root ? join21(root, "animated-gif") : void 0;
|
|
9948
10146
|
} catch {
|
|
9949
10147
|
return void 0;
|
|
9950
10148
|
}
|
|
@@ -9966,17 +10164,17 @@ function resolveEntryHtmlPath(input) {
|
|
|
9966
10164
|
const readEntry = (path) => {
|
|
9967
10165
|
if (escapesAssetRoot(path, input.assetRoot)) {
|
|
9968
10166
|
throw new Error(
|
|
9969
|
-
`Entry file "${
|
|
10167
|
+
`Entry file "${relative4(projectDir, path)}" leads outside the project folder`
|
|
9970
10168
|
);
|
|
9971
10169
|
}
|
|
9972
|
-
assertCompositionFileSize(path,
|
|
10170
|
+
assertCompositionFileSize(path, relative4(projectDir, path));
|
|
9973
10171
|
return readTextFile2(path);
|
|
9974
10172
|
};
|
|
9975
|
-
const htmlPath =
|
|
10173
|
+
const htmlPath = join21(projectDir, entryFile);
|
|
9976
10174
|
const rawEntry = readEntry(htmlPath);
|
|
9977
10175
|
if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
|
|
9978
|
-
const projectIndexPath =
|
|
9979
|
-
if (!
|
|
10176
|
+
const projectIndexPath = join21(projectDir, "index.html");
|
|
10177
|
+
if (!existsSync13(projectIndexPath)) {
|
|
9980
10178
|
throw new Error(
|
|
9981
10179
|
`Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
|
|
9982
10180
|
);
|
|
@@ -9991,7 +10189,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
9991
10189
|
`Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`
|
|
9992
10190
|
);
|
|
9993
10191
|
}
|
|
9994
|
-
const wrapperPath =
|
|
10192
|
+
const wrapperPath = join21(workDir, "standalone-entry.html");
|
|
9995
10193
|
writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
|
|
9996
10194
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
9997
10195
|
return wrapperPath;
|
|
@@ -10021,7 +10219,7 @@ async function runCompileStage(input) {
|
|
|
10021
10219
|
const assetRoot = job.config.allowOutsideProjectAssets ? void 0 : projectDir;
|
|
10022
10220
|
const htmlPath = resolveEntryHtmlPath({ projectDir, workDir, entryFile, log, assetRoot });
|
|
10023
10221
|
const compileStart = Date.now();
|
|
10024
|
-
const compiled = await compileForRender(projectDir, htmlPath,
|
|
10222
|
+
const compiled = await compileForRender(projectDir, htmlPath, join21(workDir, "downloads"), {
|
|
10025
10223
|
log,
|
|
10026
10224
|
failClosedFontFetch: failClosedFontFetch === true,
|
|
10027
10225
|
allowSystemFontCapture,
|
|
@@ -10096,7 +10294,7 @@ async function runCompileStage(input) {
|
|
|
10096
10294
|
});
|
|
10097
10295
|
await preflightCompositionAssetMediaTypes({
|
|
10098
10296
|
projectDir,
|
|
10099
|
-
compiledDir:
|
|
10297
|
+
compiledDir: join21(workDir, "compiled"),
|
|
10100
10298
|
composition,
|
|
10101
10299
|
signal: abortSignal
|
|
10102
10300
|
});
|
|
@@ -10144,7 +10342,7 @@ async function runCompileStage(input) {
|
|
|
10144
10342
|
|
|
10145
10343
|
// src/services/render/stages/probeStage.ts
|
|
10146
10344
|
import { createHash as createHash7 } from "node:crypto";
|
|
10147
|
-
import { basename as
|
|
10345
|
+
import { basename as basename7, join as join22 } from "node:path";
|
|
10148
10346
|
import { parseHTML as parseHTML6 } from "linkedom";
|
|
10149
10347
|
import {
|
|
10150
10348
|
closeCaptureSession as closeCaptureSession4,
|
|
@@ -10392,7 +10590,7 @@ function probeRequiresBrowser(args) {
|
|
|
10392
10590
|
function reportedLengthSource(source) {
|
|
10393
10591
|
if (!source) return null;
|
|
10394
10592
|
if (source.from !== "media") return { from: source.from };
|
|
10395
|
-
const name =
|
|
10593
|
+
const name = basename7(source.src.split(/[?#]/, 1)[0] ?? "");
|
|
10396
10594
|
const srcHash = createHash7("sha256").update(name).digest("hex").slice(0, 12);
|
|
10397
10595
|
return { from: "media", tag: source.tag, trimmed: source.trimmed, srcHash };
|
|
10398
10596
|
}
|
|
@@ -10458,7 +10656,7 @@ async function runProbeStage(input) {
|
|
|
10458
10656
|
});
|
|
10459
10657
|
fileServer = await createFileServer({
|
|
10460
10658
|
projectDir,
|
|
10461
|
-
compiledDir:
|
|
10659
|
+
compiledDir: join22(workDir, "compiled"),
|
|
10462
10660
|
port: 0,
|
|
10463
10661
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
10464
10662
|
fps: job.config.fps,
|
|
@@ -10495,7 +10693,7 @@ async function runProbeStage(input) {
|
|
|
10495
10693
|
log.info("Creating capture session...", { attempt, maxAttempts: PROBE_MAX_ATTEMPTS });
|
|
10496
10694
|
probeSession = await createCaptureSession4(
|
|
10497
10695
|
fileServer.url,
|
|
10498
|
-
|
|
10696
|
+
join22(workDir, "probe"),
|
|
10499
10697
|
captureOpts,
|
|
10500
10698
|
null,
|
|
10501
10699
|
probeCfg
|
|
@@ -10580,7 +10778,7 @@ async function runProbeStage(input) {
|
|
|
10580
10778
|
});
|
|
10581
10779
|
probeSession = await createCaptureSession4(
|
|
10582
10780
|
fileServer.url,
|
|
10583
|
-
|
|
10781
|
+
join22(workDir, "probe-screenshot"),
|
|
10584
10782
|
captureOpts,
|
|
10585
10783
|
null,
|
|
10586
10784
|
{ ...probeCfg, forceScreenshot: true }
|
|
@@ -10618,7 +10816,7 @@ async function runProbeStage(input) {
|
|
|
10618
10816
|
compiled,
|
|
10619
10817
|
resolutions,
|
|
10620
10818
|
projectDir,
|
|
10621
|
-
|
|
10819
|
+
join22(workDir, "downloads"),
|
|
10622
10820
|
job.config.allowOutsideProjectAssets ? void 0 : projectDir,
|
|
10623
10821
|
{ includeScripts: job.config.includeOutsideScripts }
|
|
10624
10822
|
);
|
|
@@ -10818,7 +11016,7 @@ async function runProbeStage(input) {
|
|
|
10818
11016
|
});
|
|
10819
11017
|
await preflightCompositionAssetMediaTypes({
|
|
10820
11018
|
projectDir,
|
|
10821
|
-
compiledDir:
|
|
11019
|
+
compiledDir: join22(workDir, "compiled"),
|
|
10822
11020
|
composition,
|
|
10823
11021
|
signal: abortSignal
|
|
10824
11022
|
});
|
|
@@ -10985,8 +11183,8 @@ function validateDistributedDuration(input) {
|
|
|
10985
11183
|
}
|
|
10986
11184
|
|
|
10987
11185
|
// src/services/render/stages/extractVideosStage.ts
|
|
10988
|
-
import { existsSync as
|
|
10989
|
-
import { join as
|
|
11186
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
11187
|
+
import { join as join23 } from "node:path";
|
|
10990
11188
|
import {
|
|
10991
11189
|
classifyVideoExtractionError,
|
|
10992
11190
|
createFrameLookupTable as createFrameLookupTable3,
|
|
@@ -11350,7 +11548,7 @@ async function runExtractVideosStage(input) {
|
|
|
11350
11548
|
// because short boundary counts can differ by one frame.
|
|
11351
11549
|
{
|
|
11352
11550
|
fps: job.config.fps,
|
|
11353
|
-
outputDir:
|
|
11551
|
+
outputDir: join23(compiledDir, "__hyperframes_video_frames"),
|
|
11354
11552
|
format: job.config.videoFrameFormat ?? "auto",
|
|
11355
11553
|
toneMapHdrToSdr: rendersSdrOnly(job.config, composition),
|
|
11356
11554
|
timelineEnd: composition.duration,
|
|
@@ -11358,7 +11556,7 @@ async function runExtractVideosStage(input) {
|
|
|
11358
11556
|
collectProbeFailures: extractionPolicy.failureMode === "enforce",
|
|
11359
11557
|
deferRangeExtraction,
|
|
11360
11558
|
shownBoxes,
|
|
11361
|
-
contentKeyedDirs: [
|
|
11559
|
+
contentKeyedDirs: [join23(compiledDir, REMOTE_MEDIA_SUBDIR)],
|
|
11362
11560
|
urlByAbsentLocalPath,
|
|
11363
11561
|
assetRoots,
|
|
11364
11562
|
onProgress: ({ planned = 0, done = 0 }) => {
|
|
@@ -11438,7 +11636,7 @@ function isPublicHttpsUrl(url) {
|
|
|
11438
11636
|
}
|
|
11439
11637
|
}
|
|
11440
11638
|
function opensLocally(path, assetRoots) {
|
|
11441
|
-
return
|
|
11639
|
+
return existsSync14(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
|
|
11442
11640
|
}
|
|
11443
11641
|
function localProbeSource(src, input) {
|
|
11444
11642
|
const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
|
|
@@ -11450,7 +11648,7 @@ async function remoteProbeSource(video, input) {
|
|
|
11450
11648
|
if (!isPublicHttpsUrl(video.src)) return null;
|
|
11451
11649
|
if (!resolveRestrictPageNetwork()) return video.src;
|
|
11452
11650
|
if (!video.hasAudio || video.hidden) return null;
|
|
11453
|
-
const downloadDir = input.downloadDir ??
|
|
11651
|
+
const downloadDir = input.downloadDir ?? join23(input.compiledDir, REMOTE_MEDIA_SUBDIR);
|
|
11454
11652
|
try {
|
|
11455
11653
|
return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
|
|
11456
11654
|
onTelemetry: writeUrlDownloadTelemetry2
|
|
@@ -11491,7 +11689,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
11491
11689
|
}
|
|
11492
11690
|
|
|
11493
11691
|
// src/services/render/videoLayerPassthroughPlan.ts
|
|
11494
|
-
import { existsSync as
|
|
11692
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
11495
11693
|
import {
|
|
11496
11694
|
buildVideoLayerInput,
|
|
11497
11695
|
isHttpUrl as isHttpUrl4,
|
|
@@ -11559,7 +11757,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
11559
11757
|
const { video } = q;
|
|
11560
11758
|
if (isHttpUrl4(video.src)) return { reason: "remote_source" };
|
|
11561
11759
|
const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
|
|
11562
|
-
if (!
|
|
11760
|
+
if (!existsSync15(path)) return { reason: "source_missing" };
|
|
11563
11761
|
const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
|
|
11564
11762
|
if ("reason" in layout) return layout;
|
|
11565
11763
|
const layer = await buildVideoLayerInput(
|
|
@@ -11574,8 +11772,8 @@ async function planVideoLayerPassthrough(input) {
|
|
|
11574
11772
|
}
|
|
11575
11773
|
|
|
11576
11774
|
// src/services/render/stages/audioStage.ts
|
|
11577
|
-
import { existsSync as
|
|
11578
|
-
import { join as
|
|
11775
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
11776
|
+
import { join as join26 } from "node:path";
|
|
11579
11777
|
import {
|
|
11580
11778
|
MIXED_AUDIO_FILENAME,
|
|
11581
11779
|
audioFailureDiagnostics,
|
|
@@ -11586,8 +11784,8 @@ import {
|
|
|
11586
11784
|
} from "@hyperframes/engine";
|
|
11587
11785
|
|
|
11588
11786
|
// src/services/render/audioDeliveryLimit.ts
|
|
11589
|
-
import { existsSync as
|
|
11590
|
-
import { dirname as dirname11, join as
|
|
11787
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
11788
|
+
import { dirname as dirname11, join as join25 } from "node:path";
|
|
11591
11789
|
import {
|
|
11592
11790
|
applyAudioFxChain,
|
|
11593
11791
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -11597,7 +11795,7 @@ import {
|
|
|
11597
11795
|
|
|
11598
11796
|
// src/services/render/audioPadTrim.ts
|
|
11599
11797
|
import { spawn } from "node:child_process";
|
|
11600
|
-
import { dirname as dirname10, join as
|
|
11798
|
+
import { dirname as dirname10, join as join24 } from "node:path";
|
|
11601
11799
|
import {
|
|
11602
11800
|
DEFAULT_CONFIG,
|
|
11603
11801
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -11878,7 +12076,7 @@ async function constrainAacTruePeak(input) {
|
|
|
11878
12076
|
}
|
|
11879
12077
|
async function cutSource(input, scratchDir, attenuationDb) {
|
|
11880
12078
|
if (!input.sourcePath || !input.rewriteSource) return true;
|
|
11881
|
-
const cutPath =
|
|
12079
|
+
const cutPath = join24(scratchDir, "source.wav");
|
|
11882
12080
|
try {
|
|
11883
12081
|
const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
|
|
11884
12082
|
if (!result.success) throw new Error(result.error);
|
|
@@ -11893,7 +12091,7 @@ async function enforceAacTruePeak(input) {
|
|
|
11893
12091
|
let scratchDir;
|
|
11894
12092
|
try {
|
|
11895
12093
|
scratchDir = createStagingDir3(dirname10(input.audioPath), ".true-peak-");
|
|
11896
|
-
const correctedPath =
|
|
12094
|
+
const correctedPath = join24(scratchDir, "audio.m4a");
|
|
11897
12095
|
const measurements = [];
|
|
11898
12096
|
let attenuationDb = 0;
|
|
11899
12097
|
let sourcePeakDbfs;
|
|
@@ -12106,14 +12304,14 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
12106
12304
|
applyChain: applyAudioFxChain,
|
|
12107
12305
|
encode: encodeAac2,
|
|
12108
12306
|
rename: renameWithRetry6,
|
|
12109
|
-
sourceExists:
|
|
12307
|
+
sourceExists: existsSync16
|
|
12110
12308
|
}) {
|
|
12111
12309
|
const { audioPath, sourcePath, signal, timeoutMs } = input;
|
|
12112
12310
|
if (!deps.sourceExists(sourcePath)) return { success: true };
|
|
12113
12311
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
12114
12312
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
12115
12313
|
const alternating = ["a", "b"].map(
|
|
12116
|
-
(k) =>
|
|
12314
|
+
(k) => join25(dirname11(sourcePath), `audio-source-limited-${k}.wav`)
|
|
12117
12315
|
);
|
|
12118
12316
|
let encodedFrom;
|
|
12119
12317
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -12186,7 +12384,7 @@ function runAudioStage(input) {
|
|
|
12186
12384
|
}
|
|
12187
12385
|
async function runAudioStageScoped(input) {
|
|
12188
12386
|
const stageStart = Date.now();
|
|
12189
|
-
const pcmSourcePath =
|
|
12387
|
+
const pcmSourcePath = join26(input.workDir, "audio-source.wav");
|
|
12190
12388
|
const duration = input.totalFrames * input.fps.den / input.fps.num;
|
|
12191
12389
|
let deliverySourcePath;
|
|
12192
12390
|
try {
|
|
@@ -12202,7 +12400,7 @@ async function runAudioStageScoped(input) {
|
|
|
12202
12400
|
);
|
|
12203
12401
|
audioLoweredDb = guard.loweredDb;
|
|
12204
12402
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
12205
|
-
if (input.keepDeliverySource && !guard.sourceStale &&
|
|
12403
|
+
if (input.keepDeliverySource && !guard.sourceStale && existsSync17(pcmSourcePath)) {
|
|
12206
12404
|
deliverySourcePath = pcmSourcePath;
|
|
12207
12405
|
}
|
|
12208
12406
|
}
|
|
@@ -12251,7 +12449,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
12251
12449
|
assertNotAborted,
|
|
12252
12450
|
log
|
|
12253
12451
|
} = input;
|
|
12254
|
-
const audioOutputPath =
|
|
12452
|
+
const audioOutputPath = join26(workDir, MIXED_AUDIO_FILENAME);
|
|
12255
12453
|
let hasAudio = false;
|
|
12256
12454
|
let audioError;
|
|
12257
12455
|
let audioFailures;
|
|
@@ -12331,8 +12529,8 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
12331
12529
|
}
|
|
12332
12530
|
|
|
12333
12531
|
// src/services/render/stages/captureStage.ts
|
|
12334
|
-
import { existsSync as
|
|
12335
|
-
import { join as
|
|
12532
|
+
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
12533
|
+
import { join as join27 } from "node:path";
|
|
12336
12534
|
import {
|
|
12337
12535
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
12338
12536
|
frameFileExtension,
|
|
@@ -12402,16 +12600,16 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
|
|
|
12402
12600
|
}
|
|
12403
12601
|
function measureCaptureFrameBytes(workDir, framesDir) {
|
|
12404
12602
|
let total = sampleDirectoryBytes(framesDir);
|
|
12405
|
-
if (!
|
|
12603
|
+
if (!existsSync18(workDir)) return total;
|
|
12406
12604
|
for (const attempt of readdirSync4(workDir)) {
|
|
12407
12605
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
12408
|
-
total += sampleDirectoryBytes(
|
|
12606
|
+
total += sampleDirectoryBytes(join27(workDir, attempt));
|
|
12409
12607
|
continue;
|
|
12410
12608
|
}
|
|
12411
12609
|
if (!/^capture-attempt-\d+$/.test(attempt)) continue;
|
|
12412
|
-
const attemptDir =
|
|
12610
|
+
const attemptDir = join27(workDir, attempt);
|
|
12413
12611
|
for (const name of readdirSync4(attemptDir)) {
|
|
12414
|
-
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(
|
|
12612
|
+
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join27(attemptDir, name));
|
|
12415
12613
|
}
|
|
12416
12614
|
}
|
|
12417
12615
|
return total;
|
|
@@ -12709,8 +12907,8 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
12709
12907
|
}
|
|
12710
12908
|
|
|
12711
12909
|
// src/services/render/stages/captureHdrStage.ts
|
|
12712
|
-
import { existsSync as
|
|
12713
|
-
import { join as
|
|
12910
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync10 } from "node:fs";
|
|
12911
|
+
import { join as join31 } from "node:path";
|
|
12714
12912
|
import {
|
|
12715
12913
|
closeCaptureSession as closeCaptureSession7,
|
|
12716
12914
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
@@ -12782,7 +12980,7 @@ function createHdrImageTransferCache(options = {}) {
|
|
|
12782
12980
|
}
|
|
12783
12981
|
|
|
12784
12982
|
// src/services/render/stages/captureHdrSequentialLoop.ts
|
|
12785
|
-
import { join as
|
|
12983
|
+
import { join as join28 } from "node:path";
|
|
12786
12984
|
import {
|
|
12787
12985
|
TRANSITIONS,
|
|
12788
12986
|
crossfade
|
|
@@ -12907,7 +13105,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
12907
13105
|
);
|
|
12908
13106
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
12909
13107
|
writeFileExclusiveSync(
|
|
12910
|
-
|
|
13108
|
+
join28(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
12911
13109
|
normalCanvas
|
|
12912
13110
|
);
|
|
12913
13111
|
}
|
|
@@ -12939,7 +13137,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
12939
13137
|
}
|
|
12940
13138
|
|
|
12941
13139
|
// src/services/render/stages/captureHdrHybridLoop.ts
|
|
12942
|
-
import { join as
|
|
13140
|
+
import { join as join30 } from "node:path";
|
|
12943
13141
|
import {
|
|
12944
13142
|
TRANSITIONS as TRANSITIONS2,
|
|
12945
13143
|
closeCaptureSession as closeCaptureSession6,
|
|
@@ -12953,10 +13151,10 @@ import {
|
|
|
12953
13151
|
// src/services/shaderTransitionWorkerPool.ts
|
|
12954
13152
|
import { Worker } from "node:worker_threads";
|
|
12955
13153
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
12956
|
-
import { dirname as dirname12, join as
|
|
13154
|
+
import { dirname as dirname12, join as join29 } from "node:path";
|
|
12957
13155
|
import { createRequire } from "node:module";
|
|
12958
13156
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
12959
|
-
import { existsSync as
|
|
13157
|
+
import { existsSync as existsSync19 } from "node:fs";
|
|
12960
13158
|
function resolveWorkerEntry(explicit) {
|
|
12961
13159
|
if (explicit && explicit.length > 0) {
|
|
12962
13160
|
return { path: explicit, isTs: explicit.endsWith(".ts") };
|
|
@@ -12967,9 +13165,9 @@ function resolveWorkerEntry(explicit) {
|
|
|
12967
13165
|
return { path: override, isTs };
|
|
12968
13166
|
}
|
|
12969
13167
|
const moduleDir = dirname12(fileURLToPath3(import.meta.url));
|
|
12970
|
-
const jsPath =
|
|
12971
|
-
if (
|
|
12972
|
-
const tsPath =
|
|
13168
|
+
const jsPath = join29(moduleDir, "shaderTransitionWorker.js");
|
|
13169
|
+
if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
|
|
13170
|
+
const tsPath = join29(moduleDir, "shaderTransitionWorker.ts");
|
|
12973
13171
|
return { path: tsPath, isTs: true };
|
|
12974
13172
|
}
|
|
12975
13173
|
function buildExecArgv(entryIsTs) {
|
|
@@ -13112,8 +13310,8 @@ async function createShaderTransitionWorkerPool(opts) {
|
|
|
13112
13310
|
if (terminated) {
|
|
13113
13311
|
throw new Error("shader-blend pool already terminated");
|
|
13114
13312
|
}
|
|
13115
|
-
return new Promise((
|
|
13116
|
-
const task = traceEnabled ? { req, resolve:
|
|
13313
|
+
return new Promise((resolve14, reject) => {
|
|
13314
|
+
const task = traceEnabled ? { req, resolve: resolve14, reject, enqueuedAtMs: Date.now(), traceId: ++nextTaskId } : { req, resolve: resolve14, reject };
|
|
13117
13315
|
const idle = slots.find((s) => !s.busy && !s.dead);
|
|
13118
13316
|
if (idle) {
|
|
13119
13317
|
queue.unshift(task);
|
|
@@ -13337,7 +13535,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
13337
13535
|
);
|
|
13338
13536
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
13339
13537
|
writeFileExclusiveSync(
|
|
13340
|
-
|
|
13538
|
+
join30(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
13341
13539
|
canvas
|
|
13342
13540
|
);
|
|
13343
13541
|
}
|
|
@@ -13533,8 +13731,8 @@ async function runCaptureHdrStage(input) {
|
|
|
13533
13731
|
if (hdrVideoFrameSources.has(v.id)) hdrVideoEndTimes.set(v.id, v.end);
|
|
13534
13732
|
}
|
|
13535
13733
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
13536
|
-
const debugDumpDir = debugDumpEnabled ?
|
|
13537
|
-
if (debugDumpDir && !
|
|
13734
|
+
const debugDumpDir = debugDumpEnabled ? join31(framesDir, "debug-composite") : null;
|
|
13735
|
+
if (debugDumpDir && !existsSync20(debugDumpDir)) {
|
|
13538
13736
|
mkdirSync10(debugDumpDir, { recursive: true });
|
|
13539
13737
|
}
|
|
13540
13738
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
@@ -13693,7 +13891,7 @@ async function runCaptureHdrStage(input) {
|
|
|
13693
13891
|
// src/services/render/stages/encodeStage.ts
|
|
13694
13892
|
import {
|
|
13695
13893
|
copyFileSync as copyFileSync4,
|
|
13696
|
-
existsSync as
|
|
13894
|
+
existsSync as existsSync21,
|
|
13697
13895
|
mkdirSync as mkdirSync11,
|
|
13698
13896
|
readdirSync as readdirSync5,
|
|
13699
13897
|
readFileSync as readFileSync9,
|
|
@@ -13702,7 +13900,7 @@ import {
|
|
|
13702
13900
|
writeFileSync as writeFileSync6
|
|
13703
13901
|
} from "node:fs";
|
|
13704
13902
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
13705
|
-
import { dirname as dirname13, join as
|
|
13903
|
+
import { dirname as dirname13, join as join32 } from "node:path";
|
|
13706
13904
|
import {
|
|
13707
13905
|
encodeFramesChunkedConcat,
|
|
13708
13906
|
encodeFramesFromDir,
|
|
@@ -13827,7 +14025,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
13827
14025
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
13828
14026
|
if (failure) return failure;
|
|
13829
14027
|
}
|
|
13830
|
-
const fileSize =
|
|
14028
|
+
const fileSize = existsSync21(outputPath) ? statSync10(outputPath).size : 0;
|
|
13831
14029
|
return {
|
|
13832
14030
|
success: true,
|
|
13833
14031
|
outputPath,
|
|
@@ -13918,10 +14116,10 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
13918
14116
|
const stream = await encoder;
|
|
13919
14117
|
for (let next = 0; next < totalFrames; next++) {
|
|
13920
14118
|
while (!landed.has(next) && !captureDone && !signal.aborted) {
|
|
13921
|
-
await new Promise((
|
|
14119
|
+
await new Promise((resolve14) => wake = resolve14);
|
|
13922
14120
|
}
|
|
13923
14121
|
if (signal.aborted) return;
|
|
13924
|
-
const mergedPath =
|
|
14122
|
+
const mergedPath = join32(input.framesDir, formatCaptureFrameName(next, "jpg"));
|
|
13925
14123
|
const frame = await readLandedFrame(landed.get(next), mergedPath);
|
|
13926
14124
|
landed.delete(next);
|
|
13927
14125
|
if (!await stream.writeFrame(frame)) {
|
|
@@ -13996,7 +14194,7 @@ async function runEncodeStage(input) {
|
|
|
13996
14194
|
const stage5Start = Date.now();
|
|
13997
14195
|
if (isPngSequence) {
|
|
13998
14196
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
13999
|
-
if (!
|
|
14197
|
+
if (!existsSync21(outputPath)) mkdirSync11(outputPath, { recursive: true });
|
|
14000
14198
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
14001
14199
|
if (captured.length === 0) {
|
|
14002
14200
|
throw new Error(
|
|
@@ -14004,11 +14202,11 @@ async function runEncodeStage(input) {
|
|
|
14004
14202
|
);
|
|
14005
14203
|
}
|
|
14006
14204
|
captured.forEach((name, i) => {
|
|
14007
|
-
const dst =
|
|
14008
|
-
copyFileSync4(
|
|
14205
|
+
const dst = join32(outputPath, formatExportFrameName(i, "png"));
|
|
14206
|
+
copyFileSync4(join32(framesDir, name), dst);
|
|
14009
14207
|
});
|
|
14010
|
-
if (hasAudio && audioOutputPath &&
|
|
14011
|
-
copyFileSync4(audioOutputPath,
|
|
14208
|
+
if (hasAudio && audioOutputPath && existsSync21(audioOutputPath)) {
|
|
14209
|
+
copyFileSync4(audioOutputPath, join32(outputPath, MIXED_AUDIO_FILENAME2));
|
|
14012
14210
|
log.info(
|
|
14013
14211
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
14014
14212
|
);
|
|
@@ -14028,7 +14226,7 @@ async function runEncodeStage(input) {
|
|
|
14028
14226
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
14029
14227
|
fps: job.config.fps,
|
|
14030
14228
|
loop,
|
|
14031
|
-
palettePath:
|
|
14229
|
+
palettePath: join32(dirname13(videoOnlyPath), "gif-palette.png"),
|
|
14032
14230
|
preserveAlpha: needsAlpha,
|
|
14033
14231
|
signal: abortSignal,
|
|
14034
14232
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -14239,7 +14437,7 @@ function sampleDirectoryBytes(dir) {
|
|
|
14239
14437
|
continue;
|
|
14240
14438
|
}
|
|
14241
14439
|
for (const name of entries) {
|
|
14242
|
-
const full =
|
|
14440
|
+
const full = join33(current, name);
|
|
14243
14441
|
try {
|
|
14244
14442
|
const st = statSync11(full);
|
|
14245
14443
|
if (st.isDirectory()) {
|
|
@@ -14275,6 +14473,7 @@ function summarizeExtractionObservability(extractionResult, videoCount, coverage
|
|
|
14275
14473
|
vfrPreflightCount: phaseBreakdown?.vfrPreflightCount,
|
|
14276
14474
|
cacheHits: phaseBreakdown?.cacheHits,
|
|
14277
14475
|
cacheMisses: phaseBreakdown?.cacheMisses,
|
|
14476
|
+
cachePublishFailures: phaseBreakdown?.cachePublishFailures,
|
|
14278
14477
|
transientRetries: phaseBreakdown?.transientRetries,
|
|
14279
14478
|
...coverageGauges,
|
|
14280
14479
|
authoredTimedClipCount
|
|
@@ -14396,8 +14595,8 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
14396
14595
|
const ranges = [];
|
|
14397
14596
|
let rangeStart = null;
|
|
14398
14597
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14399
|
-
const framePath =
|
|
14400
|
-
const missing = !
|
|
14598
|
+
const framePath = join33(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
14599
|
+
const missing = !existsSync22(framePath) || statSync11(framePath).size <= 8;
|
|
14401
14600
|
if (missing && rangeStart === null) {
|
|
14402
14601
|
rangeStart = frameIndex;
|
|
14403
14602
|
} else if (!missing && rangeStart !== null) {
|
|
@@ -14413,7 +14612,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
14413
14612
|
function buildMissingFrameRetryBatches(ranges, maxWorkers, workDir, attempt, rangeStart = 0, stride = 1) {
|
|
14414
14613
|
const workersPerBatch = Math.max(1, Math.floor(maxWorkers));
|
|
14415
14614
|
const batches = [];
|
|
14416
|
-
const outputDirFor = (batchIndex, workerId) =>
|
|
14615
|
+
const outputDirFor = (batchIndex, workerId) => join33(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
|
|
14417
14616
|
if (stride > 1) {
|
|
14418
14617
|
const spans = /* @__PURE__ */ new Map();
|
|
14419
14618
|
for (const range of ranges) {
|
|
@@ -14472,9 +14671,9 @@ function createCaptureObservabilityUpdater(observability, platform2 = process.pl
|
|
|
14472
14671
|
function getNextRetryWorkerCount(currentWorkers) {
|
|
14473
14672
|
return Math.max(1, Math.floor(currentWorkers / 2));
|
|
14474
14673
|
}
|
|
14475
|
-
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir =
|
|
14476
|
-
if (platform2 === "win32" || platform2 === "darwin") return
|
|
14477
|
-
return
|
|
14674
|
+
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir3()) {
|
|
14675
|
+
if (platform2 === "win32" || platform2 === "darwin") return join33(systemTempDir, "hf-render-");
|
|
14676
|
+
return join33(dirname14(outputPath), `work-${jobId}-`);
|
|
14478
14677
|
}
|
|
14479
14678
|
var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
|
|
14480
14679
|
function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
|
|
@@ -14529,8 +14728,8 @@ The composition is too large for the available memory. To reduce memory pressure
|
|
|
14529
14728
|
function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
14530
14729
|
let captured = 0;
|
|
14531
14730
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14532
|
-
const framePath =
|
|
14533
|
-
if (
|
|
14731
|
+
const framePath = join33(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
14732
|
+
if (existsSync22(framePath)) captured++;
|
|
14534
14733
|
}
|
|
14535
14734
|
return captured;
|
|
14536
14735
|
}
|
|
@@ -14555,7 +14754,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
14555
14754
|
reason: attempt === 0 ? "initial" : pendingTransientRetry ? "transient-retry" : "retry"
|
|
14556
14755
|
});
|
|
14557
14756
|
pendingTransientRetry = false;
|
|
14558
|
-
const attemptWorkDir =
|
|
14757
|
+
const attemptWorkDir = join33(options.workDir, `capture-attempt-${attempt}`);
|
|
14559
14758
|
const batches = missingRanges ? buildMissingFrameRetryBatches(
|
|
14560
14759
|
missingRanges,
|
|
14561
14760
|
currentWorkers,
|
|
@@ -15202,8 +15401,8 @@ function deVerifyFallbackTelemetry(err) {
|
|
|
15202
15401
|
};
|
|
15203
15402
|
}
|
|
15204
15403
|
function resolveRenderDebugDir() {
|
|
15205
|
-
const producerRoot = process.env.PRODUCER_RENDERS_DIR ?
|
|
15206
|
-
return
|
|
15404
|
+
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(dirname14(fileURLToPath4(import.meta.url)), "../..");
|
|
15405
|
+
return join33(producerRoot, ".debug");
|
|
15207
15406
|
}
|
|
15208
15407
|
async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
15209
15408
|
validateHlsRenderConfig(job.config);
|
|
@@ -15211,11 +15410,11 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
|
|
|
15211
15410
|
validateChromaSubsamplingConfig(job.config);
|
|
15212
15411
|
const debugDir = resolveRenderDebugDir();
|
|
15213
15412
|
const outputDir = dirname14(outputPath);
|
|
15214
|
-
if (!
|
|
15215
|
-
const workDir = job.config.debug ?
|
|
15413
|
+
if (!existsSync22(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
15414
|
+
const workDir = job.config.debug ? join33(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
15216
15415
|
const pipelineStart = Date.now();
|
|
15217
15416
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
15218
|
-
const logPath = job.config.debug ?
|
|
15417
|
+
const logPath = job.config.debug ? join33(workDir, "render.log") : null;
|
|
15219
15418
|
const execution = new RenderExecutionContext({
|
|
15220
15419
|
request: { renderJobId: job.id, projectDir, outputPath },
|
|
15221
15420
|
logger: logPath ? createRenderFileLogger(logPath, baseLog) : baseLog,
|
|
@@ -15283,7 +15482,7 @@ async function executeRenderPipeline(input) {
|
|
|
15283
15482
|
imageDecodeFailures: 0
|
|
15284
15483
|
};
|
|
15285
15484
|
let hdrPerf;
|
|
15286
|
-
const perfOutputPath =
|
|
15485
|
+
const perfOutputPath = join33(workDir, "perf-summary.json");
|
|
15287
15486
|
const cfg = { ...job.config.producerConfig ?? resolveConfig2() };
|
|
15288
15487
|
const observability = new RenderObservabilityRecorder({
|
|
15289
15488
|
pipelineStartMs: pipelineStart,
|
|
@@ -15359,7 +15558,7 @@ async function executeRenderPipeline(input) {
|
|
|
15359
15558
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
15360
15559
|
assertNotAborted();
|
|
15361
15560
|
assertConfiguredFfmpegBinariesExist();
|
|
15362
|
-
if (!
|
|
15561
|
+
if (!existsSync22(workDir)) mkdirSync12(workDir, { recursive: true });
|
|
15363
15562
|
if (job.config.debug) {
|
|
15364
15563
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
15365
15564
|
}
|
|
@@ -15388,8 +15587,8 @@ async function executeRenderPipeline(input) {
|
|
|
15388
15587
|
requestedWorkers: job.config.workers ?? "auto"
|
|
15389
15588
|
});
|
|
15390
15589
|
const entryFile = job.config.entryFile || "index.html";
|
|
15391
|
-
const htmlPath =
|
|
15392
|
-
if (!
|
|
15590
|
+
const htmlPath = join33(projectDir, entryFile);
|
|
15591
|
+
if (!existsSync22(htmlPath)) {
|
|
15393
15592
|
throw new Error(`Entry file not found: ${htmlPath}`);
|
|
15394
15593
|
}
|
|
15395
15594
|
assertNotAborted();
|
|
@@ -15485,7 +15684,7 @@ async function executeRenderPipeline(input) {
|
|
|
15485
15684
|
const largerThanCanvas = await oversizedVideos(
|
|
15486
15685
|
composition.videos,
|
|
15487
15686
|
projectDir,
|
|
15488
|
-
|
|
15687
|
+
join33(workDir, "compiled"),
|
|
15489
15688
|
{ width: outputWidth, height: outputHeight }
|
|
15490
15689
|
);
|
|
15491
15690
|
const probeResult = await observeRenderStage(
|
|
@@ -15582,7 +15781,7 @@ async function executeRenderPipeline(input) {
|
|
|
15582
15781
|
canvas: { width, height },
|
|
15583
15782
|
page: probeSession.page,
|
|
15584
15783
|
projectDir,
|
|
15585
|
-
compiledDir:
|
|
15784
|
+
compiledDir: join33(workDir, "compiled")
|
|
15586
15785
|
});
|
|
15587
15786
|
if (videoLayerPlan.videoId === void 0) {
|
|
15588
15787
|
log.info(`[Render] Video layer passthrough off: ${videoLayerPlan.reason}`);
|
|
@@ -15600,7 +15799,7 @@ async function executeRenderPipeline(input) {
|
|
|
15600
15799
|
updateJobStatus(job, "preprocessing", "Extracting video frames", 10, onProgress, {
|
|
15601
15800
|
code: "extract_video"
|
|
15602
15801
|
});
|
|
15603
|
-
const compiledDir =
|
|
15802
|
+
const compiledDir = join33(workDir, "compiled");
|
|
15604
15803
|
const segmentsCapture = (layeredOrEffectRoute) => shouldSegmentCapture({
|
|
15605
15804
|
env: process.env,
|
|
15606
15805
|
durationSeconds: probeResult.duration,
|
|
@@ -15736,7 +15935,7 @@ async function executeRenderPipeline(input) {
|
|
|
15736
15935
|
try {
|
|
15737
15936
|
fileServer = await createFileServer({
|
|
15738
15937
|
projectDir,
|
|
15739
|
-
compiledDir:
|
|
15938
|
+
compiledDir: join33(workDir, "compiled"),
|
|
15740
15939
|
port: 0,
|
|
15741
15940
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
15742
15941
|
fps: job.config.fps,
|
|
@@ -15756,8 +15955,8 @@ async function executeRenderPipeline(input) {
|
|
|
15756
15955
|
if (!activeFileServer) {
|
|
15757
15956
|
throw new Error("File server failed to initialize before frame capture");
|
|
15758
15957
|
}
|
|
15759
|
-
const framesDir =
|
|
15760
|
-
if (!
|
|
15958
|
+
const framesDir = join33(workDir, "captured-frames");
|
|
15959
|
+
if (!existsSync22(framesDir)) mkdirSync12(framesDir, { recursive: true });
|
|
15761
15960
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
15762
15961
|
code: "start_browsers"
|
|
15763
15962
|
});
|
|
@@ -16337,7 +16536,7 @@ async function executeRenderPipeline(input) {
|
|
|
16337
16536
|
hls: ".mp4"
|
|
16338
16537
|
};
|
|
16339
16538
|
const videoExt = FORMAT_EXT[outputFormat] ?? ".mp4";
|
|
16340
|
-
const videoOnlyPath =
|
|
16539
|
+
const videoOnlyPath = join33(workDir, `video-only${videoExt}`);
|
|
16341
16540
|
let usePageSideCompositingForTransitions = (cfg.enablePageSideCompositing || isGif) && compiled.hasShaderTransitions && !hasHdrContent && outputSupportsPageSideShaderCompositing(outputFormat);
|
|
16342
16541
|
if (usePageSideCompositingForTransitions) {
|
|
16343
16542
|
activeFileServer.addPreHeadScript(HF_PAGE_SIDE_COMPOSITING_STUB);
|
|
@@ -16654,7 +16853,7 @@ async function executeRenderPipeline(input) {
|
|
|
16654
16853
|
pageMotionBlur: job.config.pageMotionBlur,
|
|
16655
16854
|
captureQuality: captureOptions.quality
|
|
16656
16855
|
});
|
|
16657
|
-
const segmentDir = segmentDirFor(
|
|
16856
|
+
const segmentDir = segmentDirFor(join33(projectDir, "renders"), segmentPlanHash);
|
|
16658
16857
|
let completedSegments = /* @__PURE__ */ new Set();
|
|
16659
16858
|
if (job.config.resumeSegments === true) {
|
|
16660
16859
|
const existing = readSegmentManifest(segmentDir);
|
|
@@ -17198,7 +17397,7 @@ async function executeRenderPipeline(input) {
|
|
|
17198
17397
|
})
|
|
17199
17398
|
);
|
|
17200
17399
|
const totalElapsed = Date.now() - pipelineStart;
|
|
17201
|
-
const tmpPeakBytes =
|
|
17400
|
+
const tmpPeakBytes = existsSync22(workDir) ? sampleDirectoryBytes(workDir) : 0;
|
|
17202
17401
|
recordTransientRetryObservability();
|
|
17203
17402
|
observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
|
|
17204
17403
|
const observabilitySummary = observability.summary({
|
|
@@ -17279,8 +17478,8 @@ async function executeRenderPipeline(input) {
|
|
|
17279
17478
|
}
|
|
17280
17479
|
}
|
|
17281
17480
|
if (job.config.debug) {
|
|
17282
|
-
if (!isPngSequence && !isHls &&
|
|
17283
|
-
const debugOutput =
|
|
17481
|
+
if (!isPngSequence && !isHls && existsSync22(stagedOutputPath)) {
|
|
17482
|
+
const debugOutput = join33(workDir, `output${videoExt}`);
|
|
17284
17483
|
copyFileSync5(stagedOutputPath, debugOutput);
|
|
17285
17484
|
}
|
|
17286
17485
|
}
|
|
@@ -17359,7 +17558,8 @@ async function executeRenderPipeline(input) {
|
|
|
17359
17558
|
perfStages,
|
|
17360
17559
|
hdrDiagnostics,
|
|
17361
17560
|
observability: observabilitySummary,
|
|
17362
|
-
subTimelineWait: worstSubTimelineWaitOutcome(dedupPerfs)
|
|
17561
|
+
subTimelineWait: worstSubTimelineWaitOutcome(dedupPerfs),
|
|
17562
|
+
missingPath: describeMissingPath(error, { cacheDir: cfg.extractCacheDir, workDir })
|
|
17363
17563
|
});
|
|
17364
17564
|
publishRenderFailure(
|
|
17365
17565
|
job,
|
|
@@ -17398,14 +17598,14 @@ import {
|
|
|
17398
17598
|
referenceBackgroundResult as referenceBackgroundResult6
|
|
17399
17599
|
} from "@hyperframes/engine";
|
|
17400
17600
|
import { mkdirSync as mkdirSync20, mkdtempSync, readFileSync as readFileSync15, rmSync as rmSync18 } from "node:fs";
|
|
17401
|
-
import { join as
|
|
17402
|
-
import { tmpdir as
|
|
17601
|
+
import { join as join47 } from "node:path";
|
|
17602
|
+
import { tmpdir as tmpdir5 } from "node:os";
|
|
17403
17603
|
|
|
17404
17604
|
// src/services/distributed/mp4Stitch.ts
|
|
17405
17605
|
import { createReadStream as createReadStream3, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync13 } from "node:fs";
|
|
17406
17606
|
import { open } from "node:fs/promises";
|
|
17407
17607
|
import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
|
|
17408
|
-
import { basename as
|
|
17608
|
+
import { basename as basename8, dirname as dirname15, join as join34 } from "node:path";
|
|
17409
17609
|
import { finished, pipeline } from "node:stream/promises";
|
|
17410
17610
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
17411
17611
|
function boxAt(src, off, at, limit) {
|
|
@@ -17771,14 +17971,14 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
17771
17971
|
const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
|
|
17772
17972
|
const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
|
|
17773
17973
|
mkdirSync13(dirname15(outputPath), { recursive: true });
|
|
17774
|
-
const workDir = createStagingDir4(dirname15(outputPath), `${
|
|
17775
|
-
const out = createWriteStream(
|
|
17974
|
+
const workDir = createStagingDir4(dirname15(outputPath), `${basename8(outputPath)}.stitch-`);
|
|
17975
|
+
const out = createWriteStream(join34(workDir, "out.mp4"));
|
|
17776
17976
|
try {
|
|
17777
17977
|
out.write(header);
|
|
17778
17978
|
for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
|
|
17779
17979
|
out.end();
|
|
17780
17980
|
await finished(out);
|
|
17781
|
-
renameWithRetry7(
|
|
17981
|
+
renameWithRetry7(join34(workDir, "out.mp4"), outputPath);
|
|
17782
17982
|
} finally {
|
|
17783
17983
|
out.destroy();
|
|
17784
17984
|
rmSync13(workDir, { recursive: true, force: true });
|
|
@@ -17795,13 +17995,13 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
|
|
|
17795
17995
|
import {
|
|
17796
17996
|
copyFileSync as copyFileSync6,
|
|
17797
17997
|
cpSync as cpSync2,
|
|
17798
|
-
existsSync as
|
|
17998
|
+
existsSync as existsSync27,
|
|
17799
17999
|
linkSync,
|
|
17800
18000
|
mkdirSync as mkdirSync16,
|
|
17801
18001
|
rmSync as rmSync14,
|
|
17802
18002
|
writeFileSync as writeFileSync10
|
|
17803
18003
|
} from "node:fs";
|
|
17804
|
-
import { extname as extname6, isAbsolute as
|
|
18004
|
+
import { extname as extname6, isAbsolute as isAbsolute4, join as join42, relative as relative7, sep as sep5 } from "node:path";
|
|
17805
18005
|
import {
|
|
17806
18006
|
fpsToNumber as fpsToNumber9,
|
|
17807
18007
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
@@ -17818,7 +18018,7 @@ import {
|
|
|
17818
18018
|
} from "@hyperframes/engine";
|
|
17819
18019
|
|
|
17820
18020
|
// src/services/distributed/planFrameCost.ts
|
|
17821
|
-
import { join as
|
|
18021
|
+
import { join as join37 } from "node:path";
|
|
17822
18022
|
import {
|
|
17823
18023
|
closeCaptureSession as closeCaptureSession9,
|
|
17824
18024
|
createCaptureSession as createCaptureSession9,
|
|
@@ -17827,8 +18027,8 @@ import {
|
|
|
17827
18027
|
} from "@hyperframes/engine";
|
|
17828
18028
|
|
|
17829
18029
|
// src/services/distributed/chunkFrames.ts
|
|
17830
|
-
import { existsSync as
|
|
17831
|
-
import { extname as extname4, join as
|
|
18030
|
+
import { existsSync as existsSync24, readdirSync as readdirSync7 } from "node:fs";
|
|
18031
|
+
import { extname as extname4, join as join36 } from "node:path";
|
|
17832
18032
|
import {
|
|
17833
18033
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
17834
18034
|
createVideoFrameInjector as createVideoFrameInjector3,
|
|
@@ -17837,8 +18037,8 @@ import {
|
|
|
17837
18037
|
|
|
17838
18038
|
// src/services/distributed/shared.ts
|
|
17839
18039
|
import { execFile as execFileCallback } from "node:child_process";
|
|
17840
|
-
import { dirname as dirname16, join as
|
|
17841
|
-
import { existsSync as
|
|
18040
|
+
import { dirname as dirname16, join as join35 } from "node:path";
|
|
18041
|
+
import { existsSync as existsSync23, readFileSync as readFileSync10 } from "node:fs";
|
|
17842
18042
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
17843
18043
|
import { promisify as promisify2 } from "node:util";
|
|
17844
18044
|
import {
|
|
@@ -17853,8 +18053,8 @@ function isPlanAudioArtifactPath(path) {
|
|
|
17853
18053
|
}
|
|
17854
18054
|
function resolvePlanAudioPath(planDir) {
|
|
17855
18055
|
for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
|
|
17856
|
-
const candidate =
|
|
17857
|
-
if (
|
|
18056
|
+
const candidate = join35(planDir, name);
|
|
18057
|
+
if (existsSync23(candidate)) return candidate;
|
|
17858
18058
|
}
|
|
17859
18059
|
return null;
|
|
17860
18060
|
}
|
|
@@ -18118,8 +18318,8 @@ function readProducerVersion() {
|
|
|
18118
18318
|
const startDir = dirname16(fileURLToPath5(import.meta.url));
|
|
18119
18319
|
let current = startDir;
|
|
18120
18320
|
for (let i = 0; i < 10; i++) {
|
|
18121
|
-
const candidate =
|
|
18122
|
-
if (
|
|
18321
|
+
const candidate = join35(current, "package.json");
|
|
18322
|
+
if (existsSync23(candidate)) {
|
|
18123
18323
|
try {
|
|
18124
18324
|
const pkg = JSON.parse(readFileSync10(candidate, "utf-8"));
|
|
18125
18325
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
@@ -18173,8 +18373,8 @@ function frameNumberFromFileName(name) {
|
|
|
18173
18373
|
function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
|
|
18174
18374
|
const result = [];
|
|
18175
18375
|
for (const v of videos) {
|
|
18176
|
-
const outputDir =
|
|
18177
|
-
if (!
|
|
18376
|
+
const outputDir = join36(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
|
|
18377
|
+
if (!existsSync24(outputDir)) {
|
|
18178
18378
|
throw new Error(
|
|
18179
18379
|
`[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
|
|
18180
18380
|
);
|
|
@@ -18192,7 +18392,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
|
|
|
18192
18392
|
if (!frameName) continue;
|
|
18193
18393
|
const frameNumber = indexMode === "sparse-v2" ? frameNumberFromFileName(frameName) : null;
|
|
18194
18394
|
const frameIndex = frameNumber === null ? i : frameNumber - 1;
|
|
18195
|
-
framePaths.set(frameIndex,
|
|
18395
|
+
framePaths.set(frameIndex, join36(outputDir, frameName));
|
|
18196
18396
|
}
|
|
18197
18397
|
result.push({
|
|
18198
18398
|
videoId: v.videoId,
|
|
@@ -18272,8 +18472,8 @@ async function extractDeferredVideoFramesForChunk(input) {
|
|
|
18272
18472
|
sourceOf: (video) => {
|
|
18273
18473
|
const range = planned.get(video.videoId).deferredRange;
|
|
18274
18474
|
const remoteUrl = remoteSources[range.sourcePath];
|
|
18275
|
-
const sourcePath = remoteUrl ??
|
|
18276
|
-
if (remoteUrl === void 0 && !
|
|
18475
|
+
const sourcePath = remoteUrl ?? join36(input.planDir, ...range.sourcePath.split("/"));
|
|
18476
|
+
if (remoteUrl === void 0 && !existsSync24(sourcePath)) {
|
|
18277
18477
|
throw new RenderChunkValidationError(
|
|
18278
18478
|
MISSING_PLAN_ARTIFACT,
|
|
18279
18479
|
`[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
|
|
@@ -18303,12 +18503,12 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
18303
18503
|
planVideos,
|
|
18304
18504
|
frames: sampled,
|
|
18305
18505
|
fps: fpsRatio,
|
|
18306
|
-
outputRoot:
|
|
18506
|
+
outputRoot: join37(workDir, "frame-cost-video-frames"),
|
|
18307
18507
|
cfg: input.cfg
|
|
18308
18508
|
})
|
|
18309
18509
|
];
|
|
18310
18510
|
const lookup = extracted.length > 0 ? createFrameLookupTable4(planVideos.videos, extracted, resolveRenderFpsConfig(fpsRatio).value) : null;
|
|
18311
|
-
const compiledDir =
|
|
18511
|
+
const compiledDir = join37(planDir, "compiled");
|
|
18312
18512
|
const fileServer = await createFileServer({
|
|
18313
18513
|
projectDir: compiledDir,
|
|
18314
18514
|
compiledDir,
|
|
@@ -18320,7 +18520,7 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
18320
18520
|
try {
|
|
18321
18521
|
session = await createCaptureSession9(
|
|
18322
18522
|
fileServer.url,
|
|
18323
|
-
|
|
18523
|
+
join37(workDir, "frame-cost"),
|
|
18324
18524
|
buildChunkCaptureOptions({
|
|
18325
18525
|
dimensions: { ...input, fpsNum: fps, fpsDen: 1 },
|
|
18326
18526
|
encoder: input,
|
|
@@ -18417,7 +18617,7 @@ function buildWeightedChunkSlices(weights, chunkCount, minFrames, maxFrames) {
|
|
|
18417
18617
|
}
|
|
18418
18618
|
|
|
18419
18619
|
// src/services/render/planReferenceBackground.ts
|
|
18420
|
-
import { join as
|
|
18620
|
+
import { join as join38 } from "node:path";
|
|
18421
18621
|
import {
|
|
18422
18622
|
closeCaptureSession as closeCaptureSession10,
|
|
18423
18623
|
createCaptureSession as createCaptureSession10,
|
|
@@ -18430,14 +18630,14 @@ async function readPlanReferenceBackground(input) {
|
|
|
18430
18630
|
try {
|
|
18431
18631
|
server = await createFileServer({
|
|
18432
18632
|
projectDir: input.projectDir,
|
|
18433
|
-
compiledDir:
|
|
18633
|
+
compiledDir: join38(input.workDir, "compiled"),
|
|
18434
18634
|
port: 0,
|
|
18435
18635
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
18436
18636
|
fps: input.options.fps
|
|
18437
18637
|
});
|
|
18438
18638
|
session = await createCaptureSession10(
|
|
18439
18639
|
server.url,
|
|
18440
|
-
|
|
18640
|
+
join38(input.workDir, "reference"),
|
|
18441
18641
|
{
|
|
18442
18642
|
...input.options,
|
|
18443
18643
|
requiresWebGpu: false
|
|
@@ -18473,8 +18673,8 @@ async function readPlanReferenceBackground(input) {
|
|
|
18473
18673
|
}
|
|
18474
18674
|
|
|
18475
18675
|
// src/services/render/stages/freezePlan.ts
|
|
18476
|
-
import { existsSync as
|
|
18477
|
-
import { join as
|
|
18676
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
18677
|
+
import { join as join39, relative as relative5, resolve as resolve10 } from "node:path";
|
|
18478
18678
|
import {
|
|
18479
18679
|
REFERENCE_BACKGROUND_FIELD,
|
|
18480
18680
|
referenceBackgroundResult as referenceBackgroundResult3
|
|
@@ -18667,7 +18867,7 @@ function planFileSha256(absolutePath, digests) {
|
|
|
18667
18867
|
return sha256;
|
|
18668
18868
|
}
|
|
18669
18869
|
async function prehashPlanFiles(dir, digests) {
|
|
18670
|
-
if (!
|
|
18870
|
+
if (!existsSync25(dir)) return;
|
|
18671
18871
|
for (const { absolutePath } of listPlanFiles(dir)) {
|
|
18672
18872
|
if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
|
|
18673
18873
|
}
|
|
@@ -18688,16 +18888,16 @@ function stripUndefined(value) {
|
|
|
18688
18888
|
}
|
|
18689
18889
|
function listPlanFiles(planDir) {
|
|
18690
18890
|
const results = [];
|
|
18691
|
-
const rootResolved =
|
|
18891
|
+
const rootResolved = resolve10(planDir);
|
|
18692
18892
|
function walk(dir) {
|
|
18693
18893
|
const entries = readdirSync8(dir, { withFileTypes: true });
|
|
18694
18894
|
for (const entry of entries) {
|
|
18695
|
-
const full =
|
|
18895
|
+
const full = join39(dir, entry.name);
|
|
18696
18896
|
if (entry.isDirectory()) {
|
|
18697
18897
|
walk(full);
|
|
18698
18898
|
} else if (entry.isFile()) {
|
|
18699
18899
|
results.push({
|
|
18700
|
-
planRelativePath:
|
|
18900
|
+
planRelativePath: relative5(rootResolved, full).split(/[\\/]+/).join("/"),
|
|
18701
18901
|
absolutePath: full
|
|
18702
18902
|
});
|
|
18703
18903
|
}
|
|
@@ -18733,19 +18933,19 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
|
|
|
18733
18933
|
function writePlanRemoteFiles(planDir, files) {
|
|
18734
18934
|
if (files.length === 0) return;
|
|
18735
18935
|
const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
|
|
18736
|
-
writeFileSync8(
|
|
18936
|
+
writeFileSync8(join39(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
|
|
18737
18937
|
}
|
|
18738
18938
|
function readPlanRemoteFiles(planDir) {
|
|
18739
|
-
const path =
|
|
18740
|
-
return
|
|
18939
|
+
const path = join39(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
|
|
18940
|
+
return existsSync25(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
|
|
18741
18941
|
}
|
|
18742
18942
|
function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
18743
|
-
const planJsonPath =
|
|
18744
|
-
const encoderJsonPath =
|
|
18745
|
-
if (!
|
|
18943
|
+
const planJsonPath = join39(planDir, "plan.json");
|
|
18944
|
+
const encoderJsonPath = join39(planDir, "meta", "encoder.json");
|
|
18945
|
+
if (!existsSync25(planJsonPath)) {
|
|
18746
18946
|
throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
|
|
18747
18947
|
}
|
|
18748
|
-
if (!
|
|
18948
|
+
if (!existsSync25(encoderJsonPath)) {
|
|
18749
18949
|
throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
|
|
18750
18950
|
}
|
|
18751
18951
|
const planJson = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
|
|
@@ -18775,21 +18975,21 @@ async function freezePlan(input) {
|
|
|
18775
18975
|
hasAudio,
|
|
18776
18976
|
digests
|
|
18777
18977
|
} = input;
|
|
18778
|
-
if (!
|
|
18978
|
+
if (!existsSync25(planDir)) {
|
|
18779
18979
|
throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
|
|
18780
18980
|
}
|
|
18781
|
-
const metaDir =
|
|
18782
|
-
if (!
|
|
18981
|
+
const metaDir = join39(planDir, "meta");
|
|
18982
|
+
if (!existsSync25(metaDir)) mkdirSync14(metaDir, { recursive: true });
|
|
18783
18983
|
writeFileSync8(
|
|
18784
|
-
|
|
18984
|
+
join39(metaDir, "composition.json"),
|
|
18785
18985
|
`${JSON.stringify(composition, null, 2)}
|
|
18786
18986
|
`,
|
|
18787
18987
|
"utf-8"
|
|
18788
18988
|
);
|
|
18789
18989
|
const encoderForCanonical = stripUndefined(encoder);
|
|
18790
18990
|
const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
|
|
18791
|
-
writeFileSync8(
|
|
18792
|
-
writeFileSync8(
|
|
18991
|
+
writeFileSync8(join39(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
|
|
18992
|
+
writeFileSync8(join39(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
|
|
18793
18993
|
`, "utf-8");
|
|
18794
18994
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
18795
18995
|
const planHash = computePlanHash({
|
|
@@ -18814,7 +19014,7 @@ async function freezePlan(input) {
|
|
|
18814
19014
|
duration: durationSeconds,
|
|
18815
19015
|
hasAudio
|
|
18816
19016
|
};
|
|
18817
|
-
const planJsonPath =
|
|
19017
|
+
const planJsonPath = join39(planDir, "plan.json");
|
|
18818
19018
|
writeFileSync8(planJsonPath, `${JSON.stringify(planJson, null, 2)}
|
|
18819
19019
|
`, "utf-8");
|
|
18820
19020
|
return { planJsonPath, planHash };
|
|
@@ -18856,9 +19056,9 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
|
|
|
18856
19056
|
}
|
|
18857
19057
|
|
|
18858
19058
|
// src/services/distributed/chunkAudio.ts
|
|
18859
|
-
import { closeSync as closeSync6, existsSync as
|
|
19059
|
+
import { closeSync as closeSync6, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync6, readFileSync as readFileSync12 } from "node:fs";
|
|
18860
19060
|
import { writeFileSync as writeFileSync9, writeSync } from "node:fs";
|
|
18861
|
-
import { join as
|
|
19061
|
+
import { join as join40 } from "node:path";
|
|
18862
19062
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
18863
19063
|
function audioCutForChunk(grid, chunks, index, fps) {
|
|
18864
19064
|
const firstPacketAt = (frame) => Math.min(
|
|
@@ -18946,7 +19146,7 @@ async function writeChunkAudioSlices(input) {
|
|
|
18946
19146
|
});
|
|
18947
19147
|
const bytes = readFileSync12(input.audioPath);
|
|
18948
19148
|
const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
|
|
18949
|
-
mkdirSync15(
|
|
19149
|
+
mkdirSync15(join40(input.planDir, SLICE_DIR), { recursive: true });
|
|
18950
19150
|
input.chunks.forEach((_, index) => {
|
|
18951
19151
|
const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
|
|
18952
19152
|
if (!cut) return;
|
|
@@ -18954,17 +19154,17 @@ async function writeChunkAudioSlices(input) {
|
|
|
18954
19154
|
const start = offsets[cut.firstPacket];
|
|
18955
19155
|
layout.partStarts[index] = start;
|
|
18956
19156
|
const end = offsets[last] + track.sizes[last];
|
|
18957
|
-
writeFileSync9(
|
|
19157
|
+
writeFileSync9(join40(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
|
|
18958
19158
|
});
|
|
18959
19159
|
const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
|
|
18960
|
-
writeFileSync9(
|
|
18961
|
-
writeFileSync9(
|
|
19160
|
+
writeFileSync9(join40(input.planDir, SLICE_FRAME), Buffer.concat(frame));
|
|
19161
|
+
writeFileSync9(join40(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
|
|
18962
19162
|
}
|
|
18963
19163
|
function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
18964
|
-
const layoutPath =
|
|
18965
|
-
if (!
|
|
19164
|
+
const layoutPath = join40(planDir, SLICE_LAYOUT);
|
|
19165
|
+
if (!existsSync26(layoutPath)) return resolvePlanAudioPath(planDir);
|
|
18966
19166
|
const layout = JSON.parse(readFileSync12(layoutPath, "utf-8"));
|
|
18967
|
-
const frame = readFileSync12(
|
|
19167
|
+
const frame = readFileSync12(join40(planDir, SLICE_FRAME));
|
|
18968
19168
|
const fd = openSync6(scratchPath, "w");
|
|
18969
19169
|
try {
|
|
18970
19170
|
writeSync(fd, frame, 0, layout.payloadStart, 0);
|
|
@@ -18977,7 +19177,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
|
18977
19177
|
);
|
|
18978
19178
|
const start = layout.partStarts[chunkIndex];
|
|
18979
19179
|
if (start !== void 0) {
|
|
18980
|
-
const part = readFileSync12(
|
|
19180
|
+
const part = readFileSync12(join40(planDir, chunkAudioSlicePath(chunkIndex)));
|
|
18981
19181
|
writeSync(fd, part, 0, part.length, start);
|
|
18982
19182
|
}
|
|
18983
19183
|
ftruncateSync(fd, layout.sizeBytes);
|
|
@@ -19032,8 +19232,8 @@ async function muxChunkWithAudio(input) {
|
|
|
19032
19232
|
|
|
19033
19233
|
// src/services/distributed/planSize.ts
|
|
19034
19234
|
import { createHash as createHash9 } from "node:crypto";
|
|
19035
|
-
import { lstatSync as
|
|
19036
|
-
import { extname as extname5, join as
|
|
19235
|
+
import { lstatSync as lstatSync3, readdirSync as readdirSync9 } from "node:fs";
|
|
19236
|
+
import { extname as extname5, join as join41, relative as relative6 } from "node:path";
|
|
19037
19237
|
var MAX_TOP_COMPONENTS = 10;
|
|
19038
19238
|
var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
19039
19239
|
".aac",
|
|
@@ -19116,13 +19316,13 @@ function addCategoryBytes(result, category, filePath, sizeBytes) {
|
|
|
19116
19316
|
function recordFile(result, components, rootDir, rootKind, filePath) {
|
|
19117
19317
|
let sizeBytes;
|
|
19118
19318
|
try {
|
|
19119
|
-
const stat =
|
|
19319
|
+
const stat = lstatSync3(filePath);
|
|
19120
19320
|
if (!stat.isFile()) return;
|
|
19121
19321
|
sizeBytes = stat.size;
|
|
19122
19322
|
} catch {
|
|
19123
19323
|
return;
|
|
19124
19324
|
}
|
|
19125
|
-
const rel =
|
|
19325
|
+
const rel = relative6(rootDir, filePath);
|
|
19126
19326
|
const segments = rel.split(/[\\/]+/).filter(Boolean);
|
|
19127
19327
|
const classified = classifyFile(segments, rootKind);
|
|
19128
19328
|
result.totalBytes += sizeBytes;
|
|
@@ -19145,7 +19345,7 @@ function walkRegularFiles(dir, visit) {
|
|
|
19145
19345
|
return;
|
|
19146
19346
|
}
|
|
19147
19347
|
for (const entry of entries) {
|
|
19148
|
-
const full =
|
|
19348
|
+
const full = join41(dir, entry.name);
|
|
19149
19349
|
if (entry.isDirectory()) {
|
|
19150
19350
|
walkRegularFiles(full, visit);
|
|
19151
19351
|
} else if (entry.isFile()) {
|
|
@@ -19361,13 +19561,13 @@ function assertPositiveInteger2(name, value) {
|
|
|
19361
19561
|
}
|
|
19362
19562
|
var FREEZE_OWNED_PLAN_FILES = [
|
|
19363
19563
|
"plan.json",
|
|
19364
|
-
|
|
19365
|
-
|
|
19366
|
-
|
|
19564
|
+
join42("meta", "composition.json"),
|
|
19565
|
+
join42("meta", "encoder.json"),
|
|
19566
|
+
join42("meta", "chunks.json")
|
|
19367
19567
|
];
|
|
19368
19568
|
function removeFreezeOwnedPlanFiles(planDir) {
|
|
19369
19569
|
for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
|
|
19370
|
-
rmSync14(
|
|
19570
|
+
rmSync14(join42(planDir, relativePath), { force: true });
|
|
19371
19571
|
}
|
|
19372
19572
|
}
|
|
19373
19573
|
function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
|
|
@@ -19506,16 +19706,16 @@ function resolveDistributedEngineConfig(config) {
|
|
|
19506
19706
|
};
|
|
19507
19707
|
}
|
|
19508
19708
|
function leavesRoot(rel) {
|
|
19509
|
-
return rel === ".." || rel.startsWith(`..${
|
|
19709
|
+
return rel === ".." || rel.startsWith(`..${sep5}`) || isAbsolute4(rel);
|
|
19510
19710
|
}
|
|
19511
19711
|
function pathInside(root, path) {
|
|
19512
|
-
const rel =
|
|
19712
|
+
const rel = relative7(root, path);
|
|
19513
19713
|
return rel === "" || leavesRoot(rel) ? null : rel;
|
|
19514
19714
|
}
|
|
19515
19715
|
function stableSourcePath(roots, srcPath) {
|
|
19516
19716
|
for (const [root, prefix] of roots) {
|
|
19517
19717
|
const rel = pathInside(root, srcPath);
|
|
19518
|
-
if (rel !== null) return [prefix, ...rel.split(
|
|
19718
|
+
if (rel !== null) return [prefix, ...rel.split(sep5)].filter(Boolean).join("/");
|
|
19519
19719
|
}
|
|
19520
19720
|
return srcPath;
|
|
19521
19721
|
}
|
|
@@ -19525,19 +19725,19 @@ function createVideoSourceShipper(input) {
|
|
|
19525
19725
|
const known = shipped.get(srcPath);
|
|
19526
19726
|
if (known) return known;
|
|
19527
19727
|
const stagedRel = pathInside(input.workVideoFramesDir, srcPath);
|
|
19528
|
-
const current = stagedRel === null ? srcPath :
|
|
19728
|
+
const current = stagedRel === null ? srcPath : join42(input.planDir, "video-frames", stagedRel);
|
|
19529
19729
|
let result = null;
|
|
19530
19730
|
for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
|
|
19531
19731
|
const rel = pathInside(root, srcPath);
|
|
19532
|
-
if (rel !== null && (
|
|
19533
|
-
result = ["compiled", ...rel.split(
|
|
19732
|
+
if (rel !== null && (existsSync27(join42(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
|
|
19733
|
+
result = ["compiled", ...rel.split(sep5)].join("/");
|
|
19534
19734
|
break;
|
|
19535
19735
|
}
|
|
19536
19736
|
}
|
|
19537
19737
|
if (result === null) {
|
|
19538
19738
|
result = `video-sources/${shipped.size}${extname6(current)}`;
|
|
19539
|
-
const destination =
|
|
19540
|
-
mkdirSync16(
|
|
19739
|
+
const destination = join42(input.planDir, ...result.split("/"));
|
|
19740
|
+
mkdirSync16(join42(input.planDir, "video-sources"), { recursive: true });
|
|
19541
19741
|
try {
|
|
19542
19742
|
linkSync(current, destination);
|
|
19543
19743
|
} catch {
|
|
@@ -19557,7 +19757,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
19557
19757
|
useGpu: false,
|
|
19558
19758
|
browserGpuMode: "software"
|
|
19559
19759
|
});
|
|
19560
|
-
if (!
|
|
19760
|
+
if (!existsSync27(planDir)) mkdirSync16(planDir, { recursive: true });
|
|
19561
19761
|
const log = config.logger ?? defaultLogger;
|
|
19562
19762
|
const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
|
|
19563
19763
|
const abortSignal = config.abortSignal;
|
|
@@ -19591,21 +19791,21 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
19591
19791
|
includeOutsideScripts: options.includeOutsideScripts === true
|
|
19592
19792
|
});
|
|
19593
19793
|
const entryFile = config.entryFile ?? "index.html";
|
|
19594
|
-
const htmlPath =
|
|
19595
|
-
if (!
|
|
19794
|
+
const htmlPath = join42(projectDir, entryFile);
|
|
19795
|
+
if (!existsSync27(htmlPath)) {
|
|
19596
19796
|
throw new Error(`[plan] entry file not found: ${htmlPath}`);
|
|
19597
19797
|
}
|
|
19598
|
-
const workDir =
|
|
19798
|
+
const workDir = join42(planDir, ".plan-work");
|
|
19599
19799
|
rmSync14(workDir, { recursive: true, force: true });
|
|
19600
19800
|
mkdirSync16(workDir, { recursive: true });
|
|
19601
|
-
const compiledDir =
|
|
19801
|
+
const compiledDir = join42(workDir, "compiled");
|
|
19602
19802
|
mkdirSync16(compiledDir, { recursive: true });
|
|
19603
19803
|
let stageStarted = Date.now();
|
|
19604
19804
|
cpSync2(projectDir, compiledDir, {
|
|
19605
19805
|
recursive: true,
|
|
19606
19806
|
dereference: true,
|
|
19607
19807
|
filter: (src) => {
|
|
19608
|
-
const rel =
|
|
19808
|
+
const rel = relative7(projectDir, src);
|
|
19609
19809
|
if (rel === "") return true;
|
|
19610
19810
|
if (leavesRoot(rel)) return false;
|
|
19611
19811
|
if (job.config.allowOutsideProjectAssets) {
|
|
@@ -19613,15 +19813,15 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
19613
19813
|
const policy = { includeScripts: job.config.includeOutsideScripts };
|
|
19614
19814
|
if (refusesOutsideLink(projectDir, src, warn, policy)) return false;
|
|
19615
19815
|
} else if (!isSafePath2(projectDir, src)) return false;
|
|
19616
|
-
const firstSegment = rel.split(
|
|
19816
|
+
const firstSegment = rel.split(sep5, 1)[0];
|
|
19617
19817
|
return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
|
|
19618
19818
|
}
|
|
19619
19819
|
});
|
|
19620
19820
|
logPlanStage(log, "copy", stageStarted);
|
|
19621
|
-
const finalCompiledDir =
|
|
19821
|
+
const finalCompiledDir = join42(planDir, "compiled");
|
|
19622
19822
|
const needsAlpha = outputNeedsAlpha(config.format);
|
|
19623
19823
|
const remoteFiles = Object.entries(options.remoteFiles ?? {});
|
|
19624
|
-
const remoteLocalPath = (rel) =>
|
|
19824
|
+
const remoteLocalPath = (rel) => join42(projectDir, ...rel.split("/"));
|
|
19625
19825
|
for (const [, file] of remoteFiles) {
|
|
19626
19826
|
declareContentAddressedUrl(file.url, file.sha256);
|
|
19627
19827
|
if (file.probeFactsUrl) declareProbeFactsUrl(file.url, file.probeFactsUrl);
|
|
@@ -19826,17 +20026,17 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
19826
20026
|
let stageStarted = Date.now();
|
|
19827
20027
|
const extractResult = await extractPlanVideos(c, options.deferVideoExtraction);
|
|
19828
20028
|
logPlanStage(log, "extract", stageStarted);
|
|
19829
|
-
const stagedVideoFrames =
|
|
19830
|
-
const videoFramesDst =
|
|
19831
|
-
if (
|
|
19832
|
-
const videoSourcesDir =
|
|
20029
|
+
const stagedVideoFrames = join42(compiledDir, "__hyperframes_video_frames");
|
|
20030
|
+
const videoFramesDst = join42(planDir, "video-frames");
|
|
20031
|
+
if (existsSync27(videoFramesDst)) rmSync14(videoFramesDst, { recursive: true, force: true });
|
|
20032
|
+
const videoSourcesDir = join42(planDir, "video-sources");
|
|
19833
20033
|
rmSync14(videoSourcesDir, { recursive: true, force: true });
|
|
19834
|
-
if (
|
|
20034
|
+
if (existsSync27(stagedVideoFrames)) {
|
|
19835
20035
|
renameWithRetry8(stagedVideoFrames, videoFramesDst);
|
|
19836
20036
|
} else {
|
|
19837
20037
|
mkdirSync16(videoFramesDst, { recursive: true });
|
|
19838
20038
|
}
|
|
19839
|
-
if (
|
|
20039
|
+
if (existsSync27(finalCompiledDir)) rmSync14(finalCompiledDir, { recursive: true, force: true });
|
|
19840
20040
|
renameWithRetry8(compiledDir, finalCompiledDir);
|
|
19841
20041
|
const shipVideoSource = createVideoSourceShipper({
|
|
19842
20042
|
planDir,
|
|
@@ -19866,7 +20066,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
19866
20066
|
};
|
|
19867
20067
|
})
|
|
19868
20068
|
});
|
|
19869
|
-
mkdirSync16(
|
|
20069
|
+
mkdirSync16(join42(planDir, "meta"), { recursive: true });
|
|
19870
20070
|
writePlanRemoteFiles(
|
|
19871
20071
|
planDir,
|
|
19872
20072
|
remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
|
|
@@ -19876,7 +20076,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
19876
20076
|
}))
|
|
19877
20077
|
);
|
|
19878
20078
|
writeFileSync10(
|
|
19879
|
-
|
|
20079
|
+
join42(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
|
|
19880
20080
|
JSON.stringify(planVideosJson, null, 2),
|
|
19881
20081
|
"utf-8"
|
|
19882
20082
|
);
|
|
@@ -19956,11 +20156,11 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
19956
20156
|
if (audioResult?.audioError) {
|
|
19957
20157
|
applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
|
|
19958
20158
|
}
|
|
19959
|
-
const planAudioPath =
|
|
19960
|
-
if (audioResult?.hasAudio &&
|
|
20159
|
+
const planAudioPath = join42(planDir, PLAN_AUDIO_RELATIVE_PATH);
|
|
20160
|
+
if (audioResult?.hasAudio && existsSync27(audioResult.audioOutputPath)) {
|
|
19961
20161
|
renameWithRetry8(audioResult.audioOutputPath, planAudioPath);
|
|
19962
20162
|
}
|
|
19963
|
-
if (chunksCarryAudio &&
|
|
20163
|
+
if (chunksCarryAudio && existsSync27(planAudioPath)) {
|
|
19964
20164
|
if (options.sliceChunkAudio) {
|
|
19965
20165
|
stageStarted = Date.now();
|
|
19966
20166
|
await writeChunkAudioSlices({
|
|
@@ -20082,8 +20282,8 @@ async function plan(projectDir, config, planDir, options = {}) {
|
|
|
20082
20282
|
|
|
20083
20283
|
// src/services/distributed/renderChunk.ts
|
|
20084
20284
|
import { randomBytes } from "node:crypto";
|
|
20085
|
-
import { existsSync as
|
|
20086
|
-
import { join as
|
|
20285
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync13 } from "node:fs";
|
|
20286
|
+
import { join as join46 } from "node:path";
|
|
20087
20287
|
import {
|
|
20088
20288
|
assertSwiftShader,
|
|
20089
20289
|
BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
|
|
@@ -20109,8 +20309,8 @@ import {
|
|
|
20109
20309
|
} from "@hyperframes/engine";
|
|
20110
20310
|
import {
|
|
20111
20311
|
copyFileSync as copyFileSync8,
|
|
20112
|
-
existsSync as
|
|
20113
|
-
lstatSync as
|
|
20312
|
+
existsSync as existsSync29,
|
|
20313
|
+
lstatSync as lstatSync4,
|
|
20114
20314
|
mkdirSync as mkdirSync18,
|
|
20115
20315
|
readFileSync as readFileSync13,
|
|
20116
20316
|
readdirSync as readdirSync10,
|
|
@@ -20118,8 +20318,8 @@ import {
|
|
|
20118
20318
|
statSync as statSync13,
|
|
20119
20319
|
writeFileSync as writeFileSync12
|
|
20120
20320
|
} from "node:fs";
|
|
20121
|
-
import { tmpdir as
|
|
20122
|
-
import { dirname as dirname18, isAbsolute as
|
|
20321
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
20322
|
+
import { dirname as dirname18, isAbsolute as isAbsolute5, join as join45, relative as relative8, resolve as resolve11, sep as sep6 } from "node:path";
|
|
20123
20323
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
20124
20324
|
import {
|
|
20125
20325
|
createFrameLookupTable as createFrameLookupTable5,
|
|
@@ -20130,7 +20330,7 @@ import {
|
|
|
20130
20330
|
// src/services/distributed/planV2Publisher.ts
|
|
20131
20331
|
import {
|
|
20132
20332
|
copyFileSync as copyFileSync7,
|
|
20133
|
-
existsSync as
|
|
20333
|
+
existsSync as existsSync28,
|
|
20134
20334
|
linkSync as linkSync2,
|
|
20135
20335
|
mkdirSync as mkdirSync17,
|
|
20136
20336
|
rmSync as rmSync15,
|
|
@@ -20138,7 +20338,7 @@ import {
|
|
|
20138
20338
|
writeFileSync as writeFileSync11
|
|
20139
20339
|
} from "node:fs";
|
|
20140
20340
|
import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
|
|
20141
|
-
import { dirname as dirname17, join as
|
|
20341
|
+
import { dirname as dirname17, join as join44 } from "node:path";
|
|
20142
20342
|
|
|
20143
20343
|
// src/services/distributed/planV2Errors.ts
|
|
20144
20344
|
var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
|
|
@@ -20153,7 +20353,7 @@ var PlanV2IntegrityError = class extends Error {
|
|
|
20153
20353
|
};
|
|
20154
20354
|
|
|
20155
20355
|
// src/services/distributed/planV2Layout.ts
|
|
20156
|
-
import { join as
|
|
20356
|
+
import { join as join43 } from "node:path";
|
|
20157
20357
|
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
20158
20358
|
function assertPlanV2Sha256(value, field) {
|
|
20159
20359
|
if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
|
|
@@ -20163,7 +20363,7 @@ function assertPlanV2Sha256(value, field) {
|
|
|
20163
20363
|
}
|
|
20164
20364
|
function planV2BlobPath(root, sha256) {
|
|
20165
20365
|
const digest = assertPlanV2Sha256(sha256, "artifact sha256");
|
|
20166
|
-
return
|
|
20366
|
+
return join43(root, "artifacts", "sha256", digest.slice(0, 2), digest);
|
|
20167
20367
|
}
|
|
20168
20368
|
|
|
20169
20369
|
// src/services/distributed/planV2Publisher.ts
|
|
@@ -20194,7 +20394,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20194
20394
|
#linkFile;
|
|
20195
20395
|
#committed = false;
|
|
20196
20396
|
constructor(destinationDir, options = {}) {
|
|
20197
|
-
if (
|
|
20397
|
+
if (existsSync28(destinationDir)) {
|
|
20198
20398
|
throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
|
|
20199
20399
|
}
|
|
20200
20400
|
this.destinationDir = destinationDir;
|
|
@@ -20211,10 +20411,10 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20211
20411
|
);
|
|
20212
20412
|
}
|
|
20213
20413
|
const destinationPath = planV2BlobPath(this.temporaryDir, digest);
|
|
20214
|
-
if (
|
|
20414
|
+
if (existsSync28(destinationPath)) return;
|
|
20215
20415
|
mkdirSync17(dirname17(destinationPath), { recursive: true });
|
|
20216
20416
|
const stagingDir = createStagingDir5(dirname17(destinationPath), ".plan-v2-blob-");
|
|
20217
|
-
const temporaryPath =
|
|
20417
|
+
const temporaryPath = join44(stagingDir, "blob");
|
|
20218
20418
|
try {
|
|
20219
20419
|
try {
|
|
20220
20420
|
this.#linkFile(blob.sourcePath, temporaryPath);
|
|
@@ -20229,13 +20429,13 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20229
20429
|
}
|
|
20230
20430
|
async commitManifest(manifestBytes) {
|
|
20231
20431
|
for (const digest of new Set(manifestDigests(manifestBytes))) {
|
|
20232
|
-
if (!
|
|
20432
|
+
if (!existsSync28(planV2BlobPath(this.temporaryDir, digest))) {
|
|
20233
20433
|
throw new PlanV2IntegrityError(
|
|
20234
20434
|
`cannot commit manifest before referenced blob is durable: ${digest}`
|
|
20235
20435
|
);
|
|
20236
20436
|
}
|
|
20237
20437
|
}
|
|
20238
|
-
writeFileSync11(
|
|
20438
|
+
writeFileSync11(join44(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
|
|
20239
20439
|
renameWithRetry9(this.temporaryDir, this.destinationDir);
|
|
20240
20440
|
this.#committed = true;
|
|
20241
20441
|
}
|
|
@@ -20272,21 +20472,21 @@ function readJsonFile(path, label) {
|
|
|
20272
20472
|
}
|
|
20273
20473
|
function assertSafeRelativePath(path) {
|
|
20274
20474
|
const normalized = path.split(/[\\/]+/);
|
|
20275
|
-
if (path.length === 0 ||
|
|
20475
|
+
if (path.length === 0 || isAbsolute5(path) || normalized.some((part) => part === "" || part === "." || part === "..")) {
|
|
20276
20476
|
throw new PlanV2IntegrityError(`unsafe artifact path: ${JSON.stringify(path)}`);
|
|
20277
20477
|
}
|
|
20278
20478
|
}
|
|
20279
20479
|
function listFiles(root) {
|
|
20280
20480
|
const files = [];
|
|
20281
|
-
const rootResolved =
|
|
20481
|
+
const rootResolved = resolve11(root);
|
|
20282
20482
|
function walk(dir) {
|
|
20283
20483
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
20284
|
-
const absolutePath =
|
|
20484
|
+
const absolutePath = join45(dir, entry.name);
|
|
20285
20485
|
if (entry.isDirectory()) {
|
|
20286
20486
|
walk(absolutePath);
|
|
20287
20487
|
} else if (entry.isFile()) {
|
|
20288
20488
|
files.push({
|
|
20289
|
-
path:
|
|
20489
|
+
path: relative8(rootResolved, absolutePath).split(sep6).join("/"),
|
|
20290
20490
|
absolutePath
|
|
20291
20491
|
});
|
|
20292
20492
|
} else {
|
|
@@ -20300,7 +20500,7 @@ function listFiles(root) {
|
|
|
20300
20500
|
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
20301
20501
|
}
|
|
20302
20502
|
function assertValidExtractionCacheCompleteSentinel(path) {
|
|
20303
|
-
const sentinel =
|
|
20503
|
+
const sentinel = lstatSync4(path);
|
|
20304
20504
|
if (!sentinel.isFile() || sentinel.size !== 0) {
|
|
20305
20505
|
throw new PlanV2IntegrityError(
|
|
20306
20506
|
`${EXTRACTION_CACHE_COMPLETE_SENTINEL} must be a zero-byte regular file`
|
|
@@ -20308,13 +20508,13 @@ function assertValidExtractionCacheCompleteSentinel(path) {
|
|
|
20308
20508
|
}
|
|
20309
20509
|
}
|
|
20310
20510
|
function validateExtractionCacheCompleteSentinels(executionPlanDir) {
|
|
20311
|
-
const videoRoot =
|
|
20312
|
-
if (!
|
|
20511
|
+
const videoRoot = join45(executionPlanDir, "video-frames");
|
|
20512
|
+
if (!existsSync29(videoRoot)) return;
|
|
20313
20513
|
for (const videoEntry of readdirSync10(videoRoot, { withFileTypes: true })) {
|
|
20314
20514
|
if (!videoEntry.isDirectory()) continue;
|
|
20315
|
-
const videoDir =
|
|
20515
|
+
const videoDir = join45(videoRoot, videoEntry.name);
|
|
20316
20516
|
if (readdirSync10(videoDir).includes(EXTRACTION_CACHE_COMPLETE_SENTINEL)) {
|
|
20317
|
-
const sentinelPath =
|
|
20517
|
+
const sentinelPath = join45(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
|
|
20318
20518
|
assertValidExtractionCacheCompleteSentinel(sentinelPath);
|
|
20319
20519
|
}
|
|
20320
20520
|
}
|
|
@@ -20324,9 +20524,9 @@ function isExtractionCacheCompleteSentinelPath(path) {
|
|
|
20324
20524
|
return segments.length === 3 && segments[0] === "video-frames" && segments[1] !== "" && segments[2] === EXTRACTION_CACHE_COMPLETE_SENTINEL;
|
|
20325
20525
|
}
|
|
20326
20526
|
function resolveExtractedVideoOutputDir(planDir, videoId) {
|
|
20327
|
-
const videoRoot =
|
|
20328
|
-
const outputDir =
|
|
20329
|
-
if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${
|
|
20527
|
+
const videoRoot = resolve11(planDir, "video-frames");
|
|
20528
|
+
const outputDir = resolve11(videoRoot, mediaIdPathSegment4(videoId));
|
|
20529
|
+
if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep6}`)) {
|
|
20330
20530
|
throw new PlanV2IntegrityError(`unsafe extracted video id: ${JSON.stringify(videoId)}`);
|
|
20331
20531
|
}
|
|
20332
20532
|
return outputDir;
|
|
@@ -20361,7 +20561,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
20361
20561
|
if (video.deferredRange) {
|
|
20362
20562
|
const framePaths2 = /* @__PURE__ */ new Map();
|
|
20363
20563
|
for (let index = 0; index < video.totalFrames; index++) {
|
|
20364
|
-
framePaths2.set(index,
|
|
20564
|
+
framePaths2.set(index, join45(outputDir, String(index)));
|
|
20365
20565
|
}
|
|
20366
20566
|
return { ...video, outputDir, framePaths: framePaths2, ownedByLookup: false };
|
|
20367
20567
|
}
|
|
@@ -20369,7 +20569,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
20369
20569
|
const framePaths = /* @__PURE__ */ new Map();
|
|
20370
20570
|
for (const frameName of frameNames) {
|
|
20371
20571
|
if (frameName === EXTRACTION_CACHE_COMPLETE_SENTINEL) {
|
|
20372
|
-
assertValidExtractionCacheCompleteSentinel(
|
|
20572
|
+
assertValidExtractionCacheCompleteSentinel(join45(outputDir, frameName));
|
|
20373
20573
|
continue;
|
|
20374
20574
|
}
|
|
20375
20575
|
const match = /(\d+)(?=\.[^.]+$)/.exec(frameName);
|
|
@@ -20388,7 +20588,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
20388
20588
|
`duplicate extracted frame index ${frameIndex} in ${outputDir}`
|
|
20389
20589
|
);
|
|
20390
20590
|
}
|
|
20391
|
-
framePaths.set(frameIndex,
|
|
20591
|
+
framePaths.set(frameIndex, join45(outputDir, frameName));
|
|
20392
20592
|
}
|
|
20393
20593
|
return {
|
|
20394
20594
|
...video,
|
|
@@ -20409,8 +20609,8 @@ function parsePlanVideosJson2(value) {
|
|
|
20409
20609
|
}
|
|
20410
20610
|
}
|
|
20411
20611
|
function materializeExtractedVideoDirectories(planDir) {
|
|
20412
|
-
const videosPath =
|
|
20413
|
-
if (!
|
|
20612
|
+
const videosPath = join45(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
20613
|
+
if (!existsSync29(videosPath)) return;
|
|
20414
20614
|
const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
|
|
20415
20615
|
for (const video of videos.extracted) {
|
|
20416
20616
|
mkdirSync18(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
|
|
@@ -20443,13 +20643,13 @@ function parseChunkSlices(value) {
|
|
|
20443
20643
|
});
|
|
20444
20644
|
}
|
|
20445
20645
|
function buildVideoChunkDependencies(executionPlanDir, dimensions) {
|
|
20446
|
-
const videoRoot =
|
|
20447
|
-
const hasExtractedFrames =
|
|
20448
|
-
const videosPath =
|
|
20449
|
-
if (!
|
|
20646
|
+
const videoRoot = join45(executionPlanDir, "video-frames");
|
|
20647
|
+
const hasExtractedFrames = existsSync29(videoRoot) && listFiles(videoRoot).length > 0;
|
|
20648
|
+
const videosPath = join45(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
20649
|
+
if (!existsSync29(videosPath)) {
|
|
20450
20650
|
return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
|
|
20451
20651
|
}
|
|
20452
|
-
const chunksPath =
|
|
20652
|
+
const chunksPath = join45(executionPlanDir, "meta", "chunks.json");
|
|
20453
20653
|
const videos = readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
20454
20654
|
const chunks = readJsonFile(chunksPath, "meta/chunks.json");
|
|
20455
20655
|
const parsedVideos = parsePlanVideosJson2(videos);
|
|
@@ -20486,7 +20686,7 @@ function collectChunkVideoDependencies(input) {
|
|
|
20486
20686
|
for (let frame = chunk.startFrame; frame < chunk.endFrame; frame++) {
|
|
20487
20687
|
const globalTime = frame * input.fpsDen / input.fpsNum;
|
|
20488
20688
|
for (const [videoId, payload] of input.table.getActiveFramePayloads(globalTime)) {
|
|
20489
|
-
const path = input.deferredSources.get(videoId) ??
|
|
20689
|
+
const path = input.deferredSources.get(videoId) ?? relative8(resolve11(input.executionPlanDir), payload.framePath).split(sep6).join("/");
|
|
20490
20690
|
assertSafeRelativePath(path);
|
|
20491
20691
|
const indexes = mutable.get(path) ?? /* @__PURE__ */ new Set();
|
|
20492
20692
|
indexes.add(chunk.index);
|
|
@@ -20503,10 +20703,10 @@ function computeManifestHash(manifest) {
|
|
|
20503
20703
|
return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
|
|
20504
20704
|
}
|
|
20505
20705
|
function writeBlob(sourcePath, destinationPath) {
|
|
20506
|
-
if (
|
|
20706
|
+
if (existsSync29(destinationPath)) return;
|
|
20507
20707
|
mkdirSync18(dirname18(destinationPath), { recursive: true });
|
|
20508
20708
|
const temporaryDir = createStagingDir6(dirname18(destinationPath), ".plan-v2-blob-");
|
|
20509
|
-
const temporaryPath =
|
|
20709
|
+
const temporaryPath = join45(temporaryDir, "blob");
|
|
20510
20710
|
try {
|
|
20511
20711
|
copyFileSync8(sourcePath, temporaryPath);
|
|
20512
20712
|
renameWithRetry10(temporaryPath, destinationPath);
|
|
@@ -20542,8 +20742,8 @@ async function putTasks(tasks) {
|
|
|
20542
20742
|
if (failure) throw failure.reason;
|
|
20543
20743
|
}
|
|
20544
20744
|
function buildPlanV2Publication(executionPlanDir, digests) {
|
|
20545
|
-
const executionPlanPath =
|
|
20546
|
-
if (!
|
|
20745
|
+
const executionPlanPath = join45(executionPlanDir, "plan.json");
|
|
20746
|
+
if (!existsSync29(executionPlanPath)) {
|
|
20547
20747
|
throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
|
|
20548
20748
|
}
|
|
20549
20749
|
const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
|
|
@@ -20570,7 +20770,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
20570
20770
|
}
|
|
20571
20771
|
validateExtractionCacheCompleteSentinels(executionPlanDir);
|
|
20572
20772
|
const videoDependencyPlan = buildVideoChunkDependencies(executionPlanDir, dimensions);
|
|
20573
|
-
const encoder = readJsonFile(
|
|
20773
|
+
const encoder = readJsonFile(join45(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
|
|
20574
20774
|
const files = listFiles(executionPlanDir);
|
|
20575
20775
|
const chunkAudio = !isRecord3(encoder) || encoder.chunksCarryAudio !== true ? "none" : files.some((file) => chunkAudioSliceTarget(file.path) !== null) ? "sliced" : "whole";
|
|
20576
20776
|
for (const file of files) {
|
|
@@ -20623,7 +20823,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
20623
20823
|
};
|
|
20624
20824
|
}
|
|
20625
20825
|
function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
20626
|
-
if (
|
|
20826
|
+
if (existsSync29(planV2Dir)) {
|
|
20627
20827
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
20628
20828
|
}
|
|
20629
20829
|
const publication = buildPlanV2Publication(executionPlanDir);
|
|
@@ -20637,7 +20837,7 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
|
20637
20837
|
writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
|
|
20638
20838
|
}
|
|
20639
20839
|
writeFileSync12(
|
|
20640
|
-
|
|
20840
|
+
join45(tempDir, "plan.json"),
|
|
20641
20841
|
canonicalJsonStringify(publication.manifest),
|
|
20642
20842
|
"utf-8"
|
|
20643
20843
|
);
|
|
@@ -20678,7 +20878,7 @@ async function publishExecutionPlan(executionPlanDir, publisher, { digests, log
|
|
|
20678
20878
|
}
|
|
20679
20879
|
}
|
|
20680
20880
|
async function planV2WithPublisher(projectDir, config, publisher, options = {}) {
|
|
20681
|
-
const stagingRoot = createStagingDir6(options.stagingParentDir ??
|
|
20881
|
+
const stagingRoot = createStagingDir6(options.stagingParentDir ?? tmpdir4(), ".execution-plan-");
|
|
20682
20882
|
const digests = /* @__PURE__ */ new Map();
|
|
20683
20883
|
try {
|
|
20684
20884
|
const planned = await buildLocalExecutionPlan(projectDir, config, stagingRoot, {
|
|
@@ -20689,7 +20889,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
20689
20889
|
// artifactTargets ships every compiled/ file to all chunks, so each is in the manifest.
|
|
20690
20890
|
whileAudioMixes: () => putBlobs(
|
|
20691
20891
|
publisher,
|
|
20692
|
-
listFiles(
|
|
20892
|
+
listFiles(join45(stagingRoot, "compiled")).map(
|
|
20693
20893
|
(file) => publishBlobFor(file.absolutePath, digests)
|
|
20694
20894
|
)
|
|
20695
20895
|
),
|
|
@@ -20713,7 +20913,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
20713
20913
|
}
|
|
20714
20914
|
}
|
|
20715
20915
|
async function planV2(projectDir, config, planV2Dir) {
|
|
20716
|
-
if (
|
|
20916
|
+
if (existsSync29(planV2Dir)) {
|
|
20717
20917
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
20718
20918
|
}
|
|
20719
20919
|
const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
|
|
@@ -20730,7 +20930,7 @@ function resultFromManifest(planV2Dir, manifest) {
|
|
|
20730
20930
|
isRecord3(executionPlan) ? executionPlan[REFERENCE_BACKGROUND_FIELD3] : void 0
|
|
20731
20931
|
),
|
|
20732
20932
|
planDir: planV2Dir,
|
|
20733
|
-
manifestPath:
|
|
20933
|
+
manifestPath: join45(planV2Dir, "plan.json"),
|
|
20734
20934
|
planProtocol: PLAN_PROTOCOL_V2,
|
|
20735
20935
|
planHash: manifest.planHash,
|
|
20736
20936
|
sourcePlanV1Hash: getPlanV2ExecutionPlanHash(manifest),
|
|
@@ -20866,8 +21066,8 @@ function parsePlanV2Manifest(value) {
|
|
|
20866
21066
|
return parsed;
|
|
20867
21067
|
}
|
|
20868
21068
|
function readPlanV2Manifest(planV2Dir) {
|
|
20869
|
-
const manifestPath =
|
|
20870
|
-
if (!
|
|
21069
|
+
const manifestPath = join45(planV2Dir, "plan.json");
|
|
21070
|
+
if (!existsSync29(manifestPath)) {
|
|
20871
21071
|
throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
|
|
20872
21072
|
}
|
|
20873
21073
|
const value = readJsonFile(manifestPath, "v2 manifest");
|
|
@@ -20886,7 +21086,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
|
|
|
20886
21086
|
}
|
|
20887
21087
|
function verifyBlob(planV2Dir, artifact) {
|
|
20888
21088
|
const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
|
|
20889
|
-
if (!
|
|
21089
|
+
if (!existsSync29(sourcePath)) {
|
|
20890
21090
|
throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
|
|
20891
21091
|
}
|
|
20892
21092
|
const stats = statSync13(sourcePath);
|
|
@@ -20899,7 +21099,7 @@ function verifyBlob(planV2Dir, artifact) {
|
|
|
20899
21099
|
return sourcePath;
|
|
20900
21100
|
}
|
|
20901
21101
|
function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
|
|
20902
|
-
if (
|
|
21102
|
+
if (existsSync29(destinationDir)) {
|
|
20903
21103
|
throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
|
|
20904
21104
|
}
|
|
20905
21105
|
const manifest = readPlanV2Manifest(planV2Dir);
|
|
@@ -20915,13 +21115,13 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
20915
21115
|
const tempDir = createStagingDir6(dirname18(destinationDir), ".plan-v2-materialize-");
|
|
20916
21116
|
try {
|
|
20917
21117
|
for (const { artifact, sourcePath } of verified) {
|
|
20918
|
-
const destinationPath =
|
|
21118
|
+
const destinationPath = join45(tempDir, ...artifact.path.split("/"));
|
|
20919
21119
|
mkdirSync18(dirname18(destinationPath), { recursive: true });
|
|
20920
21120
|
copyFileSync8(sourcePath, destinationPath);
|
|
20921
21121
|
}
|
|
20922
21122
|
if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
|
|
20923
21123
|
writeFileSync12(
|
|
20924
|
-
|
|
21124
|
+
join45(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
|
|
20925
21125
|
canonicalJsonStringify({
|
|
20926
21126
|
manifest,
|
|
20927
21127
|
target,
|
|
@@ -20944,7 +21144,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
20944
21144
|
// Join the artifact's OWN name, not the current constant: a plan written
|
|
20945
21145
|
// before the container change carries the legacy name, and materializing it
|
|
20946
21146
|
// under the new one would point at a file that was never written.
|
|
20947
|
-
audioPath: target.role === "assembler" ? audioArtifact ?
|
|
21147
|
+
audioPath: target.role === "assembler" ? audioArtifact ? join45(destinationDir, audioArtifact.path) : null : null
|
|
20948
21148
|
};
|
|
20949
21149
|
}
|
|
20950
21150
|
function assertRemoteSources(remoteSources, artifacts) {
|
|
@@ -20963,8 +21163,8 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
|
|
|
20963
21163
|
return readValidatedPlanV2Materialization(planDir, expectedTarget)?.manifest ?? null;
|
|
20964
21164
|
}
|
|
20965
21165
|
function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
20966
|
-
const markerPath =
|
|
20967
|
-
if (!
|
|
21166
|
+
const markerPath = join45(planDir, PLAN_V2_MATERIALIZATION_MARKER);
|
|
21167
|
+
if (!existsSync29(markerPath)) return null;
|
|
20968
21168
|
const marker = readJsonFile(markerPath, "materialization marker");
|
|
20969
21169
|
if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
|
|
20970
21170
|
throw new PlanV2IntegrityError("malformed materialization marker");
|
|
@@ -20981,8 +21181,8 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
|
20981
21181
|
assertRemoteSources(remoteSources, required);
|
|
20982
21182
|
for (const artifact of required) {
|
|
20983
21183
|
if (Object.hasOwn(remoteSources, artifact.path)) continue;
|
|
20984
|
-
const path =
|
|
20985
|
-
if (!
|
|
21184
|
+
const path = join45(planDir, ...artifact.path.split("/"));
|
|
21185
|
+
if (!existsSync29(path) || statSync13(path).size !== artifact.sizeBytes) {
|
|
20986
21186
|
throw new PlanV2IntegrityError(
|
|
20987
21187
|
`materialized artifact missing or truncated: ${artifact.path}`
|
|
20988
21188
|
);
|
|
@@ -21113,7 +21313,7 @@ function hashChunkOutput(outputPath, kind) {
|
|
|
21113
21313
|
if (kind === "file") return sha256Hex(readFileSync14(outputPath));
|
|
21114
21314
|
const entries = readdirSync11(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
|
|
21115
21315
|
const lines = entries.map(
|
|
21116
|
-
(name) => `${name}\0${sha256Hex(readFileSync14(
|
|
21316
|
+
(name) => `${name}\0${sha256Hex(readFileSync14(join46(outputPath, name)))}`
|
|
21117
21317
|
);
|
|
21118
21318
|
return sha256Hex(lines.join("\0"));
|
|
21119
21319
|
}
|
|
@@ -21130,10 +21330,10 @@ function resolveLockedVp9CpuUsed(lockedEncoder) {
|
|
|
21130
21330
|
async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
21131
21331
|
const start = Date.now();
|
|
21132
21332
|
const log = defaultLogger;
|
|
21133
|
-
const planJsonPath =
|
|
21134
|
-
const encoderJsonPath =
|
|
21135
|
-
const chunksJsonPath =
|
|
21136
|
-
if (!
|
|
21333
|
+
const planJsonPath = join46(planDir, "plan.json");
|
|
21334
|
+
const encoderJsonPath = join46(planDir, "meta", "encoder.json");
|
|
21335
|
+
const chunksJsonPath = join46(planDir, "meta", "chunks.json");
|
|
21336
|
+
if (!existsSync30(planJsonPath)) {
|
|
21137
21337
|
throw new RenderChunkValidationError(
|
|
21138
21338
|
MISSING_PLAN_ARTIFACT,
|
|
21139
21339
|
`[renderChunk] planDir is missing required artifact: ${planJsonPath}`
|
|
@@ -21149,7 +21349,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21149
21349
|
const v2Manifest = v2Materialization?.manifest ?? null;
|
|
21150
21350
|
const remoteSources = v2Materialization?.remoteSources ?? {};
|
|
21151
21351
|
for (const required of [encoderJsonPath, chunksJsonPath]) {
|
|
21152
|
-
if (!
|
|
21352
|
+
if (!existsSync30(required)) {
|
|
21153
21353
|
throw new RenderChunkValidationError(
|
|
21154
21354
|
MISSING_PLAN_ARTIFACT,
|
|
21155
21355
|
`[renderChunk] planDir is missing required artifact: ${required}`
|
|
@@ -21158,9 +21358,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21158
21358
|
}
|
|
21159
21359
|
const encoder = JSON.parse(readFileSync14(encoderJsonPath, "utf-8"));
|
|
21160
21360
|
const chunks = JSON.parse(readFileSync14(chunksJsonPath, "utf-8"));
|
|
21161
|
-
const videosJsonPath =
|
|
21361
|
+
const videosJsonPath = join46(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21162
21362
|
let planVideos = null;
|
|
21163
|
-
if (
|
|
21363
|
+
if (existsSync30(videosJsonPath)) {
|
|
21164
21364
|
try {
|
|
21165
21365
|
planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync14(videosJsonPath, "utf-8")));
|
|
21166
21366
|
} catch (err) {
|
|
@@ -21190,8 +21390,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21190
21390
|
}
|
|
21191
21391
|
const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
|
|
21192
21392
|
const framesInChunk = range.endFrame - range.startFrame;
|
|
21193
|
-
const compiledDir =
|
|
21194
|
-
if (!
|
|
21393
|
+
const compiledDir = join46(planDir, "compiled");
|
|
21394
|
+
if (!existsSync30(compiledDir)) {
|
|
21195
21395
|
throw new RenderChunkValidationError(
|
|
21196
21396
|
MISSING_PLAN_ARTIFACT,
|
|
21197
21397
|
`[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
|
|
@@ -21249,7 +21449,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21249
21449
|
};
|
|
21250
21450
|
const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
21251
21451
|
mkdirSync19(workDir, { recursive: true });
|
|
21252
|
-
const framesDir =
|
|
21452
|
+
const framesDir = join46(workDir, "captured-frames");
|
|
21253
21453
|
mkdirSync19(framesDir, { recursive: true });
|
|
21254
21454
|
const videoFramesDir = `${workDir}.video-frames`;
|
|
21255
21455
|
const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
|
|
@@ -21274,7 +21474,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21274
21474
|
dimensions: plan2.dimensions,
|
|
21275
21475
|
encoder,
|
|
21276
21476
|
videoCount: planVideos?.videos.length ?? 0,
|
|
21277
|
-
html: readFileSync14(
|
|
21477
|
+
html: readFileSync14(join46(compiledDir, "index.html"), "utf-8"),
|
|
21278
21478
|
// The plan ships a deferred source only to chunks that show it; don't wait on the rest.
|
|
21279
21479
|
skipReadinessVideoIds: deferredVideos.filter(
|
|
21280
21480
|
(video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
|
|
@@ -21308,8 +21508,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21308
21508
|
const verifyInWorker = chunkWorkerCount > 1 && !forceScreenshotForChunk;
|
|
21309
21509
|
let boxesMeasured;
|
|
21310
21510
|
let boxesFailed;
|
|
21311
|
-
const boxesReady = new Promise((
|
|
21312
|
-
boxesMeasured =
|
|
21511
|
+
const boxesReady = new Promise((resolve14, reject) => {
|
|
21512
|
+
boxesMeasured = resolve14;
|
|
21313
21513
|
boxesFailed = reject;
|
|
21314
21514
|
});
|
|
21315
21515
|
boxesReady.catch(() => {
|
|
@@ -21443,10 +21643,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21443
21643
|
const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
|
|
21444
21644
|
const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
|
|
21445
21645
|
if (isPngSequence) {
|
|
21446
|
-
if (!
|
|
21646
|
+
if (!existsSync30(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
|
|
21447
21647
|
} else {
|
|
21448
|
-
const outDir =
|
|
21449
|
-
if (!
|
|
21648
|
+
const outDir = join46(outputChunkPath, "..");
|
|
21649
|
+
if (!existsSync30(outDir)) mkdirSync19(outDir, { recursive: true });
|
|
21450
21650
|
}
|
|
21451
21651
|
const encodeInput = {
|
|
21452
21652
|
job,
|
|
@@ -21722,10 +21922,10 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
21722
21922
|
if (config.cfr === true) {
|
|
21723
21923
|
throw new RenderSpanUnsupportedError("--start/--end cannot be combined with a cfr re-encode.");
|
|
21724
21924
|
}
|
|
21725
|
-
const workDir = mkdtempSync(
|
|
21925
|
+
const workDir = mkdtempSync(join47(tmpdir5(), "hf-render-span-"));
|
|
21726
21926
|
try {
|
|
21727
|
-
const planDir =
|
|
21728
|
-
const partsDir =
|
|
21927
|
+
const planDir = join47(workDir, "plan");
|
|
21928
|
+
const partsDir = join47(workDir, "parts");
|
|
21729
21929
|
mkdirSync20(partsDir, { recursive: true });
|
|
21730
21930
|
const planned = await plan(
|
|
21731
21931
|
projectDir,
|
|
@@ -21744,7 +21944,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
21744
21944
|
planned.totalFrames
|
|
21745
21945
|
);
|
|
21746
21946
|
const slices = JSON.parse(
|
|
21747
|
-
readFileSync15(
|
|
21947
|
+
readFileSync15(join47(planDir, "meta", "chunks.json"), "utf-8")
|
|
21748
21948
|
);
|
|
21749
21949
|
const parts = [];
|
|
21750
21950
|
for (const slice of slices) {
|
|
@@ -21754,7 +21954,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
21754
21954
|
};
|
|
21755
21955
|
if (range.endFrame <= range.startFrame) continue;
|
|
21756
21956
|
throwIfAborted(config.abortSignal);
|
|
21757
|
-
const part =
|
|
21957
|
+
const part = join47(partsDir, `part-${String(parts.length).padStart(4, "0")}.mp4`);
|
|
21758
21958
|
await renderChunk(planDir, slice.index, part, { frameRange: range });
|
|
21759
21959
|
parts.push(part);
|
|
21760
21960
|
}
|
|
@@ -22410,7 +22610,7 @@ import {
|
|
|
22410
22610
|
|
|
22411
22611
|
// src/server.ts
|
|
22412
22612
|
import {
|
|
22413
|
-
existsSync as
|
|
22613
|
+
existsSync as existsSync33,
|
|
22414
22614
|
mkdirSync as mkdirSync21,
|
|
22415
22615
|
statSync as statSync15,
|
|
22416
22616
|
mkdtempSync as mkdtempSync2,
|
|
@@ -22418,8 +22618,8 @@ import {
|
|
|
22418
22618
|
rmSync as rmSync19,
|
|
22419
22619
|
createReadStream as createReadStream5
|
|
22420
22620
|
} from "node:fs";
|
|
22421
|
-
import { resolve as
|
|
22422
|
-
import { tmpdir as
|
|
22621
|
+
import { resolve as resolve13, dirname as dirname21, join as join50 } from "node:path";
|
|
22622
|
+
import { tmpdir as tmpdir6 } from "node:os";
|
|
22423
22623
|
import { parseArgs } from "node:util";
|
|
22424
22624
|
import { isIP } from "node:net";
|
|
22425
22625
|
import crypto from "node:crypto";
|
|
@@ -22435,7 +22635,7 @@ import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
|
|
|
22435
22635
|
|
|
22436
22636
|
// src/services/hyperframeLint.ts
|
|
22437
22637
|
import {
|
|
22438
|
-
existsSync as
|
|
22638
|
+
existsSync as existsSync31,
|
|
22439
22639
|
readFileSync as readFileSync16,
|
|
22440
22640
|
statSync as statSync14,
|
|
22441
22641
|
openSync as openSync7,
|
|
@@ -22443,7 +22643,7 @@ import {
|
|
|
22443
22643
|
closeSync as closeSync7,
|
|
22444
22644
|
constants as constants3
|
|
22445
22645
|
} from "node:fs";
|
|
22446
|
-
import { resolve as
|
|
22646
|
+
import { resolve as resolve12, join as join48, relative as relative9, isAbsolute as isAbsolute6, sep as sep7, dirname as dirname19 } from "node:path";
|
|
22447
22647
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
22448
22648
|
import { Worker as Worker2 } from "node:worker_threads";
|
|
22449
22649
|
function isStringRecord(value) {
|
|
@@ -22489,19 +22689,19 @@ function readEntryHtml(filePath) {
|
|
|
22489
22689
|
}
|
|
22490
22690
|
}
|
|
22491
22691
|
function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
22492
|
-
const entryRelativePath =
|
|
22493
|
-
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${
|
|
22692
|
+
const entryRelativePath = relative9(absProjectDir, absoluteEntryPath);
|
|
22693
|
+
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep7}`) || isAbsolute6(entryRelativePath) || isAllowedEntry !== void 0 && !isAllowedEntry(absoluteEntryPath);
|
|
22494
22694
|
}
|
|
22495
22695
|
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
22496
|
-
const absProjectDir =
|
|
22497
|
-
if (!
|
|
22696
|
+
const absProjectDir = resolve12(projectDir);
|
|
22697
|
+
if (!existsSync31(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
|
|
22498
22698
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
22499
22699
|
}
|
|
22500
22700
|
const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
|
|
22501
22701
|
(value) => typeof value === "string" && value.trim().length > 0
|
|
22502
22702
|
);
|
|
22503
22703
|
for (const entryFile of entryCandidates) {
|
|
22504
|
-
const absoluteEntryPath =
|
|
22704
|
+
const absoluteEntryPath = resolve12(absProjectDir, entryFile);
|
|
22505
22705
|
if (leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry)) {
|
|
22506
22706
|
return { error: `Entry file must stay inside project directory: ${entryFile}` };
|
|
22507
22707
|
}
|
|
@@ -22515,7 +22715,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
|
22515
22715
|
}
|
|
22516
22716
|
}
|
|
22517
22717
|
return {
|
|
22518
|
-
error: `No HTML entry file found in project directory: ${
|
|
22718
|
+
error: `No HTML entry file found in project directory: ${join48(absProjectDir, preferredEntryFile || "index.html")}`
|
|
22519
22719
|
};
|
|
22520
22720
|
}
|
|
22521
22721
|
function prepareHyperframeLintBody(body, isAllowedEntry) {
|
|
@@ -22561,16 +22761,16 @@ function takeLintSlot(limit, waitMs) {
|
|
|
22561
22761
|
running++;
|
|
22562
22762
|
return Promise.resolve(true);
|
|
22563
22763
|
}
|
|
22564
|
-
return new Promise((
|
|
22764
|
+
return new Promise((resolve14) => {
|
|
22565
22765
|
const entry = () => {
|
|
22566
22766
|
clearTimeout(timer);
|
|
22567
22767
|
running++;
|
|
22568
|
-
|
|
22768
|
+
resolve14(true);
|
|
22569
22769
|
};
|
|
22570
22770
|
const timer = setTimeout(
|
|
22571
22771
|
() => {
|
|
22572
22772
|
waiting.splice(waiting.indexOf(entry), 1);
|
|
22573
|
-
|
|
22773
|
+
resolve14(false);
|
|
22574
22774
|
},
|
|
22575
22775
|
Math.max(0, waitMs)
|
|
22576
22776
|
);
|
|
@@ -22584,8 +22784,8 @@ function freeLintSlot() {
|
|
|
22584
22784
|
function resolveLintWorkerEntry() {
|
|
22585
22785
|
const here = dirname19(fileURLToPath6(import.meta.url));
|
|
22586
22786
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
22587
|
-
const candidate =
|
|
22588
|
-
if (
|
|
22787
|
+
const candidate = join48(here, name);
|
|
22788
|
+
if (existsSync31(candidate)) return candidate;
|
|
22589
22789
|
}
|
|
22590
22790
|
return void 0;
|
|
22591
22791
|
}
|
|
@@ -22655,8 +22855,8 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
22655
22855
|
// src/services/healthWorker.ts
|
|
22656
22856
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
22657
22857
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
22658
|
-
import { dirname as dirname20, join as
|
|
22659
|
-
import { existsSync as
|
|
22858
|
+
import { dirname as dirname20, join as join49 } from "node:path";
|
|
22859
|
+
import { existsSync as existsSync32 } from "node:fs";
|
|
22660
22860
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
22661
22861
|
async function startHealthWorker(options = {}) {
|
|
22662
22862
|
const log = options.logger ?? defaultLogger2();
|
|
@@ -22674,12 +22874,12 @@ async function startHealthWorker(options = {}) {
|
|
|
22674
22874
|
stdout: false,
|
|
22675
22875
|
stderr: false
|
|
22676
22876
|
});
|
|
22677
|
-
await new Promise((
|
|
22877
|
+
await new Promise((resolve14, reject) => {
|
|
22678
22878
|
const onMessage = (msg) => {
|
|
22679
22879
|
if (msg?.type === "listening") {
|
|
22680
22880
|
worker.off("error", onError);
|
|
22681
22881
|
worker.off("message", onMessage);
|
|
22682
|
-
|
|
22882
|
+
resolve14();
|
|
22683
22883
|
} else if (msg?.type === "listen-error") {
|
|
22684
22884
|
worker.off("error", onError);
|
|
22685
22885
|
worker.off("message", onMessage);
|
|
@@ -22731,9 +22931,9 @@ function defaultLogger2() {
|
|
|
22731
22931
|
}
|
|
22732
22932
|
function resolveWorkerEntry2() {
|
|
22733
22933
|
const here = dirname20(fileURLToPath7(import.meta.url));
|
|
22734
|
-
const candidates = [
|
|
22934
|
+
const candidates = [join49(here, "healthWorkerThread.js"), join49(here, "healthWorkerThread.ts")];
|
|
22735
22935
|
for (const candidate of candidates) {
|
|
22736
|
-
if (
|
|
22936
|
+
if (existsSync32(candidate)) return candidate;
|
|
22737
22937
|
}
|
|
22738
22938
|
return void 0;
|
|
22739
22939
|
}
|
|
@@ -22903,7 +23103,7 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
22903
23103
|
}
|
|
22904
23104
|
}
|
|
22905
23105
|
const outputDir = dirname21(absoluteOutputPath);
|
|
22906
|
-
if (!
|
|
23106
|
+
if (!existsSync33(outputDir)) mkdirSync21(outputDir, { recursive: true });
|
|
22907
23107
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
22908
23108
|
}
|
|
22909
23109
|
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
@@ -22964,7 +23164,7 @@ function validateOutputResolutionOverride(body) {
|
|
|
22964
23164
|
var MAX_PREVIEW_HTML_BYTES = 20 * 1024 * 1024;
|
|
22965
23165
|
function resolveRenderRequestPolicy(options) {
|
|
22966
23166
|
return {
|
|
22967
|
-
projectsDir:
|
|
23167
|
+
projectsDir: resolve13(
|
|
22968
23168
|
options.projectsDir ?? (process.env.PRODUCER_PROJECTS_DIR || process.cwd())
|
|
22969
23169
|
),
|
|
22970
23170
|
allowDebug: options.allowDebug ?? process.env.PRODUCER_ALLOW_DEBUG === "1"
|
|
@@ -22979,14 +23179,14 @@ function isAllowedEntryPath(policy, projectDir, path) {
|
|
|
22979
23179
|
function prepareProjectDirectory(projectDir, options, policy) {
|
|
22980
23180
|
const candidate = nonEmptyString(projectDir);
|
|
22981
23181
|
if (!candidate) return null;
|
|
22982
|
-
const absProjectDir = policy ?
|
|
23182
|
+
const absProjectDir = policy ? resolve13(policy.projectsDir, candidate) : resolve13(candidate);
|
|
22983
23183
|
const shown = policy ? candidate : absProjectDir;
|
|
22984
|
-
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !
|
|
23184
|
+
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync33(absProjectDir) || !statSync15(absProjectDir).isDirectory()) {
|
|
22985
23185
|
return { error: `Project directory not found: ${shown}` };
|
|
22986
23186
|
}
|
|
22987
23187
|
const entry = options.entryFile || "index.html";
|
|
22988
|
-
const entryPath =
|
|
22989
|
-
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !
|
|
23188
|
+
const entryPath = resolve13(absProjectDir, entry);
|
|
23189
|
+
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync33(entryPath)) {
|
|
22990
23190
|
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
22991
23191
|
}
|
|
22992
23192
|
return { prepared: { input: { projectDir: absProjectDir, ...options } } };
|
|
@@ -23006,9 +23206,9 @@ async function resolveInlineRenderHtml(body) {
|
|
|
23006
23206
|
}
|
|
23007
23207
|
}
|
|
23008
23208
|
function materializeInlineProject(html, options) {
|
|
23009
|
-
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR ||
|
|
23010
|
-
const tempProjectDir = mkdtempSync2(
|
|
23011
|
-
writeFileSync14(
|
|
23209
|
+
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
|
|
23210
|
+
const tempProjectDir = mkdtempSync2(join50(tempRoot, "producer-project-"));
|
|
23211
|
+
writeFileSync14(join50(tempProjectDir, "index.html"), html, "utf-8");
|
|
23012
23212
|
return {
|
|
23013
23213
|
prepared: {
|
|
23014
23214
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -23036,7 +23236,7 @@ function resolveOutputPath(projectDir, outputCandidate, rendersDir, log) {
|
|
|
23036
23236
|
try {
|
|
23037
23237
|
return resolveRenderPaths(projectDir, outputCandidate, rendersDir).absoluteOutputPath;
|
|
23038
23238
|
} catch (error) {
|
|
23039
|
-
const fallbackPath =
|
|
23239
|
+
const fallbackPath = resolve13(rendersDir, `producer-fallback-${Date.now()}.mp4`);
|
|
23040
23240
|
log.warn("Failed to resolve output path, using fallback", {
|
|
23041
23241
|
fallback: fallbackPath,
|
|
23042
23242
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -23084,7 +23284,7 @@ function publicPerfSummary(job) {
|
|
|
23084
23284
|
return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
|
|
23085
23285
|
}
|
|
23086
23286
|
function outputFileSize(path) {
|
|
23087
|
-
return
|
|
23287
|
+
return existsSync33(path) ? statSync15(path).size : 0;
|
|
23088
23288
|
}
|
|
23089
23289
|
function createBlockingProgressReporter(log, requestId) {
|
|
23090
23290
|
let lastLoggedPct = -10;
|
|
@@ -23204,7 +23404,7 @@ function createRenderHandlers(options = {}) {
|
|
|
23204
23404
|
const lintProjectDir = nonEmptyString(body.projectDir);
|
|
23205
23405
|
let isAllowedEntry;
|
|
23206
23406
|
if (policy && lintProjectDir) {
|
|
23207
|
-
const absProjectDir =
|
|
23407
|
+
const absProjectDir = resolve13(policy.projectsDir, lintProjectDir);
|
|
23208
23408
|
if (!isAllowedProjectPath(policy.projectsDir, absProjectDir)) {
|
|
23209
23409
|
const error = `Project directory not found: ${lintProjectDir}`;
|
|
23210
23410
|
return c.json({ success: false, requestId, error }, 400);
|
|
@@ -23411,7 +23611,7 @@ function createRenderHandlers(options = {}) {
|
|
|
23411
23611
|
if (!artifact) {
|
|
23412
23612
|
return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
|
|
23413
23613
|
}
|
|
23414
|
-
if (!
|
|
23614
|
+
if (!existsSync33(artifact.path)) {
|
|
23415
23615
|
store.delete(token);
|
|
23416
23616
|
return c.json({ success: false, error: "Output artifact file missing" }, 404);
|
|
23417
23617
|
}
|
|
@@ -23576,7 +23776,7 @@ function startServer(options = {}) {
|
|
|
23576
23776
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
23577
23777
|
return server;
|
|
23578
23778
|
}
|
|
23579
|
-
var entryScript = process.argv[1] ?
|
|
23779
|
+
var entryScript = process.argv[1] ? resolve13(process.argv[1]) : "";
|
|
23580
23780
|
var isPublicServerEntry = entryScript.endsWith("/public-server.js") || entryScript.endsWith("/src/server.ts");
|
|
23581
23781
|
if (isPublicServerEntry) {
|
|
23582
23782
|
const { values } = parseArgs({
|
|
@@ -23601,8 +23801,8 @@ import { quantizeTimeToFrame, MEDIA_VISUAL_STYLE_PROPERTIES } from "@hyperframes
|
|
|
23601
23801
|
|
|
23602
23802
|
// src/services/distributed/planV2Execution.ts
|
|
23603
23803
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync21 } from "node:fs";
|
|
23604
|
-
import { tmpdir as
|
|
23605
|
-
import { join as
|
|
23804
|
+
import { tmpdir as tmpdir7 } from "node:os";
|
|
23805
|
+
import { join as join52 } from "node:path";
|
|
23606
23806
|
|
|
23607
23807
|
// src/services/distributed/assemble.ts
|
|
23608
23808
|
import {
|
|
@@ -23611,7 +23811,7 @@ import {
|
|
|
23611
23811
|
} from "@hyperframes/engine";
|
|
23612
23812
|
import {
|
|
23613
23813
|
cpSync as cpSync3,
|
|
23614
|
-
existsSync as
|
|
23814
|
+
existsSync as existsSync34,
|
|
23615
23815
|
mkdirSync as mkdirSync22,
|
|
23616
23816
|
readFileSync as readFileSync17,
|
|
23617
23817
|
readdirSync as readdirSync12,
|
|
@@ -23619,7 +23819,7 @@ import {
|
|
|
23619
23819
|
statSync as statSync16,
|
|
23620
23820
|
writeFileSync as writeFileSync15
|
|
23621
23821
|
} from "node:fs";
|
|
23622
|
-
import { basename as
|
|
23822
|
+
import { basename as basename9, dirname as dirname22, join as join51 } from "node:path";
|
|
23623
23823
|
import {
|
|
23624
23824
|
appendRateCapArgs as appendRateCapArgs2,
|
|
23625
23825
|
appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
|
|
@@ -23666,10 +23866,10 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23666
23866
|
}
|
|
23667
23867
|
const format = plan2.dimensions.format;
|
|
23668
23868
|
const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
|
|
23669
|
-
if (!
|
|
23869
|
+
if (!existsSync34(dirname22(outputPath))) {
|
|
23670
23870
|
mkdirSync22(dirname22(outputPath), { recursive: true });
|
|
23671
23871
|
}
|
|
23672
|
-
const workDir = createStagingDir7(dirname22(outputPath), `${
|
|
23872
|
+
const workDir = createStagingDir7(dirname22(outputPath), `${basename9(outputPath)}.assemble-work-`);
|
|
23673
23873
|
const fps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
23674
23874
|
const stageMs = {};
|
|
23675
23875
|
const ctx = {
|
|
@@ -23689,8 +23889,8 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23689
23889
|
};
|
|
23690
23890
|
try {
|
|
23691
23891
|
const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
|
|
23692
|
-
const finalPath =
|
|
23693
|
-
const audio = audioPath !== null &&
|
|
23892
|
+
const finalPath = join51(workDir, `output.${format}`);
|
|
23893
|
+
const audio = audioPath !== null && existsSync34(audioPath) ? audioPath : null;
|
|
23694
23894
|
await writeJoined(ctx, videoSources, audio, finalPath);
|
|
23695
23895
|
renameWithRetry11(finalPath, outputPath);
|
|
23696
23896
|
log.info("[assemble] stage timings", {
|
|
@@ -23708,7 +23908,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23708
23908
|
});
|
|
23709
23909
|
}
|
|
23710
23910
|
}
|
|
23711
|
-
const fileSize =
|
|
23911
|
+
const fileSize = existsSync34(outputPath) ? statSync16(outputPath).size : 0;
|
|
23712
23912
|
return {
|
|
23713
23913
|
...referenceBackgroundResult8(plan2[REFERENCE_BACKGROUND_FIELD6]),
|
|
23714
23914
|
outputPath,
|
|
@@ -23718,15 +23918,15 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23718
23918
|
};
|
|
23719
23919
|
}
|
|
23720
23920
|
function readAssemblePlan(planDir, chunkPaths) {
|
|
23721
|
-
const planJsonPath =
|
|
23722
|
-
const chunksJsonPath =
|
|
23723
|
-
if (!
|
|
23921
|
+
const planJsonPath = join51(planDir, "plan.json");
|
|
23922
|
+
const chunksJsonPath = join51(planDir, "meta", "chunks.json");
|
|
23923
|
+
if (!existsSync34(planJsonPath)) {
|
|
23724
23924
|
throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
|
|
23725
23925
|
}
|
|
23726
23926
|
const plan2 = JSON.parse(readFileSync17(planJsonPath, "utf-8"));
|
|
23727
23927
|
readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
|
|
23728
23928
|
validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
|
|
23729
|
-
if (!
|
|
23929
|
+
if (!existsSync34(chunksJsonPath)) {
|
|
23730
23930
|
throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
|
|
23731
23931
|
}
|
|
23732
23932
|
const chunks = JSON.parse(readFileSync17(chunksJsonPath, "utf-8"));
|
|
@@ -23741,7 +23941,7 @@ function readAssemblePlan(planDir, chunkPaths) {
|
|
|
23741
23941
|
}
|
|
23742
23942
|
}
|
|
23743
23943
|
for (const path of chunkPaths.flat()) {
|
|
23744
|
-
if (!
|
|
23944
|
+
if (!existsSync34(path)) {
|
|
23745
23945
|
throw new Error(`[assemble] chunk path does not exist: ${path}`);
|
|
23746
23946
|
}
|
|
23747
23947
|
}
|
|
@@ -23770,7 +23970,7 @@ function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
|
|
|
23770
23970
|
return args;
|
|
23771
23971
|
}
|
|
23772
23972
|
async function reencodeCfr(ctx, chunkPaths, encoder) {
|
|
23773
|
-
const cfrOutputPath =
|
|
23973
|
+
const cfrOutputPath = join51(ctx.workDir, `cfr.${ctx.format}`);
|
|
23774
23974
|
const cfrArgs = cfrEncodeArgs(videoInputArgs(ctx, chunkPaths), encoder, ctx.fpsArg);
|
|
23775
23975
|
appendRenderProvenanceArgs2(cfrArgs, cfrOutputPath);
|
|
23776
23976
|
cfrArgs.push("-y", cfrOutputPath);
|
|
@@ -23797,7 +23997,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
23797
23997
|
);
|
|
23798
23998
|
return;
|
|
23799
23999
|
}
|
|
23800
|
-
const paddedAudioPath =
|
|
24000
|
+
const paddedAudioPath = join51(ctx.workDir, "audio-padded.m4a");
|
|
23801
24001
|
const padTrimResult = await ctx.timed(
|
|
23802
24002
|
"audioMs",
|
|
23803
24003
|
() => padOrTrimAudioToVideoFrameCount({
|
|
@@ -23837,7 +24037,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
23837
24037
|
}
|
|
23838
24038
|
}
|
|
23839
24039
|
function concatDemuxerInput(chunkPaths, workDir, fpsArg) {
|
|
23840
|
-
const listPath =
|
|
24040
|
+
const listPath = join51(workDir, "concat-list.txt");
|
|
23841
24041
|
const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
|
|
23842
24042
|
writeFileSync15(listPath, `${body}
|
|
23843
24043
|
`, "utf-8");
|
|
@@ -23875,12 +24075,12 @@ function stitchesSeparateAudio(planDir) {
|
|
|
23875
24075
|
return lockedAudio(planDir).separateAudio === true;
|
|
23876
24076
|
}
|
|
23877
24077
|
function planFormat(planDir) {
|
|
23878
|
-
const plan2 = JSON.parse(readFileSync17(
|
|
24078
|
+
const plan2 = JSON.parse(readFileSync17(join51(planDir, "plan.json"), "utf-8"));
|
|
23879
24079
|
return plan2.dimensions.format;
|
|
23880
24080
|
}
|
|
23881
24081
|
function lockedAudio(planDir) {
|
|
23882
|
-
const encoderJsonPath =
|
|
23883
|
-
if (!
|
|
24082
|
+
const encoderJsonPath = join51(planDir, "meta", "encoder.json");
|
|
24083
|
+
if (!existsSync34(encoderJsonPath)) return {};
|
|
23884
24084
|
return JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
|
|
23885
24085
|
}
|
|
23886
24086
|
function readCfrEncoder(planDir, format) {
|
|
@@ -23889,8 +24089,8 @@ function readCfrEncoder(planDir, format) {
|
|
|
23889
24089
|
`[assemble] cfr=true is only supported for format="mp4" (got "${format}"). Stream-copy paths for webm and mov already produce exact avg_frame_rate; cfr re-encode is not needed.`
|
|
23890
24090
|
);
|
|
23891
24091
|
}
|
|
23892
|
-
const encoderJsonPath =
|
|
23893
|
-
if (!
|
|
24092
|
+
const encoderJsonPath = join51(planDir, "meta", "encoder.json");
|
|
24093
|
+
if (!existsSync34(encoderJsonPath)) {
|
|
23894
24094
|
throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
|
|
23895
24095
|
}
|
|
23896
24096
|
const encoderJson = JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
|
|
@@ -23902,7 +24102,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
23902
24102
|
return encoderJson;
|
|
23903
24103
|
}
|
|
23904
24104
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
23905
|
-
if (
|
|
24105
|
+
if (existsSync34(outputPath)) rmSync20(outputPath, { recursive: true, force: true });
|
|
23906
24106
|
mkdirSync22(outputPath, { recursive: true });
|
|
23907
24107
|
let globalIdx = 0;
|
|
23908
24108
|
for (const chunkDir of chunkPaths) {
|
|
@@ -23916,8 +24116,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
23916
24116
|
throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
|
|
23917
24117
|
}
|
|
23918
24118
|
for (const frame of frames) {
|
|
23919
|
-
const dst =
|
|
23920
|
-
cpSync3(
|
|
24119
|
+
const dst = join51(outputPath, formatExportFrameName(globalIdx, "png"));
|
|
24120
|
+
cpSync3(join51(chunkDir, frame), dst);
|
|
23921
24121
|
globalIdx += 1;
|
|
23922
24122
|
}
|
|
23923
24123
|
}
|
|
@@ -23926,14 +24126,14 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
23926
24126
|
`[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
|
|
23927
24127
|
);
|
|
23928
24128
|
}
|
|
23929
|
-
if (audioPath !== null &&
|
|
23930
|
-
const sidecar =
|
|
24129
|
+
if (audioPath !== null && existsSync34(audioPath)) {
|
|
24130
|
+
const sidecar = join51(outputPath, MIXED_AUDIO_FILENAME4);
|
|
23931
24131
|
cpSync3(audioPath, sidecar);
|
|
23932
24132
|
}
|
|
23933
24133
|
let fileSize = 0;
|
|
23934
24134
|
for (const name of readdirSync12(outputPath)) {
|
|
23935
24135
|
try {
|
|
23936
|
-
fileSize += statSync16(
|
|
24136
|
+
fileSize += statSync16(join51(outputPath, name)).size;
|
|
23937
24137
|
} catch {
|
|
23938
24138
|
}
|
|
23939
24139
|
}
|
|
@@ -23947,8 +24147,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
23947
24147
|
|
|
23948
24148
|
// src/services/distributed/planV2Execution.ts
|
|
23949
24149
|
async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
23950
|
-
const workRoot = mkdtempSync3(
|
|
23951
|
-
const materializedPlanDir =
|
|
24150
|
+
const workRoot = mkdtempSync3(join52(tmpdir7(), "hf-plan-v2-chunk-"));
|
|
24151
|
+
const materializedPlanDir = join52(workRoot, "plan");
|
|
23952
24152
|
try {
|
|
23953
24153
|
materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
|
|
23954
24154
|
return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
|
|
@@ -23957,8 +24157,8 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
|
23957
24157
|
}
|
|
23958
24158
|
}
|
|
23959
24159
|
async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
23960
|
-
const workRoot = mkdtempSync3(
|
|
23961
|
-
const materializedPlanDir =
|
|
24160
|
+
const workRoot = mkdtempSync3(join52(tmpdir7(), "hf-plan-v2-assembler-"));
|
|
24161
|
+
const materializedPlanDir = join52(workRoot, "plan");
|
|
23962
24162
|
try {
|
|
23963
24163
|
const materialized = materializePlanV2Target(
|
|
23964
24164
|
planV2Dir,
|