Skip to content

Open source CapCut alternative.

TypeScript

fix(site): a media cache write survives its directory going away

David Led69d33ef7c97
diff --git a/site/src/cut/lib/mediaSync.ts b/site/src/cut/lib/mediaSync.ts
index d0f686f9..f2c185ac 100644
--- a/site/src/cut/lib/mediaSync.ts
+++ b/site/src/cut/lib/mediaSync.ts
@@ -276,7 +276,14 @@ async function cacheOne(
await makeRoom(projectId, Number(res.headers.get("content-length")) || 0);
const dir = await mediaDir(projectId, true);
if (!dir) return { go: true, url: null };
- const w = await (await dir.getFileHandle(fileName, { create: true })).createWritable();
+ // The directory can go out from under this between the two awaits — an
+ // eviction pass sweeping a copy, or the origin's store cleared from
+ // browser settings. The signed URL still serves the file either way.
+ const w = await dir
+ .getFileHandle(fileName, { create: true })
+ .then((h) => h.createWritable())
+ .catch(() => null);
+ if (!w) return { go: true, url: null };
try {
await res.body.pipeTo(w, { signal });
break;