Open source CapCut alternative.
TypeScript
fix(site): chat-imported media lands on the signed media origin
David Leba6a15cfd6a5
diff --git a/site/src/cut/lib/media.ts b/site/src/cut/lib/media.tsindex 1c3eca32..a4a1d329 100644--- a/site/src/cut/lib/media.ts+++ b/site/src/cut/lib/media.ts@@ -968,7 +968,16 @@ export async function assetFromProjectFile(name: string,backend: CutBackend = getBackend()): Promise<MediaAsset> {- const url = mediaUrl(projectId, fileName, backend);+ // The file lands where a dropped file lands: on this browser's own copy when+ // the store holds one, else on the signed media origin — the one origin the+ // chunk cache keeps. The route URL re-signs and redirects on every range+ // read, so a clip left on it plays through an uncached round trip per read.+ const url =+ (await localMediaUrl(projectId, fileName)) ??+ (await import("./mediaLinks")+ .then((m) => m.mintLandedUrl(projectId, fileName))+ .catch(() => null)) ??+ mediaUrl(projectId, fileName, backend);const asset: MediaAsset = {id: uid(),fileName,diff --git a/site/src/cut/lib/mediaLinks.ts b/site/src/cut/lib/mediaLinks.tsindex 0448f075..c47fb5ab 100644--- a/site/src/cut/lib/mediaLinks.ts+++ b/site/src/cut/lib/mediaLinks.ts@@ -119,12 +119,14 @@ export function refreshSignedUrls(force = false): Promise<void> {/** Mint the signed URL for one just-landed file, so an import moves straight* onto the media origin — the origin the chunk cache keeps and a playing clip- * reads from. Null when the project has no signed batch (its route URLs serve- * as they are) or the mint comes back empty; the route URL stands in and the- * scheduled machinery rotates it later. */+ * reads from. A project that loaded with no media has no batch yet; the first+ * file to land starts one, so its refresh timer runs from here on. Null when+ * the batch belongs to another project or the mint comes back empty; the+ * route URL stands in and the scheduled machinery rotates it later. */export async function mintLandedUrl(projectId: string, fileName: string): Promise<string | null> {- if (!batch || batch.projectId !== projectId) return null;+ if (batch && batch.projectId !== projectId) return null;const minted = await fetchSignedMediaUrls(projectId, [fileName]);+ if (!batch && minted.expiresAt !== null) markSignedBatch(projectId, minted.expiresAt);return minted.urls.get(fileName) ?? null;}