@effing/ffs 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/{chunk-LK5K4SQV.js → chunk-6YHSYHDY.js} +182 -22
- package/dist/chunk-6YHSYHDY.js.map +1 -0
- package/dist/{chunk-RNE6TKMF.js → chunk-A7BAW24L.js} +212 -162
- package/dist/chunk-A7BAW24L.js.map +1 -0
- package/dist/handlers/index.d.ts +5 -4
- package/dist/handlers/index.js +2 -2
- package/dist/index.d.ts +19 -11
- package/dist/index.js +3 -9
- package/dist/proxy-BI8OMQl0.d.ts +68 -0
- package/dist/server.js +277 -66
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
- package/dist/cache-BUVFfGZF.d.ts +0 -25
- package/dist/chunk-LK5K4SQV.js.map +0 -1
- package/dist/chunk-RNE6TKMF.js.map +0 -1
|
@@ -1,3 +1,162 @@
|
|
|
1
|
+
// src/ffmpeg.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { pipeline } from "stream";
|
|
4
|
+
import fs from "fs/promises";
|
|
5
|
+
import os from "os";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import pathToFFmpeg from "ffmpeg-static";
|
|
8
|
+
import tar from "tar-stream";
|
|
9
|
+
import { createWriteStream } from "fs";
|
|
10
|
+
import { promisify } from "util";
|
|
11
|
+
var pump = promisify(pipeline);
|
|
12
|
+
var FFmpegCommand = class {
|
|
13
|
+
globalArgs;
|
|
14
|
+
inputs;
|
|
15
|
+
filterComplex;
|
|
16
|
+
outputArgs;
|
|
17
|
+
constructor(globalArgs, inputs, filterComplex, outputArgs) {
|
|
18
|
+
this.globalArgs = globalArgs;
|
|
19
|
+
this.inputs = inputs;
|
|
20
|
+
this.filterComplex = filterComplex;
|
|
21
|
+
this.outputArgs = outputArgs;
|
|
22
|
+
}
|
|
23
|
+
buildArgs(inputResolver) {
|
|
24
|
+
const inputArgs = [];
|
|
25
|
+
for (const input of this.inputs) {
|
|
26
|
+
if (input.type === "color") {
|
|
27
|
+
inputArgs.push(...input.preArgs);
|
|
28
|
+
} else if (input.type === "animation") {
|
|
29
|
+
inputArgs.push(
|
|
30
|
+
...input.preArgs,
|
|
31
|
+
"-i",
|
|
32
|
+
path.join(inputResolver(input), "frame_%05d")
|
|
33
|
+
);
|
|
34
|
+
} else {
|
|
35
|
+
inputArgs.push(...input.preArgs, "-i", inputResolver(input));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const args = [
|
|
39
|
+
...this.globalArgs,
|
|
40
|
+
...inputArgs,
|
|
41
|
+
"-filter_complex",
|
|
42
|
+
this.filterComplex,
|
|
43
|
+
...this.outputArgs
|
|
44
|
+
];
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var FFmpegRunner = class {
|
|
49
|
+
command;
|
|
50
|
+
ffmpegProc;
|
|
51
|
+
constructor(command) {
|
|
52
|
+
this.command = command;
|
|
53
|
+
}
|
|
54
|
+
async run(sourceFetcher, imageTransformer, referenceResolver, urlTransformer) {
|
|
55
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ffs-"));
|
|
56
|
+
const fileMapping = /* @__PURE__ */ new Map();
|
|
57
|
+
const fetchCache = /* @__PURE__ */ new Map();
|
|
58
|
+
const fetchAndSaveSource = async (input, sourceUrl, inputName) => {
|
|
59
|
+
const stream = await sourceFetcher({
|
|
60
|
+
type: input.type,
|
|
61
|
+
src: sourceUrl
|
|
62
|
+
});
|
|
63
|
+
if (input.type === "animation") {
|
|
64
|
+
const extractionDir = path.join(tempDir, inputName);
|
|
65
|
+
await fs.mkdir(extractionDir, { recursive: true });
|
|
66
|
+
const extract = tar.extract();
|
|
67
|
+
const extractPromise = new Promise((resolve, reject) => {
|
|
68
|
+
extract.on("entry", async (header, stream2, next) => {
|
|
69
|
+
if (header.name.startsWith("frame_")) {
|
|
70
|
+
const transformedStream = imageTransformer ? await imageTransformer(stream2) : stream2;
|
|
71
|
+
const outputPath = path.join(extractionDir, header.name);
|
|
72
|
+
const writeStream = createWriteStream(outputPath);
|
|
73
|
+
transformedStream.pipe(writeStream);
|
|
74
|
+
writeStream.on("finish", next);
|
|
75
|
+
writeStream.on("error", reject);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
extract.on("finish", resolve);
|
|
79
|
+
extract.on("error", reject);
|
|
80
|
+
});
|
|
81
|
+
stream.pipe(extract);
|
|
82
|
+
await extractPromise;
|
|
83
|
+
return extractionDir;
|
|
84
|
+
} else if (input.type === "image" && imageTransformer) {
|
|
85
|
+
const tempFile = path.join(tempDir, inputName);
|
|
86
|
+
const transformedStream = await imageTransformer(stream);
|
|
87
|
+
const writeStream = createWriteStream(tempFile);
|
|
88
|
+
transformedStream.on("error", (e) => writeStream.destroy(e));
|
|
89
|
+
await pump(transformedStream, writeStream);
|
|
90
|
+
return tempFile;
|
|
91
|
+
} else {
|
|
92
|
+
const tempFile = path.join(tempDir, inputName);
|
|
93
|
+
const writeStream = createWriteStream(tempFile);
|
|
94
|
+
stream.on("error", (e) => writeStream.destroy(e));
|
|
95
|
+
await pump(stream, writeStream);
|
|
96
|
+
return tempFile;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
await Promise.all(
|
|
100
|
+
this.command.inputs.map(async (input) => {
|
|
101
|
+
if (input.type === "color") return;
|
|
102
|
+
const inputName = `ffmpeg_input_${input.index.toString().padStart(3, "0")}`;
|
|
103
|
+
const sourceUrl = referenceResolver ? referenceResolver(input.source) : input.source;
|
|
104
|
+
if ((input.type === "video" || input.type === "audio") && (sourceUrl.startsWith("http://") || sourceUrl.startsWith("https://"))) {
|
|
105
|
+
const finalUrl = urlTransformer ? urlTransformer(sourceUrl) : sourceUrl;
|
|
106
|
+
fileMapping.set(input.index, finalUrl);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const shouldCache = input.source.startsWith("#");
|
|
110
|
+
if (shouldCache) {
|
|
111
|
+
let fetchPromise = fetchCache.get(input.source);
|
|
112
|
+
if (!fetchPromise) {
|
|
113
|
+
fetchPromise = fetchAndSaveSource(input, sourceUrl, inputName);
|
|
114
|
+
fetchCache.set(input.source, fetchPromise);
|
|
115
|
+
}
|
|
116
|
+
const filePath = await fetchPromise;
|
|
117
|
+
fileMapping.set(input.index, filePath);
|
|
118
|
+
} else {
|
|
119
|
+
const filePath = await fetchAndSaveSource(
|
|
120
|
+
input,
|
|
121
|
+
sourceUrl,
|
|
122
|
+
inputName
|
|
123
|
+
);
|
|
124
|
+
fileMapping.set(input.index, filePath);
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
const finalArgs = this.command.buildArgs((input) => {
|
|
129
|
+
const filePath = fileMapping.get(input.index);
|
|
130
|
+
if (!filePath)
|
|
131
|
+
throw new Error(`File for input index ${input.index} not found`);
|
|
132
|
+
return filePath;
|
|
133
|
+
});
|
|
134
|
+
const ffmpegProc = spawn(process.env.FFMPEG ?? pathToFFmpeg, finalArgs);
|
|
135
|
+
ffmpegProc.stderr.on("data", (data) => {
|
|
136
|
+
console.error(data.toString());
|
|
137
|
+
});
|
|
138
|
+
ffmpegProc.on("close", async () => {
|
|
139
|
+
try {
|
|
140
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.error("Error removing temp directory:", err);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
this.ffmpegProc = ffmpegProc;
|
|
146
|
+
return ffmpegProc.stdout;
|
|
147
|
+
}
|
|
148
|
+
close() {
|
|
149
|
+
if (this.ffmpegProc) {
|
|
150
|
+
this.ffmpegProc.kill("SIGTERM");
|
|
151
|
+
this.ffmpegProc = void 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/render.ts
|
|
157
|
+
import { Readable } from "stream";
|
|
158
|
+
import { createReadStream as createReadStream2 } from "fs";
|
|
159
|
+
|
|
1
160
|
// src/motion.ts
|
|
2
161
|
function getEasingExpression(tNormExpr, easingType) {
|
|
3
162
|
switch (easingType) {
|
|
@@ -189,151 +348,6 @@ function processEffects(effects, frameRate, frameWidth, frameHeight) {
|
|
|
189
348
|
return filters.join(",");
|
|
190
349
|
}
|
|
191
350
|
|
|
192
|
-
// src/ffmpeg.ts
|
|
193
|
-
import { spawn } from "child_process";
|
|
194
|
-
import { pipeline } from "stream";
|
|
195
|
-
import fs from "fs/promises";
|
|
196
|
-
import os from "os";
|
|
197
|
-
import path from "path";
|
|
198
|
-
import pathToFFmpeg from "ffmpeg-static";
|
|
199
|
-
import tar from "tar-stream";
|
|
200
|
-
import { createWriteStream } from "fs";
|
|
201
|
-
import { promisify } from "util";
|
|
202
|
-
var pump = promisify(pipeline);
|
|
203
|
-
var FFmpegCommand = class {
|
|
204
|
-
globalArgs;
|
|
205
|
-
inputs;
|
|
206
|
-
filterComplex;
|
|
207
|
-
outputArgs;
|
|
208
|
-
constructor(globalArgs, inputs, filterComplex, outputArgs) {
|
|
209
|
-
this.globalArgs = globalArgs;
|
|
210
|
-
this.inputs = inputs;
|
|
211
|
-
this.filterComplex = filterComplex;
|
|
212
|
-
this.outputArgs = outputArgs;
|
|
213
|
-
}
|
|
214
|
-
buildArgs(inputResolver) {
|
|
215
|
-
const inputArgs = [];
|
|
216
|
-
for (const input of this.inputs) {
|
|
217
|
-
if (input.type === "color") {
|
|
218
|
-
inputArgs.push(...input.preArgs);
|
|
219
|
-
} else if (input.type === "animation") {
|
|
220
|
-
inputArgs.push(
|
|
221
|
-
...input.preArgs,
|
|
222
|
-
"-i",
|
|
223
|
-
path.join(inputResolver(input), "frame_%05d")
|
|
224
|
-
);
|
|
225
|
-
} else {
|
|
226
|
-
inputArgs.push(...input.preArgs, "-i", inputResolver(input));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const args = [
|
|
230
|
-
...this.globalArgs,
|
|
231
|
-
...inputArgs,
|
|
232
|
-
"-filter_complex",
|
|
233
|
-
this.filterComplex,
|
|
234
|
-
...this.outputArgs
|
|
235
|
-
];
|
|
236
|
-
return args;
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
var FFmpegRunner = class {
|
|
240
|
-
command;
|
|
241
|
-
ffmpegProc;
|
|
242
|
-
constructor(command) {
|
|
243
|
-
this.command = command;
|
|
244
|
-
}
|
|
245
|
-
async run(sourceResolver, imageTransformer) {
|
|
246
|
-
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ffs-"));
|
|
247
|
-
const fileMapping = /* @__PURE__ */ new Map();
|
|
248
|
-
const sourceCache = /* @__PURE__ */ new Map();
|
|
249
|
-
const fetchAndSaveSource = async (input, inputName) => {
|
|
250
|
-
const stream = await sourceResolver({
|
|
251
|
-
type: input.type,
|
|
252
|
-
src: input.source
|
|
253
|
-
});
|
|
254
|
-
if (input.type === "animation") {
|
|
255
|
-
const extractionDir = path.join(tempDir, inputName);
|
|
256
|
-
await fs.mkdir(extractionDir, { recursive: true });
|
|
257
|
-
const extract = tar.extract();
|
|
258
|
-
const extractPromise = new Promise((resolve, reject) => {
|
|
259
|
-
extract.on("entry", async (header, stream2, next) => {
|
|
260
|
-
if (header.name.startsWith("frame_")) {
|
|
261
|
-
const transformedStream = imageTransformer ? await imageTransformer(stream2) : stream2;
|
|
262
|
-
const outputPath = path.join(extractionDir, header.name);
|
|
263
|
-
const writeStream = createWriteStream(outputPath);
|
|
264
|
-
transformedStream.pipe(writeStream);
|
|
265
|
-
writeStream.on("finish", next);
|
|
266
|
-
writeStream.on("error", reject);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
extract.on("finish", resolve);
|
|
270
|
-
extract.on("error", reject);
|
|
271
|
-
});
|
|
272
|
-
stream.pipe(extract);
|
|
273
|
-
await extractPromise;
|
|
274
|
-
return extractionDir;
|
|
275
|
-
} else if (input.type === "image" && imageTransformer) {
|
|
276
|
-
const tempFile = path.join(tempDir, inputName);
|
|
277
|
-
const transformedStream = await imageTransformer(stream);
|
|
278
|
-
const writeStream = createWriteStream(tempFile);
|
|
279
|
-
transformedStream.on("error", (e) => writeStream.destroy(e));
|
|
280
|
-
await pump(transformedStream, writeStream);
|
|
281
|
-
return tempFile;
|
|
282
|
-
} else {
|
|
283
|
-
const tempFile = path.join(tempDir, inputName);
|
|
284
|
-
const writeStream = createWriteStream(tempFile);
|
|
285
|
-
stream.on("error", (e) => writeStream.destroy(e));
|
|
286
|
-
await pump(stream, writeStream);
|
|
287
|
-
return tempFile;
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
await Promise.all(
|
|
291
|
-
this.command.inputs.map(async (input) => {
|
|
292
|
-
if (input.type === "color") return;
|
|
293
|
-
const inputName = `ffmpeg_input_${input.index.toString().padStart(3, "0")}`;
|
|
294
|
-
const shouldCache = input.source.startsWith("#");
|
|
295
|
-
if (shouldCache) {
|
|
296
|
-
let fetchPromise = sourceCache.get(input.source);
|
|
297
|
-
if (!fetchPromise) {
|
|
298
|
-
fetchPromise = fetchAndSaveSource(input, inputName);
|
|
299
|
-
sourceCache.set(input.source, fetchPromise);
|
|
300
|
-
}
|
|
301
|
-
const filePath = await fetchPromise;
|
|
302
|
-
fileMapping.set(input.index, filePath);
|
|
303
|
-
} else {
|
|
304
|
-
const filePath = await fetchAndSaveSource(input, inputName);
|
|
305
|
-
fileMapping.set(input.index, filePath);
|
|
306
|
-
}
|
|
307
|
-
})
|
|
308
|
-
);
|
|
309
|
-
const finalArgs = this.command.buildArgs((input) => {
|
|
310
|
-
const filePath = fileMapping.get(input.index);
|
|
311
|
-
if (!filePath)
|
|
312
|
-
throw new Error(`File for input index ${input.index} not found`);
|
|
313
|
-
return filePath;
|
|
314
|
-
});
|
|
315
|
-
const ffmpegProc = spawn(process.env.FFMPEG ?? pathToFFmpeg, finalArgs);
|
|
316
|
-
ffmpegProc.stderr.on("data", (data) => {
|
|
317
|
-
console.error(data.toString());
|
|
318
|
-
});
|
|
319
|
-
ffmpegProc.on("close", async () => {
|
|
320
|
-
try {
|
|
321
|
-
await fs.rm(tempDir, { recursive: true, force: true });
|
|
322
|
-
} catch (err) {
|
|
323
|
-
console.error("Error removing temp directory:", err);
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
this.ffmpegProc = ffmpegProc;
|
|
327
|
-
return ffmpegProc.stdout;
|
|
328
|
-
}
|
|
329
|
-
close() {
|
|
330
|
-
if (this.ffmpegProc) {
|
|
331
|
-
this.ffmpegProc.kill("SIGTERM");
|
|
332
|
-
this.ffmpegProc = void 0;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
|
|
337
351
|
// src/transition.ts
|
|
338
352
|
function processTransition(transition) {
|
|
339
353
|
switch (transition.type) {
|
|
@@ -390,8 +404,6 @@ function processTransition(transition) {
|
|
|
390
404
|
}
|
|
391
405
|
|
|
392
406
|
// src/render.ts
|
|
393
|
-
import { Readable } from "stream";
|
|
394
|
-
import { createReadStream as createReadStream2 } from "fs";
|
|
395
407
|
import sharp from "sharp";
|
|
396
408
|
|
|
397
409
|
// src/fetch.ts
|
|
@@ -719,19 +731,14 @@ var EffieRenderer = class {
|
|
|
719
731
|
ffmpegRunner;
|
|
720
732
|
allowLocalFiles;
|
|
721
733
|
cacheStorage;
|
|
734
|
+
httpProxy;
|
|
722
735
|
constructor(effieData, options) {
|
|
723
736
|
this.effieData = effieData;
|
|
724
737
|
this.allowLocalFiles = options?.allowLocalFiles ?? false;
|
|
725
738
|
this.cacheStorage = options?.cacheStorage;
|
|
739
|
+
this.httpProxy = options?.httpProxy;
|
|
726
740
|
}
|
|
727
741
|
async fetchSource(src) {
|
|
728
|
-
if (src.startsWith("#")) {
|
|
729
|
-
const sourceName = src.slice(1);
|
|
730
|
-
if (!(sourceName in this.effieData.sources)) {
|
|
731
|
-
throw new Error(`Named source "${sourceName}" not found`);
|
|
732
|
-
}
|
|
733
|
-
src = this.effieData.sources[sourceName];
|
|
734
|
-
}
|
|
735
742
|
if (src.startsWith("data:")) {
|
|
736
743
|
const commaIndex = src.indexOf(",");
|
|
737
744
|
if (commaIndex === -1) {
|
|
@@ -1025,6 +1032,12 @@ var EffieRenderer = class {
|
|
|
1025
1032
|
segmentBgInputIndices.push(null);
|
|
1026
1033
|
}
|
|
1027
1034
|
}
|
|
1035
|
+
const globalBgSegmentIndices = [];
|
|
1036
|
+
for (let i = 0; i < this.effieData.segments.length; i++) {
|
|
1037
|
+
if (segmentBgInputIndices[i] === null) {
|
|
1038
|
+
globalBgSegmentIndices.push(i);
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1028
1041
|
for (const segment of this.effieData.segments) {
|
|
1029
1042
|
for (const layer of segment.layers) {
|
|
1030
1043
|
inputs.push(this.buildLayerInput(layer, segment.duration, inputIndex));
|
|
@@ -1061,6 +1074,26 @@ var EffieRenderer = class {
|
|
|
1061
1074
|
const filterParts = [];
|
|
1062
1075
|
const videoSegmentLabels = [];
|
|
1063
1076
|
const audioSegmentLabels = [];
|
|
1077
|
+
const globalBgFifoLabels = /* @__PURE__ */ new Map();
|
|
1078
|
+
const bgFilter = `fps=${this.effieData.fps},scale=${frameWidth}x${frameHeight}:force_original_aspect_ratio=increase,crop=${frameWidth}:${frameHeight}`;
|
|
1079
|
+
if (globalBgSegmentIndices.length === 1) {
|
|
1080
|
+
const fifoLabel = `bg_fifo_0`;
|
|
1081
|
+
filterParts.push(`[${globalBgInputIdx}:v]${bgFilter},fifo[${fifoLabel}]`);
|
|
1082
|
+
globalBgFifoLabels.set(globalBgSegmentIndices[0], fifoLabel);
|
|
1083
|
+
} else if (globalBgSegmentIndices.length > 1) {
|
|
1084
|
+
const splitCount = globalBgSegmentIndices.length;
|
|
1085
|
+
const splitOutputLabels = globalBgSegmentIndices.map(
|
|
1086
|
+
(_, i) => `bg_split_${i}`
|
|
1087
|
+
);
|
|
1088
|
+
filterParts.push(
|
|
1089
|
+
`[${globalBgInputIdx}:v]${bgFilter},split=${splitCount}${splitOutputLabels.map((l) => `[${l}]`).join("")}`
|
|
1090
|
+
);
|
|
1091
|
+
for (let i = 0; i < splitCount; i++) {
|
|
1092
|
+
const fifoLabel = `bg_fifo_${i}`;
|
|
1093
|
+
filterParts.push(`[${splitOutputLabels[i]}]fifo[${fifoLabel}]`);
|
|
1094
|
+
globalBgFifoLabels.set(globalBgSegmentIndices[i], fifoLabel);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1064
1097
|
for (let segIdx = 0; segIdx < this.effieData.segments.length; segIdx++) {
|
|
1065
1098
|
const segment = this.effieData.segments[segIdx];
|
|
1066
1099
|
const bgLabel = `bg_seg${segIdx}`;
|
|
@@ -1071,9 +1104,12 @@ var EffieRenderer = class {
|
|
|
1071
1104
|
`[${segBgInputIdx}:v]fps=${this.effieData.fps},scale=${frameWidth}x${frameHeight},trim=start=${segBgSeek}:duration=${segment.duration},setpts=PTS-STARTPTS[${bgLabel}]`
|
|
1072
1105
|
);
|
|
1073
1106
|
} else {
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1107
|
+
const fifoLabel = globalBgFifoLabels.get(segIdx);
|
|
1108
|
+
if (fifoLabel) {
|
|
1109
|
+
filterParts.push(
|
|
1110
|
+
`[${fifoLabel}]trim=start=${backgroundSeek + currentTime}:duration=${segment.duration},setpts=PTS-STARTPTS[${bgLabel}]`
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1077
1113
|
}
|
|
1078
1114
|
const vidLabel = `vid_seg${segIdx}`;
|
|
1079
1115
|
filterParts.push(
|
|
@@ -1157,6 +1193,20 @@ var EffieRenderer = class {
|
|
|
1157
1193
|
}
|
|
1158
1194
|
};
|
|
1159
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Resolves a source reference to its actual URL.
|
|
1198
|
+
* If the source is a #reference, returns the resolved URL.
|
|
1199
|
+
* Otherwise, returns the source as-is.
|
|
1200
|
+
*/
|
|
1201
|
+
resolveReference(src) {
|
|
1202
|
+
if (src.startsWith("#")) {
|
|
1203
|
+
const sourceName = src.slice(1);
|
|
1204
|
+
if (sourceName in this.effieData.sources) {
|
|
1205
|
+
return this.effieData.sources[sourceName];
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return src;
|
|
1209
|
+
}
|
|
1160
1210
|
/**
|
|
1161
1211
|
* Renders the effie data to a video stream.
|
|
1162
1212
|
* @param scaleFactor - Scale factor for output dimensions
|
|
@@ -1164,9 +1214,12 @@ var EffieRenderer = class {
|
|
|
1164
1214
|
async render(scaleFactor = 1) {
|
|
1165
1215
|
const ffmpegCommand = this.buildFFmpegCommand("-", scaleFactor);
|
|
1166
1216
|
this.ffmpegRunner = new FFmpegRunner(ffmpegCommand);
|
|
1217
|
+
const urlTransformer = this.httpProxy ? (url) => this.httpProxy.transformUrl(url) : void 0;
|
|
1167
1218
|
return this.ffmpegRunner.run(
|
|
1168
1219
|
async ({ src }) => this.fetchSource(src),
|
|
1169
|
-
this.createImageTransformer(scaleFactor)
|
|
1220
|
+
this.createImageTransformer(scaleFactor),
|
|
1221
|
+
(src) => this.resolveReference(src),
|
|
1222
|
+
urlTransformer
|
|
1170
1223
|
);
|
|
1171
1224
|
}
|
|
1172
1225
|
close() {
|
|
@@ -1177,14 +1230,11 @@ var EffieRenderer = class {
|
|
|
1177
1230
|
};
|
|
1178
1231
|
|
|
1179
1232
|
export {
|
|
1180
|
-
processMotion,
|
|
1181
|
-
processEffects,
|
|
1182
1233
|
FFmpegCommand,
|
|
1183
1234
|
FFmpegRunner,
|
|
1184
|
-
processTransition,
|
|
1185
1235
|
ffsFetch,
|
|
1186
1236
|
createCacheStorage,
|
|
1187
1237
|
cacheKeys,
|
|
1188
1238
|
EffieRenderer
|
|
1189
1239
|
};
|
|
1190
|
-
//# sourceMappingURL=chunk-
|
|
1240
|
+
//# sourceMappingURL=chunk-A7BAW24L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ffmpeg.ts","../src/render.ts","../src/motion.ts","../src/effect.ts","../src/transition.ts","../src/fetch.ts","../src/cache.ts"],"sourcesContent":["import type { ChildProcess } from \"child_process\";\nimport { spawn } from \"child_process\";\nimport type { Readable } from \"stream\";\nimport { pipeline } from \"stream\";\nimport fs from \"fs/promises\";\nimport os from \"os\";\nimport path from \"path\";\nimport pathToFFmpeg from \"ffmpeg-static\";\nimport tar from \"tar-stream\";\nimport { createWriteStream } from \"fs\";\nimport { promisify } from \"util\";\n\nconst pump = promisify(pipeline);\n\n/**\n * Each input is represented by its index, its source, and the pre–arguments\n * that must appear immediately before its \"-i\" option.\n */\nexport type FFmpegInput = {\n index: number;\n source: string;\n preArgs: string[];\n type: \"image\" | \"video\" | \"audio\" | \"color\" | \"animation\";\n};\n\nexport class FFmpegCommand {\n globalArgs: string[];\n inputs: FFmpegInput[];\n filterComplex: string;\n outputArgs: string[];\n\n constructor(\n globalArgs: string[],\n inputs: FFmpegInput[],\n filterComplex: string,\n outputArgs: string[],\n ) {\n this.globalArgs = globalArgs;\n this.inputs = inputs;\n this.filterComplex = filterComplex;\n this.outputArgs = outputArgs;\n }\n\n buildArgs(inputResolver: (input: FFmpegInput) => string): string[] {\n const inputArgs: string[] = [];\n for (const input of this.inputs) {\n if (input.type === \"color\") {\n inputArgs.push(...input.preArgs);\n } else if (input.type === \"animation\") {\n inputArgs.push(\n ...input.preArgs,\n \"-i\",\n path.join(inputResolver(input), \"frame_%05d\"),\n );\n } else {\n inputArgs.push(...input.preArgs, \"-i\", inputResolver(input));\n }\n }\n const args = [\n ...this.globalArgs,\n ...inputArgs,\n \"-filter_complex\",\n this.filterComplex,\n ...this.outputArgs,\n ];\n return args;\n }\n}\n\nexport class FFmpegRunner {\n private command: FFmpegCommand;\n\n private ffmpegProc?: ChildProcess;\n\n constructor(command: FFmpegCommand) {\n this.command = command;\n }\n\n async run(\n sourceFetcher: (input: {\n type: FFmpegInput[\"type\"];\n src: string;\n }) => Promise<Readable>,\n imageTransformer?: (imageStream: Readable) => Promise<Readable>,\n referenceResolver?: (src: string) => string,\n urlTransformer?: (url: string) => string,\n ): Promise<Readable> {\n const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), \"ffs-\"));\n const fileMapping = new Map<number, string>();\n // Cache for #reference sources to avoid duplicate fetches.\n // Uses promises to handle concurrent requests for the same source.\n // Key is input.source (the original #ref) to preserve deduplication.\n const fetchCache = new Map<string, Promise<string>>();\n\n const fetchAndSaveSource = async (\n input: FFmpegInput,\n sourceUrl: string,\n inputName: string,\n ): Promise<string> => {\n const stream = await sourceFetcher({\n type: input.type,\n src: sourceUrl,\n });\n\n if (input.type === \"animation\") {\n // we expect annie files for animations,\n // which are a TAR that needs to be extracted\n const extractionDir = path.join(tempDir, inputName);\n await fs.mkdir(extractionDir, { recursive: true });\n const extract = tar.extract();\n const extractPromise = new Promise<void>((resolve, reject) => {\n extract.on(\"entry\", async (header, stream, next) => {\n if (header.name.startsWith(\"frame_\")) {\n const transformedStream = imageTransformer\n ? await imageTransformer(stream)\n : stream;\n const outputPath = path.join(extractionDir, header.name);\n const writeStream = createWriteStream(outputPath);\n transformedStream.pipe(writeStream);\n writeStream.on(\"finish\", next);\n writeStream.on(\"error\", reject);\n }\n });\n extract.on(\"finish\", resolve);\n extract.on(\"error\", reject);\n });\n stream.pipe(extract);\n await extractPromise;\n return extractionDir;\n } else if (input.type === \"image\" && imageTransformer) {\n const tempFile = path.join(tempDir, inputName);\n const transformedStream = await imageTransformer(stream);\n const writeStream = createWriteStream(tempFile);\n transformedStream.on(\"error\", (e) => writeStream.destroy(e));\n await pump(transformedStream, writeStream);\n return tempFile;\n } else {\n const tempFile = path.join(tempDir, inputName);\n const writeStream = createWriteStream(tempFile);\n stream.on(\"error\", (e) => writeStream.destroy(e));\n await pump(stream, writeStream);\n return tempFile;\n }\n };\n\n await Promise.all(\n this.command.inputs.map(async (input) => {\n if (input.type === \"color\") return;\n\n const inputName = `ffmpeg_input_${input.index\n .toString()\n .padStart(3, \"0\")}`;\n\n // Resolve #references to get the actual URL\n const sourceUrl = referenceResolver\n ? referenceResolver(input.source)\n : input.source;\n\n // Pass HTTP(S) video/audio URLs directly to FFmpeg without downloading\n // If urlTransformer is provided, transform the URL (e.g., for proxy)\n if (\n (input.type === \"video\" || input.type === \"audio\") &&\n (sourceUrl.startsWith(\"http://\") || sourceUrl.startsWith(\"https://\"))\n ) {\n const finalUrl = urlTransformer\n ? urlTransformer(sourceUrl)\n : sourceUrl;\n fileMapping.set(input.index, finalUrl);\n return;\n }\n\n // Deduplicate fetches when the same #ref appears multiple times.\n // Only for #refs since they're short strings; data URLs would bloat the map.\n const shouldCache = input.source.startsWith(\"#\");\n if (shouldCache) {\n let fetchPromise = fetchCache.get(input.source);\n if (!fetchPromise) {\n fetchPromise = fetchAndSaveSource(input, sourceUrl, inputName);\n fetchCache.set(input.source, fetchPromise);\n }\n const filePath = await fetchPromise;\n fileMapping.set(input.index, filePath);\n } else {\n const filePath = await fetchAndSaveSource(\n input,\n sourceUrl,\n inputName,\n );\n fileMapping.set(input.index, filePath);\n }\n }),\n );\n\n const finalArgs = this.command.buildArgs((input) => {\n const filePath = fileMapping.get(input.index);\n if (!filePath)\n throw new Error(`File for input index ${input.index} not found`);\n return filePath;\n });\n const ffmpegProc = spawn(process.env.FFMPEG ?? pathToFFmpeg!, finalArgs);\n ffmpegProc.stderr!.on(\"data\", (data) => {\n console.error(data.toString());\n });\n\n ffmpegProc.on(\"close\", async () => {\n try {\n await fs.rm(tempDir, { recursive: true, force: true });\n } catch (err) {\n console.error(\"Error removing temp directory:\", err);\n }\n });\n\n this.ffmpegProc = ffmpegProc;\n return ffmpegProc.stdout as Readable;\n }\n\n close(): void {\n if (this.ffmpegProc) {\n this.ffmpegProc.kill(\"SIGTERM\");\n this.ffmpegProc = undefined;\n }\n }\n}\n","import { Readable } from \"stream\";\nimport { createReadStream } from \"fs\";\nimport { processMotion } from \"./motion\";\nimport { processEffects } from \"./effect\";\nimport type { FFmpegInput } from \"./ffmpeg\";\nimport { FFmpegCommand, FFmpegRunner } from \"./ffmpeg\";\nimport { processTransition } from \"./transition\";\nimport type { EffieData, EffieSources, EffieWebUrl } from \"@effing/effie\";\nimport sharp from \"sharp\";\nimport { ffsFetch } from \"./fetch\";\nimport { fileURLToPath } from \"url\";\nimport { cacheKeys } from \"./cache\";\nimport type { CacheStorage } from \"./cache\";\nimport type { HttpProxy } from \"./proxy\";\n\nexport type EffieRendererOptions = {\n /**\n * Allow reading from local file paths.\n * WARNING: Only enable this for trusted internal operations.\n * Enabling this for user-provided data is a security risk.\n * @default false\n */\n allowLocalFiles?: boolean;\n /**\n * Cache storage instance for source lookups.\n * If not provided, a shared lazy-initialized cache will be used.\n */\n cacheStorage?: CacheStorage;\n /**\n * HTTP proxy for video/audio URLs.\n * When provided, HTTP(S) URLs for video/audio inputs will be routed\n * through this proxy, allowing Node.js to handle DNS resolution\n * instead of FFmpeg (useful for Alpine Linux with musl libc).\n */\n httpProxy?: HttpProxy;\n};\n\nexport class EffieRenderer<U extends string = EffieWebUrl> {\n private effieData: EffieData<EffieSources<U>, U>;\n private ffmpegRunner?: FFmpegRunner;\n private allowLocalFiles: boolean;\n private cacheStorage?: CacheStorage;\n private httpProxy?: HttpProxy;\n\n constructor(\n effieData: EffieData<EffieSources<U>, U>,\n options?: EffieRendererOptions,\n ) {\n this.effieData = effieData;\n this.allowLocalFiles = options?.allowLocalFiles ?? false;\n this.cacheStorage = options?.cacheStorage;\n this.httpProxy = options?.httpProxy;\n }\n\n private async fetchSource(src: string): Promise<Readable> {\n // src is already a resolved URL - no #ref handling needed\n // (references are resolved in FFmpegRunner via referenceResolver)\n\n // Handle data URLs (inline, no actual fetch or cache needed)\n if (src.startsWith(\"data:\")) {\n const commaIndex = src.indexOf(\",\");\n if (commaIndex === -1) {\n throw new Error(\"Invalid data URL\");\n }\n const meta = src.slice(5, commaIndex); // after \"data:\"\n const isBase64 = meta.endsWith(\";base64\");\n const data = src.slice(commaIndex + 1);\n const buffer = isBase64\n ? Buffer.from(data, \"base64\")\n : Buffer.from(decodeURIComponent(data));\n return Readable.from(buffer);\n }\n\n // Handle local file paths, if allowed\n if (src.startsWith(\"file:\")) {\n if (!this.allowLocalFiles) {\n throw new Error(\n \"Local file paths are not allowed. Use allowLocalFiles option for trusted operations.\",\n );\n }\n return createReadStream(fileURLToPath(src));\n }\n\n // If we have a cache, check the cache first\n if (this.cacheStorage) {\n const cachedStream = await this.cacheStorage.getStream(\n cacheKeys.source(src),\n );\n if (cachedStream) {\n return cachedStream;\n }\n }\n\n // Fetch from network\n const response = await ffsFetch(src, {\n headersTimeout: 10 * 60 * 1000, // 10 minutes\n bodyTimeout: 20 * 60 * 1000, // 20 minutes\n });\n if (!response.ok) {\n throw new Error(\n `Failed to fetch ${src}: ${response.status} ${response.statusText}`,\n );\n }\n if (!response.body) {\n throw new Error(`No body for ${src}`);\n }\n // Convert WHATWG ReadableStream to Node.js Readable\n return Readable.fromWeb(response.body);\n }\n\n private buildAudioFilter({\n duration,\n volume,\n fadeIn,\n fadeOut,\n }: {\n duration: number;\n volume?: number;\n fadeIn?: number;\n fadeOut?: number;\n }) {\n const filters = [];\n if (volume !== undefined) {\n filters.push(`volume=${volume}`);\n }\n if (fadeIn !== undefined) {\n filters.push(`afade=type=in:start_time=0:duration=${fadeIn}`);\n }\n if (fadeOut !== undefined) {\n filters.push(\n `afade=type=out:start_time=${duration - fadeOut}:duration=${fadeOut}`,\n );\n }\n return filters.length ? filters.join(\",\") : \"anull\";\n }\n\n private getFrameDimensions(scaleFactor: number) {\n // Round down to the nearest even number for H.264 compatibility\n return {\n frameWidth: Math.floor((this.effieData.width * scaleFactor) / 2) * 2,\n frameHeight: Math.floor((this.effieData.height * scaleFactor) / 2) * 2,\n };\n }\n\n /**\n * Builds an FFmpeg input for a background (global or segment).\n */\n private buildBackgroundInput(\n background: EffieData<EffieSources<U>, U>[\"background\"],\n inputIndex: number,\n frameWidth: number,\n frameHeight: number,\n ): FFmpegInput {\n if (background.type === \"image\") {\n return {\n index: inputIndex,\n source: background.source,\n preArgs: [\"-loop\", \"1\", \"-framerate\", this.effieData.fps.toString()],\n type: \"image\",\n };\n } else if (background.type === \"video\") {\n return {\n index: inputIndex,\n source: background.source,\n preArgs: [\"-stream_loop\", \"-1\"],\n type: \"video\",\n };\n }\n // Color background - use lavfi to generate\n return {\n index: inputIndex,\n source: \"\",\n preArgs: [\n \"-f\",\n \"lavfi\",\n \"-i\",\n `color=${background.color}:size=${frameWidth}x${frameHeight}:rate=${this.effieData.fps}`,\n ],\n type: \"color\",\n };\n }\n\n private buildOutputArgs(outputFilename: string): string[] {\n return [\n \"-map\",\n \"[outv]\",\n \"-map\",\n \"[outa]\",\n \"-c:v\",\n \"libx264\",\n \"-r\",\n this.effieData.fps.toString(),\n \"-pix_fmt\",\n \"yuv420p\",\n \"-preset\",\n \"fast\",\n \"-crf\",\n \"28\",\n \"-c:a\",\n \"aac\",\n \"-movflags\",\n \"frag_keyframe+empty_moov\",\n \"-f\",\n \"mp4\",\n outputFilename,\n ];\n }\n\n private buildLayerInput(\n layer: EffieData<EffieSources<U>, U>[\"segments\"][0][\"layers\"][0],\n duration: number,\n inputIndex: number,\n ): FFmpegInput {\n let preArgs: string[] = [];\n if (layer.type === \"image\") {\n preArgs = [\n \"-loop\",\n \"1\",\n \"-t\",\n duration.toString(),\n \"-framerate\",\n this.effieData.fps.toString(),\n ];\n } else if (layer.type === \"animation\") {\n preArgs = [\"-f\", \"image2\", \"-framerate\", this.effieData.fps.toString()];\n }\n return {\n index: inputIndex,\n source: layer.source,\n preArgs,\n type: layer.type,\n };\n }\n\n /**\n * Builds filter chain for all layers in a segment.\n * @param segment - The segment containing layers\n * @param bgLabel - Label for the background input (e.g., \"bg_seg0\" or \"bg_seg\")\n * @param labelPrefix - Prefix for generated labels (e.g., \"seg0_\" or \"\")\n * @param layerInputOffset - Starting input index for layers\n * @param frameWidth - Frame width for nullsrc\n * @param frameHeight - Frame height for nullsrc\n * @param outputLabel - Label for the final video output\n * @returns Array of filter parts to add to the filter chain\n */\n private buildLayerFilters(\n segment: EffieData<EffieSources<U>, U>[\"segments\"][0],\n bgLabel: string,\n labelPrefix: string,\n layerInputOffset: number,\n frameWidth: number,\n frameHeight: number,\n outputLabel: string,\n ): string[] {\n const filterParts: string[] = [];\n let currentVidLabel = bgLabel;\n\n for (let l = 0; l < segment.layers.length; l++) {\n const inputIdx = layerInputOffset + l;\n const layerLabel = `${labelPrefix}layer${l}`;\n const layer = segment.layers[l];\n const effectChain = layer.effects\n ? processEffects(\n layer.effects,\n this.effieData.fps,\n frameWidth,\n frameHeight,\n )\n : \"\";\n filterParts.push(\n `[${inputIdx}:v]trim=start=0:duration=${segment.duration},${\n effectChain ? effectChain + \",\" : \"\"\n }setsar=1,setpts=PTS-STARTPTS[${layerLabel}]`,\n );\n let overlayInputLabel = layerLabel;\n const delay = layer.delay ?? 0;\n if (delay > 0) {\n filterParts.push(\n `nullsrc=size=${frameWidth}x${frameHeight}:duration=${delay},setpts=PTS-STARTPTS[null_${layerLabel}]`,\n );\n filterParts.push(\n `[null_${layerLabel}][${layerLabel}]concat=n=2:v=1:a=0[delayed_${layerLabel}]`,\n );\n overlayInputLabel = `delayed_${layerLabel}`;\n }\n const overlayOutputLabel = `${labelPrefix}tmp${l}`;\n const offset = layer.motion ? processMotion(delay, layer.motion) : \"0:0\";\n const fromTime = layer.from ?? 0;\n const untilTime = layer.until ?? segment.duration;\n filterParts.push(\n `[${currentVidLabel}][${overlayInputLabel}]overlay=${offset}:enable='between(t,${fromTime},${untilTime})',fps=${this.effieData.fps}[${overlayOutputLabel}]`,\n );\n currentVidLabel = overlayOutputLabel;\n }\n filterParts.push(`[${currentVidLabel}]null[${outputLabel}]`);\n\n return filterParts;\n }\n\n /**\n * Applies xfade/concat transitions between video segments.\n * Modifies videoSegmentLabels in place to update labels after transitions.\n * @param filterParts - Array to append filter parts to\n * @param videoSegmentLabels - Array of video segment labels (modified in place)\n */\n private applyTransitions(\n filterParts: string[],\n videoSegmentLabels: string[],\n ): void {\n let transitionOffset = 0;\n this.effieData.segments.forEach((segment, i) => {\n if (i === 0) {\n transitionOffset = segment.duration;\n return;\n }\n const combineLabel = `[vid_com${i}]`;\n if (!segment.transition) {\n transitionOffset += segment.duration;\n filterParts.push(\n `${videoSegmentLabels[i - 1]}${\n videoSegmentLabels[i]\n }concat=n=2:v=1:a=0,fps=${this.effieData.fps}${combineLabel}`,\n );\n videoSegmentLabels[i] = combineLabel;\n return;\n }\n const transitionName = processTransition(segment.transition);\n const transitionDuration = segment.transition.duration;\n transitionOffset -= transitionDuration;\n filterParts.push(\n `${videoSegmentLabels[i - 1]}${\n videoSegmentLabels[i]\n }xfade=transition=${transitionName}:duration=${transitionDuration}:offset=${transitionOffset}${combineLabel}`,\n );\n videoSegmentLabels[i] = combineLabel;\n transitionOffset += segment.duration;\n });\n filterParts.push(`${videoSegmentLabels.at(-1)}null[outv]`);\n }\n\n /**\n * Applies general audio mixing: concats segment audio and mixes with global audio if present.\n * @param filterParts - Array to append filter parts to\n * @param audioSegmentLabels - Array of audio segment labels to concat\n * @param totalDuration - Total duration for audio trimming\n * @param generalAudioInputIndex - Input index for general audio (if present)\n */\n private applyGeneralAudio(\n filterParts: string[],\n audioSegmentLabels: string[],\n totalDuration: number,\n generalAudioInputIndex: number,\n ): void {\n if (this.effieData.audio) {\n const audioSeek = this.effieData.audio.seek ?? 0;\n const generalAudioFilter = this.buildAudioFilter({\n duration: totalDuration,\n volume: this.effieData.audio.volume,\n fadeIn: this.effieData.audio.fadeIn,\n fadeOut: this.effieData.audio.fadeOut,\n });\n filterParts.push(\n `[${generalAudioInputIndex}:a]atrim=start=${audioSeek}:duration=${totalDuration},${generalAudioFilter},asetpts=PTS-STARTPTS[general_audio]`,\n );\n filterParts.push(\n `${audioSegmentLabels.join(\"\")}concat=n=${\n this.effieData.segments.length\n }:v=0:a=1,atrim=start=0:duration=${totalDuration}[segments_audio]`,\n );\n filterParts.push(\n `[general_audio][segments_audio]amix=inputs=2:duration=longest[outa]`,\n );\n } else {\n filterParts.push(\n `${audioSegmentLabels.join(\"\")}concat=n=${\n this.effieData.segments.length\n }:v=0:a=1[outa]`,\n );\n }\n }\n\n private buildFFmpegCommand(\n outputFilename: string,\n scaleFactor: number = 1,\n ): FFmpegCommand {\n const globalArgs: string[] = [\"-y\", \"-loglevel\", \"error\"];\n const inputs: FFmpegInput[] = [];\n let inputIndex = 0;\n\n const { frameWidth, frameHeight } = this.getFrameDimensions(scaleFactor);\n const backgroundSeek =\n this.effieData.background.type === \"video\"\n ? (this.effieData.background.seek ?? 0)\n : 0;\n\n // Global background input:\n inputs.push(\n this.buildBackgroundInput(\n this.effieData.background,\n inputIndex,\n frameWidth,\n frameHeight,\n ),\n );\n const globalBgInputIdx = inputIndex;\n inputIndex++;\n\n // Segment background inputs:\n const segmentBgInputIndices: (number | null)[] = [];\n for (const segment of this.effieData.segments) {\n if (segment.background) {\n inputs.push(\n this.buildBackgroundInput(\n segment.background,\n inputIndex,\n frameWidth,\n frameHeight,\n ),\n );\n segmentBgInputIndices.push(inputIndex);\n inputIndex++;\n } else {\n segmentBgInputIndices.push(null);\n }\n }\n\n // Identify segments using global background\n const globalBgSegmentIndices: number[] = [];\n for (let i = 0; i < this.effieData.segments.length; i++) {\n if (segmentBgInputIndices[i] === null) {\n globalBgSegmentIndices.push(i);\n }\n }\n\n // Layer inputs:\n for (const segment of this.effieData.segments) {\n for (const layer of segment.layers) {\n inputs.push(this.buildLayerInput(layer, segment.duration, inputIndex));\n inputIndex++;\n }\n }\n\n // Audio inputs:\n for (const segment of this.effieData.segments) {\n if (segment.audio) {\n inputs.push({\n index: inputIndex,\n source: segment.audio.source,\n preArgs: [],\n type: \"audio\",\n });\n inputIndex++;\n }\n }\n\n // General audio input:\n if (this.effieData.audio) {\n inputs.push({\n index: inputIndex,\n source: this.effieData.audio.source,\n preArgs: [],\n type: \"audio\",\n });\n inputIndex++;\n }\n\n // Compute how many video inputs we have:\n const numSegmentBgInputs = segmentBgInputIndices.filter(\n (i) => i !== null,\n ).length;\n const numVideoInputs =\n 1 +\n numSegmentBgInputs +\n this.effieData.segments.reduce((sum, seg) => sum + seg.layers.length, 0);\n let audioCounter = 0;\n\n // Build filter_complex:\n let currentTime = 0;\n let layerInputOffset = 1 + numSegmentBgInputs; // Global background is input 0\n const filterParts: string[] = [];\n const videoSegmentLabels: string[] = [];\n const audioSegmentLabels: string[] = [];\n\n // Build split/fifo chain for global background\n const globalBgFifoLabels: Map<number, string> = new Map();\n const bgFilter = `fps=${this.effieData.fps},scale=${frameWidth}x${frameHeight}:force_original_aspect_ratio=increase,crop=${frameWidth}:${frameHeight}`;\n if (globalBgSegmentIndices.length === 1) {\n // Single segment - no split needed, just fifo\n const fifoLabel = `bg_fifo_0`;\n filterParts.push(`[${globalBgInputIdx}:v]${bgFilter},fifo[${fifoLabel}]`);\n globalBgFifoLabels.set(globalBgSegmentIndices[0], fifoLabel);\n } else if (globalBgSegmentIndices.length > 1) {\n // Multiple segments - use split + fifo\n const splitCount = globalBgSegmentIndices.length;\n const splitOutputLabels = globalBgSegmentIndices.map(\n (_, i) => `bg_split_${i}`,\n );\n\n filterParts.push(\n `[${globalBgInputIdx}:v]${bgFilter},split=${splitCount}${splitOutputLabels.map((l) => `[${l}]`).join(\"\")}`,\n );\n\n for (let i = 0; i < splitCount; i++) {\n const fifoLabel = `bg_fifo_${i}`;\n filterParts.push(`[${splitOutputLabels[i]}]fifo[${fifoLabel}]`);\n globalBgFifoLabels.set(globalBgSegmentIndices[i], fifoLabel);\n }\n }\n\n for (let segIdx = 0; segIdx < this.effieData.segments.length; segIdx++) {\n const segment = this.effieData.segments[segIdx];\n\n // Determine background for this segment (segment bg overrides global bg)\n const bgLabel = `bg_seg${segIdx}`;\n if (segment.background) {\n // Use segment background\n const segBgInputIdx = segmentBgInputIndices[segIdx]!;\n const segBgSeek =\n segment.background.type === \"video\"\n ? (segment.background.seek ?? 0)\n : 0;\n filterParts.push(\n `[${segBgInputIdx}:v]fps=${this.effieData.fps},scale=${frameWidth}x${frameHeight},trim=start=${segBgSeek}:duration=${segment.duration},setpts=PTS-STARTPTS[${bgLabel}]`,\n );\n } else {\n // Use global background (via split/fifo chain)\n const fifoLabel = globalBgFifoLabels.get(segIdx);\n if (fifoLabel) {\n // fps/scale already applied in split/fifo chain\n filterParts.push(\n `[${fifoLabel}]trim=start=${backgroundSeek + currentTime}:duration=${segment.duration},setpts=PTS-STARTPTS[${bgLabel}]`,\n );\n }\n }\n\n // Process layers\n const vidLabel = `vid_seg${segIdx}`;\n filterParts.push(\n ...this.buildLayerFilters(\n segment,\n bgLabel,\n `seg${segIdx}_`,\n layerInputOffset,\n frameWidth,\n frameHeight,\n vidLabel,\n ),\n );\n layerInputOffset += segment.layers.length;\n videoSegmentLabels.push(`[${vidLabel}]`);\n\n const nextSegment = this.effieData.segments[segIdx + 1];\n const transitionDuration = nextSegment?.transition?.duration ?? 0;\n // Ensure audio duration is always at least 0.001 seconds to avoid FFmpeg misbehavior\n const realDuration = Math.max(\n 0.001,\n segment.duration - transitionDuration,\n );\n\n // Process audio: use the corresponding audio input index if audio exists\n if (segment.audio) {\n // Audio inputs start after all video inputs\n const audioInputIndex = numVideoInputs + audioCounter;\n const audioFilter = this.buildAudioFilter({\n duration: realDuration,\n volume: segment.audio.volume,\n fadeIn: segment.audio.fadeIn,\n fadeOut: segment.audio.fadeOut,\n });\n filterParts.push(\n `[${audioInputIndex}:a]atrim=start=0:duration=${realDuration},${audioFilter},asetpts=PTS-STARTPTS[aud_seg${segIdx}]`,\n );\n audioCounter++;\n } else {\n filterParts.push(\n `anullsrc=r=44100:cl=stereo,atrim=start=0:duration=${realDuration},asetpts=PTS-STARTPTS[aud_seg${segIdx}]`,\n );\n }\n audioSegmentLabels.push(`[aud_seg${segIdx}]`);\n\n currentTime += realDuration;\n }\n\n // Add general audio if present\n this.applyGeneralAudio(\n filterParts,\n audioSegmentLabels,\n currentTime,\n numVideoInputs + audioCounter,\n );\n\n // Apply transitions between video segments\n this.applyTransitions(filterParts, videoSegmentLabels);\n\n const filterComplex = filterParts.join(\";\");\n const outputArgs = this.buildOutputArgs(outputFilename);\n\n return new FFmpegCommand(globalArgs, inputs, filterComplex, outputArgs);\n }\n\n private createImageTransformer(scaleFactor: number) {\n return async (imageStream: Readable): Promise<Readable> => {\n if (scaleFactor === 1) return imageStream;\n\n const sharpTransformer = sharp();\n imageStream.on(\"error\", (err) => {\n if (!sharpTransformer.destroyed) {\n sharpTransformer.destroy(err);\n }\n });\n sharpTransformer.on(\"error\", (err) => {\n if (!imageStream.destroyed) {\n imageStream.destroy(err);\n }\n });\n imageStream.pipe(sharpTransformer);\n try {\n const metadata = await sharpTransformer.metadata();\n const imageWidth = metadata.width ?? this.effieData.width;\n const imageHeight = metadata.height ?? this.effieData.height;\n return sharpTransformer.resize({\n width: Math.floor(imageWidth * scaleFactor),\n height: Math.floor(imageHeight * scaleFactor),\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n if (!sharpTransformer.destroyed) {\n sharpTransformer.destroy(error);\n }\n throw error;\n }\n };\n }\n\n /**\n * Resolves a source reference to its actual URL.\n * If the source is a #reference, returns the resolved URL.\n * Otherwise, returns the source as-is.\n */\n private resolveReference(src: string): string {\n if (src.startsWith(\"#\")) {\n const sourceName = src.slice(1);\n if (sourceName in this.effieData.sources!) {\n return this.effieData.sources![sourceName];\n }\n }\n return src;\n }\n\n /**\n * Renders the effie data to a video stream.\n * @param scaleFactor - Scale factor for output dimensions\n */\n async render(scaleFactor = 1): Promise<Readable> {\n const ffmpegCommand = this.buildFFmpegCommand(\"-\", scaleFactor);\n this.ffmpegRunner = new FFmpegRunner(ffmpegCommand);\n\n // Create URL transformer for proxy if available\n const urlTransformer = this.httpProxy\n ? (url: string) => this.httpProxy!.transformUrl(url)\n : undefined;\n\n return this.ffmpegRunner.run(\n async ({ src }) => this.fetchSource(src),\n this.createImageTransformer(scaleFactor),\n (src) => this.resolveReference(src),\n urlTransformer,\n );\n }\n\n close(): void {\n if (this.ffmpegRunner) {\n this.ffmpegRunner.close();\n }\n }\n}\n","import type { EffieMotion } from \"@effing/effie\";\n\n/**\n * Defines the building blocks for an FFmpeg motion expression.\n */\ntype MotionComponents = {\n initialX: string; // Expression for X before animation starts\n initialY: string; // Expression for Y before animation starts\n activeX: string; // Expression for X during animation (incorporates relative time)\n activeY: string; // Expression for Y during animation (incorporates relative time)\n finalX: string; // Expression for X after animation ends\n finalY: string; // Expression for Y after animation ends\n duration: number; // Duration of the animation effect itself\n};\n\nfunction getEasingExpression(\n tNormExpr: string,\n easingType: \"linear\" | \"ease-in\" | \"ease-out\" | \"ease-in-out\",\n): string {\n switch (easingType) {\n case \"ease-in\":\n // t^2\n return `pow(${tNormExpr},2)`;\n case \"ease-out\":\n // 1 - (1-t)^2\n return `(1-pow(1-(${tNormExpr}),2))`;\n case \"ease-in-out\":\n // t < 0.5 ? 2*t^2 : 1 - (-2*t + 2)^2 / 2\n return `if(lt(${tNormExpr},0.5),2*pow(${tNormExpr},2),1-pow(-2*(${tNormExpr})+2,2)/2)`;\n case \"linear\":\n default:\n // Default to linear if type is unknown or \"linear\"\n return `(${tNormExpr})`; // Ensure parentheses for safety if tNormExpr is complex\n }\n}\n\nfunction processSlideMotion(\n motion: Extract<EffieMotion, { type: \"slide\" }>,\n relativeTimeExpr: string,\n): MotionComponents {\n const duration = motion.duration ?? 1;\n const distance = motion.distance ?? 1;\n const reverse = motion.reverse ?? false;\n const easing = motion.easing ?? \"linear\"; // Default to linear easing\n\n // 1. Calculate normalized time (0 to 1 over the duration)\n // Assuming duration > 0\n const tNormExpr = `(${relativeTimeExpr})/${duration}`;\n\n // 2. Get the easing function expression applied to normalized time\n const easedProgressExpr = getEasingExpression(tNormExpr, easing);\n\n // 3. Determine the final time factor based on easing and direction (reverse)\n // - If reverse (slide out): Progress goes 0 -> 1 (eased)\n // - If not reverse (slide in): Progress goes 1 -> 0 (eased, so 1 - eased_progress)\n const finalTimeFactorExpr = reverse\n ? easedProgressExpr\n : `(1-(${easedProgressExpr}))`; // Parentheses around easedProgressExpr are crucial\n\n let activeX: string;\n let activeY: string;\n let initialX: string;\n let initialY: string;\n let finalX: string;\n let finalY: string;\n\n switch (motion.direction) {\n case \"left\": {\n const offsetXLeft = `${distance}*W`;\n activeX = `(${offsetXLeft})*${finalTimeFactorExpr}`;\n activeY = \"0\";\n initialX = reverse ? \"0\" : offsetXLeft;\n initialY = \"0\";\n finalX = reverse ? offsetXLeft : \"0\";\n finalY = \"0\";\n break;\n }\n case \"right\": {\n const offsetXRight = `-${distance}*W`;\n activeX = `(${offsetXRight})*${finalTimeFactorExpr}`;\n activeY = \"0\";\n initialX = reverse ? \"0\" : offsetXRight;\n initialY = \"0\";\n finalX = reverse ? offsetXRight : \"0\";\n finalY = \"0\";\n break;\n }\n case \"up\": {\n const offsetYUp = `${distance}*H`;\n activeX = \"0\";\n activeY = `(${offsetYUp})*${finalTimeFactorExpr}`;\n initialX = \"0\";\n initialY = reverse ? \"0\" : offsetYUp;\n finalX = \"0\";\n finalY = reverse ? offsetYUp : \"0\";\n break;\n }\n case \"down\": {\n const offsetYDown = `-${distance}*H`;\n activeX = \"0\";\n activeY = `(${offsetYDown})*${finalTimeFactorExpr}`;\n initialX = \"0\";\n initialY = reverse ? \"0\" : offsetYDown;\n finalX = \"0\";\n finalY = reverse ? offsetYDown : \"0\";\n break;\n }\n }\n\n return { initialX, initialY, activeX, activeY, finalX, finalY, duration };\n}\n\nfunction processBounceMotion(\n motion: Extract<EffieMotion, { type: \"bounce\" }>,\n relativeTimeExpr: string,\n): MotionComponents {\n const amplitude = motion.amplitude ?? 0.5;\n const duration = motion.duration ?? 1;\n const initialY = `-overlay_h*${amplitude}`;\n const finalY = \"0\";\n\n // Calculate the normalized time expression (ranging from 0 to 1 over the duration)\n // Note: Assumes duration > 0. FFmpeg might handle division by zero, but it's safer to ensure duration > 0.\n const tNormExpr = `(${relativeTimeExpr})/${duration}`;\n\n // Piecewise parabolic approximation using normalized time (tNormExpr)\n const activeBounceExpression =\n `if(lt(${tNormExpr},0.363636),${initialY}+overlay_h*${amplitude}*(7.5625*${tNormExpr}*${tNormExpr}),` +\n `if(lt(${tNormExpr},0.727273),${initialY}+overlay_h*${amplitude}*(7.5625*(${tNormExpr}-0.545455)*(${tNormExpr}-0.545455)+0.75),` +\n `if(lt(${tNormExpr},0.909091),${initialY}+overlay_h*${amplitude}*(7.5625*(${tNormExpr}-0.818182)*(${tNormExpr}-0.818182)+0.9375),` +\n `if(lt(${tNormExpr},0.954545),${initialY}+overlay_h*${amplitude}*(7.5625*(${tNormExpr}-0.954545)*(${tNormExpr}-0.954545)+0.984375),` +\n `${finalY}` + // Should settle to finalY as tNormExpr approaches 1\n `))))`;\n\n return {\n initialX: \"0\",\n initialY: initialY,\n activeX: \"0\",\n activeY: activeBounceExpression, // This expression now scales with duration\n finalX: \"0\",\n finalY: finalY,\n duration: duration, // Return the actual duration used\n };\n}\n\nfunction processShakeMotion(\n motion: Extract<EffieMotion, { type: \"shake\" }>,\n relativeTimeExpr: string,\n): MotionComponents {\n const intensity = motion.intensity ?? 10;\n const frequency = motion.frequency ?? 4;\n const duration = motion.duration ?? 1;\n\n const activeX = `${intensity}*sin(${relativeTimeExpr}*PI*${frequency})`;\n const activeY = `${intensity}*cos(${relativeTimeExpr}*PI*${frequency})`;\n\n return {\n initialX: \"0\",\n initialY: \"0\",\n activeX: activeX,\n activeY: activeY,\n finalX: \"0\",\n finalY: \"0\",\n duration: duration,\n };\n}\n\nexport function processMotion(delay: number, motion?: EffieMotion): string {\n if (!motion) return \"x=0:y=0\";\n\n const start = delay + (motion.start ?? 0);\n const relativeTimeExpr = `(t-${start})`;\n let components: MotionComponents;\n\n switch (motion.type) {\n case \"bounce\":\n components = processBounceMotion(motion, relativeTimeExpr);\n break;\n case \"shake\":\n components = processShakeMotion(motion, relativeTimeExpr);\n break;\n case \"slide\":\n components = processSlideMotion(motion, relativeTimeExpr);\n break;\n default:\n motion satisfies never;\n throw new Error(\n `Unsupported motion type: ${(motion as EffieMotion).type}`,\n );\n }\n\n const motionEndTime = start + components.duration;\n\n const xArg = `if(lt(t,${start}),${components.initialX},if(lt(t,${motionEndTime}),${components.activeX},${components.finalX}))`;\n const yArg = `if(lt(t,${start}),${components.initialY},if(lt(t,${motionEndTime}),${components.activeY},${components.finalY}))`;\n\n return `x='${xArg}':y='${yArg}'`;\n}\n","import type { EffieEffect } from \"@effing/effie\";\n\nfunction processFadeIn(\n effect: Extract<EffieEffect, { type: \"fade-in\" }>,\n _frameRate: number,\n _frameWidth: number,\n _frameHeight: number,\n): string {\n return `fade=t=in:st=${effect.start}:d=${effect.duration}:alpha=1`;\n}\n\nfunction processFadeOut(\n effect: Extract<EffieEffect, { type: \"fade-out\" }>,\n _frameRate: number,\n _frameWidth: number,\n _frameHeight: number,\n): string {\n return `fade=t=out:st=${effect.start}:d=${effect.duration}:alpha=1`;\n}\n\nfunction processSaturateIn(\n effect: Extract<EffieEffect, { type: \"saturate-in\" }>,\n _frameRate: number,\n _frameWidth: number,\n _frameHeight: number,\n): string {\n return `hue='s=max(0,min(1,(t-${effect.start})/${effect.duration}))'`;\n}\n\nfunction processSaturateOut(\n effect: Extract<EffieEffect, { type: \"saturate-out\" }>,\n _frameRate: number,\n _frameWidth: number,\n _frameHeight: number,\n): string {\n return `hue='s=max(0,min(1,(${effect.start + effect.duration}-t)/${effect.duration}))'`;\n}\n\nfunction processScroll(\n effect: Extract<EffieEffect, { type: \"scroll\" }>,\n frameRate: number,\n _frameWidth: number,\n _frameHeight: number,\n): string {\n const distance = effect.distance ?? 1;\n const scroll = distance / (1 + distance);\n const speed = scroll / (effect.duration * frameRate);\n switch (effect.direction) {\n case \"left\":\n return `scroll=h=${speed}`;\n case \"right\":\n return `scroll=hpos=${1 - scroll}:h=-${speed}`;\n case \"up\":\n return `scroll=v=${speed}`;\n case \"down\":\n return `scroll=vpos=${1 - scroll}:v=-${speed}`;\n }\n}\n\nfunction processEffect(\n effect: EffieEffect,\n frameRate: number,\n frameWidth: number,\n frameHeight: number,\n): string {\n switch (effect.type) {\n case \"fade-in\":\n return processFadeIn(effect, frameRate, frameWidth, frameHeight);\n case \"fade-out\":\n return processFadeOut(effect, frameRate, frameWidth, frameHeight);\n case \"saturate-in\":\n return processSaturateIn(effect, frameRate, frameWidth, frameHeight);\n case \"saturate-out\":\n return processSaturateOut(effect, frameRate, frameWidth, frameHeight);\n case \"scroll\":\n return processScroll(effect, frameRate, frameWidth, frameHeight);\n default:\n effect satisfies never;\n throw new Error(\n `Unsupported effect type: ${(effect as EffieEffect).type}`,\n );\n }\n}\n\nexport function processEffects(\n effects: EffieEffect[] | undefined,\n frameRate: number,\n frameWidth: number,\n frameHeight: number,\n): string {\n if (!effects || effects.length === 0) return \"\";\n\n const filters: string[] = [];\n\n for (const effect of effects) {\n const filter = processEffect(effect, frameRate, frameWidth, frameHeight);\n filters.push(filter);\n }\n\n return filters.join(\",\");\n}\n","import type { EffieTransition } from \"@effing/effie\";\n\nexport function processTransition(transition: EffieTransition): string {\n switch (transition.type) {\n case \"fade\": {\n if (\"through\" in transition) {\n // Fade through color: fadeblack, fadewhite, fadegrays\n return `fade${transition.through}`;\n }\n // Crossfade with easing\n const easing = transition.easing ?? \"linear\";\n return {\n linear: \"fade\",\n \"ease-in\": \"fadeslow\",\n \"ease-out\": \"fadefast\",\n }[easing];\n }\n case \"barn\": {\n // Barn door wipes: vertopen, vertclose, horzopen, horzclose\n const orientation = transition.orientation ?? \"horizontal\";\n const mode = transition.mode ?? \"open\";\n const prefix = orientation === \"vertical\" ? \"vert\" : \"horz\";\n return `${prefix}${mode}`;\n }\n case \"circle\": {\n // Circle wipes: circleopen, circleclose, circlecrop\n const mode = transition.mode ?? \"open\";\n return `circle${mode}`;\n }\n case \"wipe\":\n case \"slide\":\n case \"smooth\": {\n const direction = transition.direction ?? \"left\";\n return `${transition.type}${direction}`;\n }\n case \"slice\": {\n const direction = transition.direction ?? \"left\";\n const prefix = {\n left: \"hl\",\n right: \"hr\",\n up: \"vu\",\n down: \"vd\",\n }[direction];\n return `${prefix}${transition.type}`;\n }\n case \"zoom\": {\n return \"zoomin\";\n }\n case \"dissolve\":\n case \"pixelize\":\n case \"radial\":\n return transition.type;\n default:\n transition satisfies never;\n throw new Error(\n `Unsupported transition type: ${(transition as EffieTransition).type}`,\n );\n }\n}\n","import { fetch, Agent, type Response, type BodyInit } from \"undici\";\n\n/**\n * Options for ffsFetch function\n */\nexport type FfsFetchOptions = {\n /** HTTP method */\n method?: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\" | \"HEAD\" | \"OPTIONS\";\n /** Request body */\n body?: BodyInit;\n /** Headers to send (merged with default User-Agent) */\n headers?: Record<string, string>;\n /** Timeout for receiving response headers in ms. @default 300000 (5 min) */\n headersTimeout?: number;\n /** Timeout between body data chunks in ms. 0 = no timeout. @default 300000 (5 min) */\n bodyTimeout?: number;\n};\n\n/**\n * Fetch with default User-Agent and configurable timeouts.\n *\n * @example\n * // Simple GET\n * const response = await ffsFetch(\"https://example.com/data.json\");\n *\n * @example\n * // Large file with infinite body timeout\n * const response = await ffsFetch(\"https://example.com/video.mp4\", {\n * bodyTimeout: 0,\n * });\n *\n * @example\n * // PUT upload\n * const response = await ffsFetch(\"https://s3.example.com/video.mp4\", {\n * method: \"PUT\",\n * body: videoBuffer,\n * bodyTimeout: 0,\n * headers: { \"Content-Type\": \"video/mp4\" },\n * });\n */\nexport async function ffsFetch(\n url: string,\n options?: FfsFetchOptions,\n): Promise<Response> {\n const {\n method,\n body,\n headers,\n headersTimeout = 300000, // 5 minutes\n bodyTimeout = 300000, // 5 minutes\n } = options ?? {};\n\n const agent = new Agent({ headersTimeout, bodyTimeout });\n\n return fetch(url, {\n method,\n body,\n headers: { \"User-Agent\": \"FFS (+https://effing.dev/ffs)\", ...headers },\n dispatcher: agent,\n });\n}\n","import {\n S3Client,\n PutObjectCommand,\n GetObjectCommand,\n HeadObjectCommand,\n DeleteObjectCommand,\n} from \"@aws-sdk/client-s3\";\nimport { Upload } from \"@aws-sdk/lib-storage\";\nimport fs from \"fs/promises\";\nimport { createReadStream, createWriteStream, existsSync } from \"fs\";\nimport { pipeline } from \"stream/promises\";\nimport path from \"path\";\nimport os from \"os\";\nimport crypto from \"crypto\";\nimport type { Readable } from \"stream\";\n\n/**\n * Cache storage interface\n */\nexport interface CacheStorage {\n /** Store a stream with the given key */\n put(key: string, stream: Readable): Promise<void>;\n /** Get a stream for the given key, or null if not found */\n getStream(key: string): Promise<Readable | null>;\n /** Check if a key exists */\n exists(key: string): Promise<boolean>;\n /** Check if multiple keys exist (batch operation) */\n existsMany(keys: string[]): Promise<Map<string, boolean>>;\n /** Delete a key */\n delete(key: string): Promise<void>;\n /** Store JSON data */\n putJson(key: string, data: object): Promise<void>;\n /** Get JSON data, or null if not found */\n getJson<T>(key: string): Promise<T | null>;\n /** Close and cleanup resources */\n close(): void;\n}\n\n/**\n * S3-compatible cache storage implementation\n */\nexport class S3CacheStorage implements CacheStorage {\n private client: S3Client;\n private bucket: string;\n private prefix: string;\n private ttlMs: number;\n\n constructor(options: {\n endpoint?: string;\n region?: string;\n bucket: string;\n prefix?: string;\n accessKeyId?: string;\n secretAccessKey?: string;\n ttlMs?: number;\n }) {\n this.client = new S3Client({\n endpoint: options.endpoint,\n region: options.region ?? \"auto\",\n credentials: options.accessKeyId\n ? {\n accessKeyId: options.accessKeyId,\n secretAccessKey: options.secretAccessKey!,\n }\n : undefined,\n forcePathStyle: !!options.endpoint,\n });\n this.bucket = options.bucket;\n this.prefix = options.prefix ?? \"\";\n this.ttlMs = options.ttlMs ?? 60 * 60 * 1000; // Default: 60 minutes\n }\n\n private getExpires(): Date {\n return new Date(Date.now() + this.ttlMs);\n }\n\n private getFullKey(key: string): string {\n return `${this.prefix}${key}`;\n }\n\n async put(key: string, stream: Readable): Promise<void> {\n const upload = new Upload({\n client: this.client,\n params: {\n Bucket: this.bucket,\n Key: this.getFullKey(key),\n Body: stream,\n Expires: this.getExpires(),\n },\n });\n await upload.done();\n }\n\n async getStream(key: string): Promise<Readable | null> {\n try {\n const response = await this.client.send(\n new GetObjectCommand({\n Bucket: this.bucket,\n Key: this.getFullKey(key),\n }),\n );\n return response.Body as Readable;\n } catch (err: unknown) {\n const error = err as {\n name?: string;\n $metadata?: { httpStatusCode?: number };\n };\n if (\n error.name === \"NoSuchKey\" ||\n error.$metadata?.httpStatusCode === 404\n ) {\n return null;\n }\n throw err;\n }\n }\n\n async exists(key: string): Promise<boolean> {\n try {\n await this.client.send(\n new HeadObjectCommand({\n Bucket: this.bucket,\n Key: this.getFullKey(key),\n }),\n );\n return true;\n } catch (err: unknown) {\n const error = err as {\n name?: string;\n $metadata?: { httpStatusCode?: number };\n };\n if (\n error.name === \"NotFound\" ||\n error.$metadata?.httpStatusCode === 404\n ) {\n return false;\n }\n throw err;\n }\n }\n\n async existsMany(keys: string[]): Promise<Map<string, boolean>> {\n const results = await Promise.all(\n keys.map(async (key) => [key, await this.exists(key)] as const),\n );\n return new Map(results);\n }\n\n async delete(key: string): Promise<void> {\n try {\n await this.client.send(\n new DeleteObjectCommand({\n Bucket: this.bucket,\n Key: this.getFullKey(key),\n }),\n );\n } catch (err: unknown) {\n const error = err as {\n name?: string;\n $metadata?: { httpStatusCode?: number };\n };\n if (\n error.name === \"NoSuchKey\" ||\n error.$metadata?.httpStatusCode === 404\n ) {\n return;\n }\n throw err;\n }\n }\n\n async putJson(key: string, data: object): Promise<void> {\n await this.client.send(\n new PutObjectCommand({\n Bucket: this.bucket,\n Key: this.getFullKey(key),\n Body: JSON.stringify(data),\n ContentType: \"application/json\",\n Expires: this.getExpires(),\n }),\n );\n }\n\n async getJson<T>(key: string): Promise<T | null> {\n try {\n const response = await this.client.send(\n new GetObjectCommand({\n Bucket: this.bucket,\n Key: this.getFullKey(key),\n }),\n );\n const body = await response.Body?.transformToString();\n if (!body) return null;\n return JSON.parse(body) as T;\n } catch (err: unknown) {\n const error = err as {\n name?: string;\n $metadata?: { httpStatusCode?: number };\n };\n if (\n error.name === \"NoSuchKey\" ||\n error.$metadata?.httpStatusCode === 404\n ) {\n return null;\n }\n throw err;\n }\n }\n\n close(): void {\n // nothing to do here\n }\n}\n\n/**\n * Local filesystem cache storage implementation\n */\nexport class LocalCacheStorage implements CacheStorage {\n private baseDir: string;\n private initialized = false;\n private cleanupInterval?: ReturnType<typeof setInterval>;\n private ttlMs: number;\n\n constructor(baseDir?: string, ttlMs: number = 60 * 60 * 1000) {\n this.baseDir = baseDir ?? path.join(os.tmpdir(), \"ffs-cache\");\n this.ttlMs = ttlMs;\n\n // Cleanup expired files every 5 minutes\n this.cleanupInterval = setInterval(() => {\n this.cleanupExpired().catch(console.error);\n }, 300_000);\n }\n\n /**\n * Remove files older than TTL\n */\n public async cleanupExpired(): Promise<void> {\n if (!this.initialized) return;\n\n const now = Date.now();\n await this.cleanupDir(this.baseDir, now);\n }\n\n private async cleanupDir(dir: string, now: number): Promise<void> {\n let entries;\n try {\n entries = await fs.readdir(dir, { withFileTypes: true });\n } catch {\n return; // Directory doesn't exist or can't be read\n }\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n await this.cleanupDir(fullPath, now);\n // Remove empty directories\n try {\n await fs.rmdir(fullPath);\n } catch {\n // Directory not empty or other error, ignore\n }\n } else if (entry.isFile()) {\n try {\n const stat = await fs.stat(fullPath);\n if (now - stat.mtimeMs > this.ttlMs) {\n await fs.rm(fullPath, { force: true });\n }\n } catch {\n // File may have been deleted, ignore\n }\n }\n }\n }\n\n private async ensureDir(filePath: string): Promise<void> {\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n this.initialized = true;\n }\n\n private filePath(key: string): string {\n return path.join(this.baseDir, key);\n }\n\n private tmpPathFor(finalPath: string): string {\n const rand = crypto.randomBytes(8).toString(\"hex\");\n // Keep tmp file in the same directory so rename stays atomic on POSIX filesystems.\n return `${finalPath}.tmp-${process.pid}-${rand}`;\n }\n\n async put(key: string, stream: Readable): Promise<void> {\n const fp = this.filePath(key);\n await this.ensureDir(fp);\n\n // Write to temp file, then rename for atomicity (no partial reads).\n const tmpPath = this.tmpPathFor(fp);\n try {\n const writeStream = createWriteStream(tmpPath);\n await pipeline(stream, writeStream);\n await fs.rename(tmpPath, fp);\n } catch (err) {\n await fs.rm(tmpPath, { force: true }).catch(() => {});\n throw err;\n }\n }\n\n async getStream(key: string): Promise<Readable | null> {\n const fp = this.filePath(key);\n if (!existsSync(fp)) return null;\n return createReadStream(fp);\n }\n\n async exists(key: string): Promise<boolean> {\n try {\n await fs.access(this.filePath(key));\n return true;\n } catch {\n return false;\n }\n }\n\n async existsMany(keys: string[]): Promise<Map<string, boolean>> {\n const results = await Promise.all(\n keys.map(async (key) => [key, await this.exists(key)] as const),\n );\n return new Map(results);\n }\n\n async delete(key: string): Promise<void> {\n await fs.rm(this.filePath(key), { force: true });\n }\n\n async putJson(key: string, data: object): Promise<void> {\n const fp = this.filePath(key);\n await this.ensureDir(fp);\n\n // Write to temp file, then rename for atomicity (no partial reads).\n const tmpPath = this.tmpPathFor(fp);\n try {\n await fs.writeFile(tmpPath, JSON.stringify(data));\n await fs.rename(tmpPath, fp);\n } catch (err) {\n await fs.rm(tmpPath, { force: true }).catch(() => {});\n throw err;\n }\n }\n\n async getJson<T>(key: string): Promise<T | null> {\n try {\n const content = await fs.readFile(this.filePath(key), \"utf-8\");\n return JSON.parse(content) as T;\n } catch {\n return null;\n }\n }\n\n close(): void {\n // Stop the cleanup interval\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval);\n this.cleanupInterval = undefined;\n }\n }\n}\n\n/**\n * Create a cache storage instance based on environment variables.\n * Uses S3 if FFS_CACHE_BUCKET is set, otherwise uses local filesystem.\n */\nexport function createCacheStorage(): CacheStorage {\n // Parse TTL from env (default: 60 minutes)\n const ttlMs = process.env.FFS_CACHE_TTL_MS\n ? parseInt(process.env.FFS_CACHE_TTL_MS, 10)\n : 60 * 60 * 1000;\n\n if (process.env.FFS_CACHE_BUCKET) {\n return new S3CacheStorage({\n endpoint: process.env.FFS_CACHE_ENDPOINT,\n region: process.env.FFS_CACHE_REGION ?? \"auto\",\n bucket: process.env.FFS_CACHE_BUCKET,\n prefix: process.env.FFS_CACHE_PREFIX,\n accessKeyId: process.env.FFS_CACHE_ACCESS_KEY,\n secretAccessKey: process.env.FFS_CACHE_SECRET_KEY,\n ttlMs,\n });\n }\n\n return new LocalCacheStorage(process.env.FFS_CACHE_LOCAL_DIR, ttlMs);\n}\n\nexport function hashUrl(url: string): string {\n return crypto.createHash(\"sha256\").update(url).digest(\"hex\").slice(0, 16);\n}\n\nexport type SourceCacheKey = `sources/${string}`;\nexport type WarmupJobCacheKey = `jobs/warmup/${string}.json`;\nexport type RenderJobCacheKey = `jobs/render/${string}.json`;\n\n/**\n * Build the cache key for a source URL (hashing is handled internally).\n */\nexport function sourceCacheKey(url: string): SourceCacheKey {\n return `sources/${hashUrl(url)}`;\n}\n\nexport function warmupJobCacheKey(jobId: string): WarmupJobCacheKey {\n return `jobs/warmup/${jobId}.json`;\n}\n\nexport function renderJobCacheKey(jobId: string): RenderJobCacheKey {\n return `jobs/render/${jobId}.json`;\n}\n\n/**\n * Centralized cache key builders for known namespaces.\n * Prefer using these helpers over manual string interpolation.\n */\nexport const cacheKeys = {\n source: sourceCacheKey,\n warmupJob: warmupJobCacheKey,\n renderJob: renderJobCacheKey,\n} as const;\n"],"mappings":";AACA,SAAS,aAAa;AAEtB,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,kBAAkB;AACzB,OAAO,SAAS;AAChB,SAAS,yBAAyB;AAClC,SAAS,iBAAiB;AAE1B,IAAM,OAAO,UAAU,QAAQ;AAaxB,IAAM,gBAAN,MAAoB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YACE,YACA,QACA,eACA,YACA;AACA,SAAK,aAAa;AAClB,SAAK,SAAS;AACd,SAAK,gBAAgB;AACrB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