Open source CapCut alternative.
TypeScript
fix(site): upload each export overlay with the type its URL was signed for
David Le6b0c4a506daa
diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.tsindex 049df3b0..9dc4045e 100644--- a/site/src/cut/lib/exportClient.ts+++ b/site/src/cut/lib/exportClient.ts@@ -541,7 +541,8 @@ async function postExport(files: payload.pngs.map((p) => ({ name: p.name, bytes: p.blob.size })),}),});- const preBody = await apiJson<{ files?: { name: string; key: string; url: string }[] }>(pre);+ const preBody =+ await apiJson<{ files?: { name: string; key: string; type?: string; url: string }[] }>(pre);if (!pre.ok || !preBody.files) {throw new Error(quotaErrorMessage(pre.status, preBody) ?? preBody.error ?? "Export failed to start."@@ -552,7 +553,10 @@ async function postExport(payload.pngs.map(async (p) => {const target = byName.get(p.name);if (!target) throw new Error("Export failed to start.");- await putSigned(target.url, p.blob, p.blob.type || "image/png");+ // The content type the URL was signed with, not the blob's: they agree+ // for the PNG frames and differ for the behind-speaker mask clip, and+ // sending anything but the signed one fails the signature.+ await putSigned(target.url, p.blob, target.type || "image/png");}));for (const p of payload.pngs) overlays.push({ name: p.name, key: byName.get(p.name)!.key });diff --git a/site/src/cut/server/cloud/jobs.ts b/site/src/cut/server/cloud/jobs.tsindex 568f4601..35f6b4e7 100644--- a/site/src/cut/server/cloud/jobs.ts+++ b/site/src/cut/server/cloud/jobs.ts@@ -77,8 +77,13 @@ async function exportName(}export const jobsCloud = {- /** Presign overlay-PNG uploads for an export. Overlays are transient worker- * inputs — no CutMediaObject bookkeeping, no quota. */+ /** Presign the overlay uploads for an export — stamped title and effect+ * frames, and the behind-speaker mask clip. Transient worker inputs: no+ * CutMediaObject bookkeeping, no quota.+ *+ * The content type is part of a presigned PUT's signature, so the answer+ * carries the one that was signed and the uploader sends it back verbatim.+ * Anything else is a 403 at R2. */async exportPresign(userId: string, req: Request) {try {const { files } = (await req.json()) as { files?: { name?: string; bytes?: number }[] };@@ -89,7 +94,8 @@ export const jobsCloud = {const name = String(f.name ?? "").replace(/[/\\]/g, "");if (!name) throw new Error("Every overlay needs a name.");const key = overlayKey(userId, batchId, name);- return { name, key, url: await presignPut(key, "image/png") };+ const type = name.toLowerCase().endsWith(".mp4") ? "video/mp4" : "image/png";+ return { name, key, type, url: await presignPut(key, type) };}));return Response.json({ files: out });