Skip to content

Open source CapCut alternative.

TypeScript

fix(site): shared projects carry every asset playback draws

David Lec5b9671cdfc0
diff --git a/site/src/cut/server/cloud/sharedView.test.ts b/site/src/cut/server/cloud/sharedView.test.ts
index 575cfc40..382e1845 100644
--- a/site/src/cut/server/cloud/sharedView.test.ts
+++ b/site/src/cut/server/cloud/sharedView.test.ts
@@ -48,4 +48,51 @@ describe("filterDocForShare", () => {
expect(filterDocForShare(withRenders, features({ chat: true })).renders?.length).toBe(1);
expect(filterDocForShare(withRenders, features({ media: true })).renders).toBeUndefined();
});
+
+ test("what playback draws travels with the clip that uses it", () => {
+ const playback = {
+ ...doc,
+ assets: [
+ ...doc.assets,
+ { id: "m1", fileName: "m1.mp4", type: "video", duration: 1, origin: "matte" },
+ { id: "fill", fileName: "fill.png", type: "image", duration: 0 },
+ { id: "sticker", fileName: "s.png", type: "image", duration: 0, origin: "cutout" },
+ { id: "font1", fileName: "f.ttf", type: "font", duration: 0 },
+ ],
+ clips: [
+ {
+ ...(doc.clips[0] as object),
+ removal: {
+ mode: "auto",
+ matte: { assetId: "m1", fingerprint: "fp", quality: "local", in: 0 },
+ backdrop: { kind: "image", assetId: "fill" },
+ },
+ },
+ ],
+ overlays: [
+ { id: "o1", kind: "sticker", assetId: "sticker", start: 0, end: 1, x: 0, y: 0, w: 0.2 },
+ { id: "o2", kind: "text", text: "hi", font: "asset:font1", start: 0, end: 1, x: 0, y: 0 },
+ ],
+ } as unknown as ProjectDoc;
+ expect(ids(filterDocForShare(playback, features()))).toEqual([
+ "fill",
+ "font1",
+ "m1",
+ "placed",
+ "sticker",
+ ]);
+ });
+
+ test("a caption font travels only when subtitles are shared", () => {
+ const captioned = {
+ ...doc,
+ assets: [...doc.assets, { id: "font1", fileName: "f.ttf", type: "font", duration: 0 }],
+ subtitles: { cues: [], font: "asset:font1" },
+ } as unknown as ProjectDoc;
+ expect(ids(filterDocForShare(captioned, features({ subtitles: true })))).toEqual([
+ "font1",
+ "placed",
+ ]);
+ expect(ids(filterDocForShare(captioned, features()))).toEqual(["placed"]);
+ });
});
diff --git a/site/src/cut/server/cloud/sharedView.ts b/site/src/cut/server/cloud/sharedView.ts
index badac1fd..3ece086c 100644
--- a/site/src/cut/server/cloud/sharedView.ts
+++ b/site/src/cut/server/cloud/sharedView.ts
@@ -4,7 +4,7 @@
// the content boundary: the filtered doc and the media allowlist are what
// decide which bytes a viewer can reach; the client's tab hiding is
// presentation only. Copying a share lives in copyQueue.ts.
-import type { ProjectDoc, StoredAsset } from "@/cut/lib/types";
+import { uploadedFontId, type ProjectDoc, type StoredAsset } from "@/cut/lib/types";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { readLadder } from "./ladderStore";
@@ -76,18 +76,33 @@ async function offeredFeatures(view: ShareView): Promise<ShareFeatures> {
return threads > 0 ? view.features : { ...view.features, chat: false };
}
-/** The asset set a viewer may see: everything playback needs (referenced by a
- * clip), plus each optional surface's assets when that surface is shared.
- * Untagged assets belong to the Media panel; origin-tagged ones to the
- * generate panels; chat-tagged ones to chat. The Library is never shared. */
+/** The asset set a viewer may see: everything playback needs, plus each
+ * optional surface's assets when that surface is shared. Playback references
+ * more than the clips' own sources: a removal's baked matte and fill image,
+ * sticker overlays' pictures, and uploaded fonts on text overlays and shared
+ * captions all draw into the frame, so each rides along with the clip that
+ * uses it. Untagged assets belong to the Media panel; origin-tagged ones to
+ * the generate panels; chat-tagged ones to chat. The Library is never
+ * shared. */
function allowedAssets(doc: ProjectDoc, features: ShareFeatures): StoredAsset[] {
const assets = Array.isArray(doc.assets) ? doc.assets : [];
+ const clips = Array.isArray(doc.clips) ? doc.clips : [];
const referenced = new Set<string>([
- ...(Array.isArray(doc.clips) ? doc.clips : []).map((c) => c.assetId),
+ ...clips.map((c) => c.assetId),
...(Array.isArray(doc.audioClips) ? doc.audioClips : []).map((c) => c.assetId),
]);
+ for (const c of clips) {
+ if (c.removal?.matte) referenced.add(c.removal.matte.assetId);
+ if (c.removal?.backdrop?.assetId) referenced.add(c.removal.backdrop.assetId);
+ }
+ const fonts = new Set<string>();
+ for (const o of Array.isArray(doc.overlays) ? doc.overlays : []) {
+ if (o.kind === "sticker" && o.assetId) referenced.add(o.assetId);
+ if (o.kind === "text") fonts.add(o.font);
+ }
+ if (features.subtitles && doc.subtitles?.font) fonts.add(doc.subtitles.font);
return assets.filter((a) => {
- if (referenced.has(a.id)) return true;
+ if (referenced.has(a.id) || fonts.has(uploadedFontId(a.id))) return true;
if (a.chatId) return features.chat;
if (a.origin) return features.genai;
return features.media;