Skip to content

Open source CapCut alternative.

TypeScript

fix(site): a shelf-side library copy reports as a copy

David Le7cbeaa83cad8
diff --git a/site/src/cut/components/Editor.tsx b/site/src/cut/components/Editor.tsx
index fb49a10c..e2d4f9fc 100644
--- a/site/src/cut/components/Editor.tsx
+++ b/site/src/cut/components/Editor.tsx
@@ -182,14 +182,18 @@ export function Editor({
});
const [importing, setImporting] = useState(0);
// Files being probed and named, plus the ones already placed whose bytes are
- // still going out — both are work the save indicator reports.
+ // still going out — both are work the save indicator reports. A library file
+ // copying shelf-side is reported as the copy it is.
const sending = useEditor((s) =>
- s.assets.reduce((n, a) => (a.upload && !a.upload.error ? n + 1 : n), 0)
+ s.assets.reduce((n, a) => (a.upload && !a.upload.error && !a.upload.server ? n + 1 : n), 0)
+ );
+ const copying = useEditor((s) =>
+ s.assets.reduce((n, a) => (a.upload && !a.upload.error && a.upload.server ? n + 1 : n), 0)
);
// Bytes moving into the project are work the tab should show.
useEffect(() => {
- reportActivity("import", importing + sending > 0);
- }, [importing, sending]);
+ reportActivity("import", importing + sending + copying > 0);
+ }, [importing, sending, copying]);
// Uploaded fonts become live FontFaces the moment their assets exist (and
// drop out when deleted), so titles set in them never measure a fallback.
@@ -1127,6 +1131,7 @@ export function Editor({
from={from}
folder={folder}
uploading={importing + sending}
+ copying={copying}
/>
)}
<div
diff --git a/site/src/cut/components/TopBar.tsx b/site/src/cut/components/TopBar.tsx
index 0ae23812..670a8539 100644
--- a/site/src/cut/components/TopBar.tsx
+++ b/site/src/cut/components/TopBar.tsx
@@ -52,6 +52,7 @@ export function TopBar({
from,
folder,
uploading = 0,
+ copying = 0,
}: {
onImport: (files: File[], opts?: { origin?: "recording" }) => void;
from?: string | null;
@@ -60,6 +61,9 @@ export function TopBar({
* reports them ("Uploading") — those are real network uploads, not local
* disk copies. */
uploading?: number;
+ /** Library files copying into the project on the cloud's own shelf; the
+ * bytes never touch this browser, so the indicator calls it a copy. */
+ copying?: number;
}) {
const base = useCutBase();
const back = backTarget(base, from, folder);
@@ -247,7 +251,16 @@ export function TopBar({
const canMoveToCloud = cutMode === "local" || cutMode === "browser";
// Cloud imports are real uploads worth reporting; local imports are instant
// disk copies, so they report nothing.
- const cloudUploading = uploading > 0 && cutMode === "cloud";
+ const cloudUploading = (uploading > 0 || copying > 0) && cutMode === "cloud";
+ const transferLabel =
+ uploading > 0
+ ? uploading === 1
+ ? "Uploading"
+ : `Uploading ${uploading} files`
+ : copying === 1
+ ? "Copying"
+ : `Copying ${copying} files`;
+ const finishingLabel = uploading > 0 ? "Finishing uploads…" : "Finishing copies…";
// An import whose bytes never landed is absent from the saved document, so
// its clip disappears on the next open. The Media panel shows this for a
// dropped file, but a stock or library import lives on the timeline and has
@@ -361,7 +374,7 @@ export function TopBar({
failedImports > 0
? "Retry the failed imports first"
: cloudUploading
- ? "Finishing uploads…"
+ ? finishingLabel
: compact
? "Export"
: undefined
@@ -463,7 +476,7 @@ export function TopBar({
) : cloudUploading ? (
<>
<Loader2 className="size-3 animate-spin" />{" "}
- {uploading === 1 ? "Uploading" : `Uploading ${uploading} files`}
+ {transferLabel}
</>
) : saveState === "saving" || saveState === "dirty" ? (
<>
@@ -665,7 +678,7 @@ export function TopBar({
s.setExportOpen(true);
}}
>
- <Upload /> {cloudUploading ? "Finishing uploads…" : "Export"}
+ <Upload /> {cloudUploading ? finishingLabel : "Export"}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
diff --git a/site/src/cut/lib/importQueue.ts b/site/src/cut/lib/importQueue.ts
index 8ad10714..9d6ce7f6 100644
--- a/site/src/cut/lib/importQueue.ts
+++ b/site/src/cut/lib/importQueue.ts
@@ -80,13 +80,15 @@ const storeBacked = (job: Job) => job.pending.asset.upload?.stored === true;
/** The `upload` patch for a job, keeping `stored` so a progress tick can't
* demote a store-backed asset to tab-scoped (which would strip it from the
- * saved document). `updateAsset` merges shallowly; `upload` is replaced whole. */
+ * saved document), and `server` so the indicator keeps calling a copy a copy.
+ * `updateAsset` merges shallowly; `upload` is replaced whole. */
function uploadPatch(job: Job, progress: number, error?: string) {
return {
upload: {
progress,
...(error !== undefined ? { error } : {}),
...(storeBacked(job) ? { stored: true as const } : {}),
+ ...(job.pending.asset.upload?.server ? { server: true as const } : {}),
},
};
}
diff --git a/site/src/cut/lib/library.ts b/site/src/cut/lib/library.ts
index 143b005d..c4e4dde8 100644
--- a/site/src/cut/lib/library.ts
+++ b/site/src/cut/lib/library.ts
@@ -661,6 +661,10 @@ export async function deleteFromLibrary(residency: Residency, id: string) {
if (!res.ok) throw new Error("Could not delete.");
}
+/** Whether a library file on this shelf lands in the open project by a
+ * server-side copy: the project's own backend holds both ends. */
+const sameShelf = (residency: Residency) => residency === getBackend().kind;
+
/** Land one library file in the open project and return its stored name.
*
* On the project's own shelf the server does the copy without the bytes ever
@@ -675,7 +679,7 @@ async function copyLibraryFileToProject(
opts?: { onProgress?: (fraction: number) => void; signal?: AbortSignal },
): Promise<string> {
const target = getBackend();
- if (assetId && residency === target.kind) {
+ if (assetId && sameShelf(residency)) {
const res = await target.fetch("/api/cut/library/use", {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -724,6 +728,7 @@ export async function importLibraryAsset(
duration: lib.duration,
width: lib.width,
height: lib.height,
+ server: sameShelf(lib.residency),
},
(opts) =>
copyLibraryFileToProject(
diff --git a/site/src/cut/lib/media.ts b/site/src/cut/lib/media.ts
index 4d099e1f..2fb3acf2 100644
--- a/site/src/cut/lib/media.ts
+++ b/site/src/cut/lib/media.ts
@@ -692,6 +692,9 @@ type RemoteImportInit = {
width?: number;
height?: number;
origin?: StoredAsset["origin"];
+ /** The copy runs server-side, so the save indicator reports a copy, not an
+ * upload. */
+ server?: boolean;
};
/** Copy attempts ride out transient blips before the queue marks the asset
@@ -740,7 +743,7 @@ export function importRemote(
...(init.height !== undefined ? { height: init.height } : {}),
...(init.origin ? { origin: init.origin } : {}),
url: init.url,
- upload: { progress: 0 },
+ upload: { progress: 0, ...(init.server ? { server: true } : {}) },
};
useEditor.getState().addAsset(asset);
void enrichAsset(asset);
diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.ts
index bf20bd7c..7a844668 100644
--- a/site/src/cut/lib/types.ts
+++ b/site/src/cut/lib/types.ts
@@ -247,6 +247,9 @@ export interface AssetUpload {
/** The bytes are held durably in the browser store, so the asset is safe to
* save and the upload safe to resume after a reload. */
stored?: boolean;
+ /** The bytes move server-side, shelf to project, and nothing leaves the
+ * browser: a library file landing in a project on its own shelf. */
+ server?: boolean;
}
/** Runtime asset: stored fields plus derived/browser-only data. */