-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate-snapshot.ts
More file actions
29 lines (23 loc) · 1016 Bytes
/
create-snapshot.ts
File metadata and controls
29 lines (23 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { put } from "@vercel/blob";
import { addBundleToSandbox, createSandbox } from "@remotion/vercel";
import { bundleRemotionProject } from "./src/app/api/render/helpers";
const getSnapshotBlobKey = () =>
`snapshot-cache/${process.env.VERCEL_DEPLOYMENT_ID ?? "local"}.json`;
const sandbox = await createSandbox({
onProgress: ({ progress, message }) => {
const pct = Math.round(progress * 100);
console.log(`[create-snapshot] ${message} (${pct}%)`);
},
});
console.log("[create-snapshot] Adding Remotion bundle...");
bundleRemotionProject(".remotion");
await addBundleToSandbox({ sandbox, bundleDir: ".remotion" });
console.log("[create-snapshot] Taking snapshot...");
const snapshot = await sandbox.snapshot({ expiration: 0 });
const { snapshotId } = snapshot;
await put(getSnapshotBlobKey(), JSON.stringify({ snapshotId }), {
access: "public",
contentType: "application/json",
addRandomSuffix: false,
});
console.log(`[create-snapshot] Snapshot saved: ${snapshotId} (never expires)`);