@effing/ffs 0.4.0 → 0.5.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/dist/chunk-5SGOYTM2.js +341 -0
- package/dist/chunk-5SGOYTM2.js.map +1 -0
- package/dist/{chunk-J64HSZNQ.js → chunk-N3D6I2BD.js} +179 -499
- package/dist/chunk-N3D6I2BD.js.map +1 -0
- package/dist/chunk-QPZEAH3J.js +342 -0
- package/dist/{chunk-7FMPCMLO.js → chunk-ZERUSI5T.js} +10 -5
- package/dist/chunk-ZERUSI5T.js.map +1 -0
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +2 -2
- package/dist/index.js +2 -1
- package/dist/render-NEDCS65O.js +8 -0
- package/dist/render-NEDCS65O.js.map +1 -0
- package/dist/render-VWBOR3Y2.js +936 -0
- package/dist/server.js +22 -1259
- package/dist/server.js.map +1 -1
- package/package.json +5 -3
- package/dist/chunk-7FMPCMLO.js.map +0 -1
- package/dist/chunk-J64HSZNQ.js.map +0 -1
|
@@ -1,161 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
ffsFetch,
|
|
3
|
+
storeKeys
|
|
4
|
+
} from "./chunk-5SGOYTM2.js";
|
|
155
5
|
|
|
156
6
|
// src/render.ts
|
|
157
7
|
import { Readable } from "stream";
|
|
158
|
-
import { createReadStream
|
|
8
|
+
import { createReadStream } from "fs";
|
|
159
9
|
|
|
160
10
|
// src/motion.ts
|
|
161
11
|
function getEasingExpression(tNormExpr, easingType) {
|
|
@@ -348,6 +198,178 @@ function processEffects(effects, frameRate, frameWidth, frameHeight) {
|
|
|
348
198
|
return filters.join(",");
|
|
349
199
|
}
|
|
350
200
|
|
|
201
|
+
// src/ffmpeg.ts
|
|
202
|
+
import { spawn } from "child_process";
|
|
203
|
+
import { pipeline } from "stream";
|
|
204
|
+
import fs from "fs/promises";
|
|
205
|
+
import os from "os";
|
|
206
|
+
import path from "path";
|
|
207
|
+
import tar from "tar-stream";
|
|
208
|
+
import { createWriteStream } from "fs";
|
|
209
|
+
import { promisify } from "util";
|
|
210
|
+
var pump = promisify(pipeline);
|
|
211
|
+
var resolvedBin;
|
|
212
|
+
async function getFFmpegBin() {
|
|
213
|
+
if (resolvedBin) return resolvedBin;
|
|
214
|
+
if (process.env.FFMPEG) {
|
|
215
|
+
resolvedBin = process.env.FFMPEG;
|
|
216
|
+
return resolvedBin;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const { pathToFFmpeg } = await import("@effing/ffmpeg");
|
|
220
|
+
if (pathToFFmpeg) {
|
|
221
|
+
resolvedBin = pathToFFmpeg;
|
|
222
|
+
return resolvedBin;
|
|
223
|
+
}
|
|
224
|
+
} catch {
|
|
225
|
+
}
|
|
226
|
+
resolvedBin = "ffmpeg";
|
|
227
|
+
return resolvedBin;
|
|
228
|
+
}
|
|
229
|
+
var FFmpegCommand = class {
|
|
230
|
+
globalArgs;
|
|
231
|
+
inputs;
|
|
232
|
+
filterComplex;
|
|
233
|
+
outputArgs;
|
|
234
|
+
constructor(globalArgs, inputs, filterComplex, outputArgs) {
|
|
235
|
+
this.globalArgs = globalArgs;
|
|
236
|
+
this.inputs = inputs;
|
|
237
|
+
this.filterComplex = filterComplex;
|
|
238
|
+
this.outputArgs = outputArgs;
|
|
239
|
+
}
|
|
240
|
+
buildArgs(inputResolver) {
|
|
241
|
+
const inputArgs = [];
|
|
242
|
+
for (const input of this.inputs) {
|
|
243
|
+
if (input.type === "color") {
|
|
244
|
+
inputArgs.push(...input.preArgs);
|
|
245
|
+
} else if (input.type === "animation") {
|
|
246
|
+
inputArgs.push(
|
|
247
|
+
...input.preArgs,
|
|
248
|
+
"-i",
|
|
249
|
+
path.join(inputResolver(input), "frame_%05d")
|
|
250
|
+
);
|
|
251
|
+
} else {
|
|
252
|
+
inputArgs.push(...input.preArgs, "-i", inputResolver(input));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const args = [
|
|
256
|
+
...this.globalArgs,
|
|
257
|
+
...inputArgs,
|
|
258
|
+
"-filter_complex",
|
|
259
|
+
this.filterComplex,
|
|
260
|
+
...this.outputArgs
|
|
261
|
+
];
|
|
262
|
+
return args;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var FFmpegRunner = class {
|
|
266
|
+
command;
|
|
267
|
+
ffmpegProc;
|
|
268
|
+
constructor(command) {
|
|
269
|
+
this.command = command;
|
|
270
|
+
}
|
|
271
|
+
async run(sourceFetcher, imageTransformer, referenceResolver, urlTransformer) {
|
|
272
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "ffs-"));
|
|
273
|
+
const fileMapping = /* @__PURE__ */ new Map();
|
|
274
|
+
const fetchCache = /* @__PURE__ */ new Map();
|
|
275
|
+
const fetchAndSaveSource = async (input, sourceUrl, inputName) => {
|
|
276
|
+
const stream = await sourceFetcher({
|
|
277
|
+
type: input.type,
|
|
278
|
+
src: sourceUrl
|
|
279
|
+
});
|
|
280
|
+
if (input.type === "animation") {
|
|
281
|
+
const extractionDir = path.join(tempDir, inputName);
|
|
282
|
+
await fs.mkdir(extractionDir, { recursive: true });
|
|
283
|
+
const extract = tar.extract();
|
|
284
|
+
const extractPromise = new Promise((resolve, reject) => {
|
|
285
|
+
extract.on("entry", async (header, stream2, next) => {
|
|
286
|
+
if (header.name.startsWith("frame_")) {
|
|
287
|
+
const transformedStream = imageTransformer ? await imageTransformer(stream2) : stream2;
|
|
288
|
+
const outputPath = path.join(extractionDir, header.name);
|
|
289
|
+
const writeStream = createWriteStream(outputPath);
|
|
290
|
+
transformedStream.pipe(writeStream);
|
|
291
|
+
writeStream.on("finish", next);
|
|
292
|
+
writeStream.on("error", reject);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
extract.on("finish", resolve);
|
|
296
|
+
extract.on("error", reject);
|
|
297
|
+
});
|
|
298
|
+
stream.pipe(extract);
|
|
299
|
+
await extractPromise;
|
|
300
|
+
return extractionDir;
|
|
301
|
+
} else if (input.type === "image" && imageTransformer) {
|
|
302
|
+
const tempFile = path.join(tempDir, inputName);
|
|
303
|
+
const transformedStream = await imageTransformer(stream);
|
|
304
|
+
const writeStream = createWriteStream(tempFile);
|
|
305
|
+
transformedStream.on("error", (e) => writeStream.destroy(e));
|
|
306
|
+
await pump(transformedStream, writeStream);
|
|
307
|
+
return tempFile;
|
|
308
|
+
} else {
|
|
309
|
+
const tempFile = path.join(tempDir, inputName);
|
|
310
|
+
const writeStream = createWriteStream(tempFile);
|
|
311
|
+
stream.on("error", (e) => writeStream.destroy(e));
|
|
312
|
+
await pump(stream, writeStream);
|
|
313
|
+
return tempFile;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
await Promise.all(
|
|
317
|
+
this.command.inputs.map(async (input) => {
|
|
318
|
+
if (input.type === "color") return;
|
|
319
|
+
const inputName = `ffmpeg_input_${input.index.toString().padStart(3, "0")}`;
|
|
320
|
+
const sourceUrl = referenceResolver ? referenceResolver(input.source) : input.source;
|
|
321
|
+
if ((input.type === "video" || input.type === "audio") && (sourceUrl.startsWith("http://") || sourceUrl.startsWith("https://"))) {
|
|
322
|
+
const finalUrl = urlTransformer ? urlTransformer(sourceUrl) : sourceUrl;
|
|
323
|
+
fileMapping.set(input.index, finalUrl);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const shouldCache = input.source.startsWith("#");
|
|
327
|
+
if (shouldCache) {
|
|
328
|
+
let fetchPromise = fetchCache.get(input.source);
|
|
329
|
+
if (!fetchPromise) {
|
|
330
|
+
fetchPromise = fetchAndSaveSource(input, sourceUrl, inputName);
|
|
331
|
+
fetchCache.set(input.source, fetchPromise);
|
|
332
|
+
}
|
|
333
|
+
const filePath = await fetchPromise;
|
|
334
|
+
fileMapping.set(input.index, filePath);
|
|
335
|
+
} else {
|
|
336
|
+
const filePath = await fetchAndSaveSource(
|
|
337
|
+
input,
|
|
338
|
+
sourceUrl,
|
|
339
|
+
inputName
|
|
340
|
+
);
|
|
341
|
+
fileMapping.set(input.index, filePath);
|
|
342
|
+
}
|
|
343
|
+
})
|
|
344
|
+
);
|
|
345
|
+
const finalArgs = this.command.buildArgs((input) => {
|
|
346
|
+
const filePath = fileMapping.get(input.index);
|
|
347
|
+
if (!filePath)
|
|
348
|
+
throw new Error(`File for input index ${input.index} not found`);
|
|
349
|
+
return filePath;
|
|
350
|
+
});
|
|
351
|
+
const ffmpegProc = spawn(await getFFmpegBin(), finalArgs);
|
|
352
|
+
ffmpegProc.stderr.on("data", (data) => {
|
|
353
|
+
console.error(data.toString());
|
|
354
|
+
});
|
|
355
|
+
ffmpegProc.on("close", async () => {
|
|
356
|
+
try {
|
|
357
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
358
|
+
} catch (err) {
|
|
359
|
+
console.error("Error removing temp directory:", err);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
this.ffmpegProc = ffmpegProc;
|
|
363
|
+
return ffmpegProc.stdout;
|
|
364
|
+
}
|
|
365
|
+
close() {
|
|
366
|
+
if (this.ffmpegProc) {
|
|
367
|
+
this.ffmpegProc.kill("SIGTERM");
|
|
368
|
+
this.ffmpegProc = void 0;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
351
373
|
// src/transition.ts
|
|
352
374
|
function processTransition(transition) {
|
|
353
375
|
switch (transition.type) {
|
|
@@ -405,346 +427,7 @@ function processTransition(transition) {
|
|
|
405
427
|
|
|
406
428
|
// src/render.ts
|
|
407
429
|
import sharp from "sharp";
|
|
408
|
-
|
|
409
|
-
// src/fetch.ts
|
|
410
|
-
import { fetch, Agent } from "undici";
|
|
411
|
-
async function ffsFetch(url, options) {
|
|
412
|
-
const {
|
|
413
|
-
method,
|
|
414
|
-
body,
|
|
415
|
-
headers,
|
|
416
|
-
headersTimeout = 3e5,
|
|
417
|
-
// 5 minutes
|
|
418
|
-
bodyTimeout = 3e5
|
|
419
|
-
// 5 minutes
|
|
420
|
-
} = options ?? {};
|
|
421
|
-
const agent = new Agent({ headersTimeout, bodyTimeout });
|
|
422
|
-
return fetch(url, {
|
|
423
|
-
method,
|
|
424
|
-
body,
|
|
425
|
-
headers: { "User-Agent": "FFS (+https://effing.dev/ffs)", ...headers },
|
|
426
|
-
dispatcher: agent
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// src/render.ts
|
|
431
430
|
import { fileURLToPath } from "url";
|
|
432
|
-
|
|
433
|
-
// src/storage.ts
|
|
434
|
-
import {
|
|
435
|
-
S3Client,
|
|
436
|
-
PutObjectCommand,
|
|
437
|
-
GetObjectCommand,
|
|
438
|
-
HeadObjectCommand,
|
|
439
|
-
DeleteObjectCommand
|
|
440
|
-
} from "@aws-sdk/client-s3";
|
|
441
|
-
import { Upload } from "@aws-sdk/lib-storage";
|
|
442
|
-
import fs2 from "fs/promises";
|
|
443
|
-
import { createReadStream, createWriteStream as createWriteStream2, existsSync } from "fs";
|
|
444
|
-
import { pipeline as pipeline2 } from "stream/promises";
|
|
445
|
-
import path2 from "path";
|
|
446
|
-
import os2 from "os";
|
|
447
|
-
import crypto from "crypto";
|
|
448
|
-
var DEFAULT_SOURCE_TTL_MS = 60 * 60 * 1e3;
|
|
449
|
-
var DEFAULT_JOB_METADATA_TTL_MS = 8 * 60 * 60 * 1e3;
|
|
450
|
-
var S3TransientStore = class {
|
|
451
|
-
client;
|
|
452
|
-
bucket;
|
|
453
|
-
prefix;
|
|
454
|
-
sourceTtlMs;
|
|
455
|
-
jobMetadataTtlMs;
|
|
456
|
-
constructor(options) {
|
|
457
|
-
this.client = new S3Client({
|
|
458
|
-
endpoint: options.endpoint,
|
|
459
|
-
region: options.region ?? "auto",
|
|
460
|
-
credentials: options.accessKeyId ? {
|
|
461
|
-
accessKeyId: options.accessKeyId,
|
|
462
|
-
secretAccessKey: options.secretAccessKey
|
|
463
|
-
} : void 0,
|
|
464
|
-
forcePathStyle: !!options.endpoint
|
|
465
|
-
});
|
|
466
|
-
this.bucket = options.bucket;
|
|
467
|
-
this.prefix = options.prefix ?? "";
|
|
468
|
-
this.sourceTtlMs = options.sourceTtlMs ?? DEFAULT_SOURCE_TTL_MS;
|
|
469
|
-
this.jobMetadataTtlMs = options.jobMetadataTtlMs ?? DEFAULT_JOB_METADATA_TTL_MS;
|
|
470
|
-
}
|
|
471
|
-
getExpires(ttlMs) {
|
|
472
|
-
return new Date(Date.now() + ttlMs);
|
|
473
|
-
}
|
|
474
|
-
getFullKey(key) {
|
|
475
|
-
return `${this.prefix}${key}`;
|
|
476
|
-
}
|
|
477
|
-
async put(key, stream, ttlMs) {
|
|
478
|
-
const upload = new Upload({
|
|
479
|
-
client: this.client,
|
|
480
|
-
params: {
|
|
481
|
-
Bucket: this.bucket,
|
|
482
|
-
Key: this.getFullKey(key),
|
|
483
|
-
Body: stream,
|
|
484
|
-
Expires: this.getExpires(ttlMs ?? this.sourceTtlMs)
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
await upload.done();
|
|
488
|
-
}
|
|
489
|
-
async getStream(key) {
|
|
490
|
-
try {
|
|
491
|
-
const response = await this.client.send(
|
|
492
|
-
new GetObjectCommand({
|
|
493
|
-
Bucket: this.bucket,
|
|
494
|
-
Key: this.getFullKey(key)
|
|
495
|
-
})
|
|
496
|
-
);
|
|
497
|
-
return response.Body;
|
|
498
|
-
} catch (err) {
|
|
499
|
-
const error = err;
|
|
500
|
-
if (error.name === "NoSuchKey" || error.$metadata?.httpStatusCode === 404) {
|
|
501
|
-
return null;
|
|
502
|
-
}
|
|
503
|
-
throw err;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
async exists(key) {
|
|
507
|
-
try {
|
|
508
|
-
await this.client.send(
|
|
509
|
-
new HeadObjectCommand({
|
|
510
|
-
Bucket: this.bucket,
|
|
511
|
-
Key: this.getFullKey(key)
|
|
512
|
-
})
|
|
513
|
-
);
|
|
514
|
-
return true;
|
|
515
|
-
} catch (err) {
|
|
516
|
-
const error = err;
|
|
517
|
-
if (error.name === "NotFound" || error.$metadata?.httpStatusCode === 404) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
throw err;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
async existsMany(keys) {
|
|
524
|
-
const results = await Promise.all(
|
|
525
|
-
keys.map(async (key) => [key, await this.exists(key)])
|
|
526
|
-
);
|
|
527
|
-
return new Map(results);
|
|
528
|
-
}
|
|
529
|
-
async delete(key) {
|
|
530
|
-
try {
|
|
531
|
-
await this.client.send(
|
|
532
|
-
new DeleteObjectCommand({
|
|
533
|
-
Bucket: this.bucket,
|
|
534
|
-
Key: this.getFullKey(key)
|
|
535
|
-
})
|
|
536
|
-
);
|
|
537
|
-
} catch (err) {
|
|
538
|
-
const error = err;
|
|
539
|
-
if (error.name === "NoSuchKey" || error.$metadata?.httpStatusCode === 404) {
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
throw err;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
async putJson(key, data, ttlMs) {
|
|
546
|
-
await this.client.send(
|
|
547
|
-
new PutObjectCommand({
|
|
548
|
-
Bucket: this.bucket,
|
|
549
|
-
Key: this.getFullKey(key),
|
|
550
|
-
Body: JSON.stringify(data),
|
|
551
|
-
ContentType: "application/json",
|
|
552
|
-
Expires: this.getExpires(ttlMs ?? this.jobMetadataTtlMs)
|
|
553
|
-
})
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
async getJson(key) {
|
|
557
|
-
try {
|
|
558
|
-
const response = await this.client.send(
|
|
559
|
-
new GetObjectCommand({
|
|
560
|
-
Bucket: this.bucket,
|
|
561
|
-
Key: this.getFullKey(key)
|
|
562
|
-
})
|
|
563
|
-
);
|
|
564
|
-
const body = await response.Body?.transformToString();
|
|
565
|
-
if (!body) return null;
|
|
566
|
-
return JSON.parse(body);
|
|
567
|
-
} catch (err) {
|
|
568
|
-
const error = err;
|
|
569
|
-
if (error.name === "NoSuchKey" || error.$metadata?.httpStatusCode === 404) {
|
|
570
|
-
return null;
|
|
571
|
-
}
|
|
572
|
-
throw err;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
close() {
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
var LocalTransientStore = class {
|
|
579
|
-
baseDir;
|
|
580
|
-
initialized = false;
|
|
581
|
-
cleanupInterval;
|
|
582
|
-
sourceTtlMs;
|
|
583
|
-
jobMetadataTtlMs;
|
|
584
|
-
/** For cleanup, use the longer of the two TTLs */
|
|
585
|
-
maxTtlMs;
|
|
586
|
-
constructor(options) {
|
|
587
|
-
this.baseDir = options?.baseDir ?? path2.join(os2.tmpdir(), "ffs-transient");
|
|
588
|
-
this.sourceTtlMs = options?.sourceTtlMs ?? DEFAULT_SOURCE_TTL_MS;
|
|
589
|
-
this.jobMetadataTtlMs = options?.jobMetadataTtlMs ?? DEFAULT_JOB_METADATA_TTL_MS;
|
|
590
|
-
this.maxTtlMs = Math.max(this.sourceTtlMs, this.jobMetadataTtlMs);
|
|
591
|
-
this.cleanupInterval = setInterval(() => {
|
|
592
|
-
this.cleanupExpired().catch(console.error);
|
|
593
|
-
}, 3e5);
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Remove files older than max TTL
|
|
597
|
-
*/
|
|
598
|
-
async cleanupExpired() {
|
|
599
|
-
if (!this.initialized) return;
|
|
600
|
-
const now = Date.now();
|
|
601
|
-
await this.cleanupDir(this.baseDir, now);
|
|
602
|
-
}
|
|
603
|
-
async cleanupDir(dir, now) {
|
|
604
|
-
let entries;
|
|
605
|
-
try {
|
|
606
|
-
entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
607
|
-
} catch {
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
for (const entry of entries) {
|
|
611
|
-
const fullPath = path2.join(dir, entry.name);
|
|
612
|
-
if (entry.isDirectory()) {
|
|
613
|
-
await this.cleanupDir(fullPath, now);
|
|
614
|
-
try {
|
|
615
|
-
await fs2.rmdir(fullPath);
|
|
616
|
-
} catch {
|
|
617
|
-
}
|
|
618
|
-
} else if (entry.isFile()) {
|
|
619
|
-
try {
|
|
620
|
-
const stat = await fs2.stat(fullPath);
|
|
621
|
-
if (now - stat.mtimeMs > this.maxTtlMs) {
|
|
622
|
-
await fs2.rm(fullPath, { force: true });
|
|
623
|
-
}
|
|
624
|
-
} catch {
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
async ensureDir(filePath) {
|
|
630
|
-
await fs2.mkdir(path2.dirname(filePath), { recursive: true });
|
|
631
|
-
this.initialized = true;
|
|
632
|
-
}
|
|
633
|
-
filePath(key) {
|
|
634
|
-
return path2.join(this.baseDir, key);
|
|
635
|
-
}
|
|
636
|
-
tmpPathFor(finalPath) {
|
|
637
|
-
const rand = crypto.randomBytes(8).toString("hex");
|
|
638
|
-
return `${finalPath}.tmp-${process.pid}-${rand}`;
|
|
639
|
-
}
|
|
640
|
-
async put(key, stream, _ttlMs) {
|
|
641
|
-
const fp = this.filePath(key);
|
|
642
|
-
await this.ensureDir(fp);
|
|
643
|
-
const tmpPath = this.tmpPathFor(fp);
|
|
644
|
-
try {
|
|
645
|
-
const writeStream = createWriteStream2(tmpPath);
|
|
646
|
-
await pipeline2(stream, writeStream);
|
|
647
|
-
await fs2.rename(tmpPath, fp);
|
|
648
|
-
} catch (err) {
|
|
649
|
-
await fs2.rm(tmpPath, { force: true }).catch(() => {
|
|
650
|
-
});
|
|
651
|
-
throw err;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
async getStream(key) {
|
|
655
|
-
const fp = this.filePath(key);
|
|
656
|
-
if (!existsSync(fp)) return null;
|
|
657
|
-
return createReadStream(fp);
|
|
658
|
-
}
|
|
659
|
-
async exists(key) {
|
|
660
|
-
try {
|
|
661
|
-
await fs2.access(this.filePath(key));
|
|
662
|
-
return true;
|
|
663
|
-
} catch {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
async existsMany(keys) {
|
|
668
|
-
const results = await Promise.all(
|
|
669
|
-
keys.map(async (key) => [key, await this.exists(key)])
|
|
670
|
-
);
|
|
671
|
-
return new Map(results);
|
|
672
|
-
}
|
|
673
|
-
async delete(key) {
|
|
674
|
-
await fs2.rm(this.filePath(key), { force: true });
|
|
675
|
-
}
|
|
676
|
-
async putJson(key, data, _ttlMs) {
|
|
677
|
-
const fp = this.filePath(key);
|
|
678
|
-
await this.ensureDir(fp);
|
|
679
|
-
const tmpPath = this.tmpPathFor(fp);
|
|
680
|
-
try {
|
|
681
|
-
await fs2.writeFile(tmpPath, JSON.stringify(data));
|
|
682
|
-
await fs2.rename(tmpPath, fp);
|
|
683
|
-
} catch (err) {
|
|
684
|
-
await fs2.rm(tmpPath, { force: true }).catch(() => {
|
|
685
|
-
});
|
|
686
|
-
throw err;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
async getJson(key) {
|
|
690
|
-
try {
|
|
691
|
-
const content = await fs2.readFile(this.filePath(key), "utf-8");
|
|
692
|
-
return JSON.parse(content);
|
|
693
|
-
} catch {
|
|
694
|
-
return null;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
close() {
|
|
698
|
-
if (this.cleanupInterval) {
|
|
699
|
-
clearInterval(this.cleanupInterval);
|
|
700
|
-
this.cleanupInterval = void 0;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
function createTransientStore() {
|
|
705
|
-
const sourceTtlMs = process.env.FFS_SOURCE_CACHE_TTL_MS ? parseInt(process.env.FFS_SOURCE_CACHE_TTL_MS, 10) : DEFAULT_SOURCE_TTL_MS;
|
|
706
|
-
const jobMetadataTtlMs = process.env.FFS_JOB_METADATA_TTL_MS ? parseInt(process.env.FFS_JOB_METADATA_TTL_MS, 10) : DEFAULT_JOB_METADATA_TTL_MS;
|
|
707
|
-
if (process.env.FFS_TRANSIENT_STORE_BUCKET) {
|
|
708
|
-
return new S3TransientStore({
|
|
709
|
-
endpoint: process.env.FFS_TRANSIENT_STORE_ENDPOINT,
|
|
710
|
-
region: process.env.FFS_TRANSIENT_STORE_REGION ?? "auto",
|
|
711
|
-
bucket: process.env.FFS_TRANSIENT_STORE_BUCKET,
|
|
712
|
-
prefix: process.env.FFS_TRANSIENT_STORE_PREFIX,
|
|
713
|
-
accessKeyId: process.env.FFS_TRANSIENT_STORE_ACCESS_KEY,
|
|
714
|
-
secretAccessKey: process.env.FFS_TRANSIENT_STORE_SECRET_KEY,
|
|
715
|
-
sourceTtlMs,
|
|
716
|
-
jobMetadataTtlMs
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
return new LocalTransientStore({
|
|
720
|
-
baseDir: process.env.FFS_TRANSIENT_STORE_LOCAL_DIR,
|
|
721
|
-
sourceTtlMs,
|
|
722
|
-
jobMetadataTtlMs
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
function hashUrl(url) {
|
|
726
|
-
return crypto.createHash("sha256").update(url).digest("hex").slice(0, 16);
|
|
727
|
-
}
|
|
728
|
-
function sourceStoreKey(url) {
|
|
729
|
-
return `sources/${hashUrl(url)}`;
|
|
730
|
-
}
|
|
731
|
-
function warmupJobStoreKey(jobId) {
|
|
732
|
-
return `jobs/warmup/${jobId}.json`;
|
|
733
|
-
}
|
|
734
|
-
function renderJobStoreKey(jobId) {
|
|
735
|
-
return `jobs/render/${jobId}.json`;
|
|
736
|
-
}
|
|
737
|
-
function warmupAndRenderJobStoreKey(jobId) {
|
|
738
|
-
return `jobs/warmup-and-render/${jobId}.json`;
|
|
739
|
-
}
|
|
740
|
-
var storeKeys = {
|
|
741
|
-
source: sourceStoreKey,
|
|
742
|
-
warmupJob: warmupJobStoreKey,
|
|
743
|
-
renderJob: renderJobStoreKey,
|
|
744
|
-
warmupAndRenderJob: warmupAndRenderJobStoreKey
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
// src/render.ts
|
|
748
431
|
var EffieRenderer = class {
|
|
749
432
|
effieData;
|
|
750
433
|
ffmpegRunner;
|
|
@@ -775,7 +458,7 @@ var EffieRenderer = class {
|
|
|
775
458
|
"Local file paths are not allowed. Use allowLocalFiles option for trusted operations."
|
|
776
459
|
);
|
|
777
460
|
}
|
|
778
|
-
return
|
|
461
|
+
return createReadStream(fileURLToPath(src));
|
|
779
462
|
}
|
|
780
463
|
if (this.transientStore) {
|
|
781
464
|
const cachedStream = await this.transientStore.getStream(
|
|
@@ -1251,9 +934,6 @@ var EffieRenderer = class {
|
|
|
1251
934
|
export {
|
|
1252
935
|
FFmpegCommand,
|
|
1253
936
|
FFmpegRunner,
|
|
1254
|
-
ffsFetch,
|
|
1255
|
-
createTransientStore,
|
|
1256
|
-
storeKeys,
|
|
1257
937
|
EffieRenderer
|
|
1258
938
|
};
|
|
1259
|
-
//# sourceMappingURL=chunk-
|
|
939
|
+
//# sourceMappingURL=chunk-N3D6I2BD.js.map
|