Open source CapCut alternative.
TypeScript
fix(site): stored assets share one address resolver that heals dead blob URLs [rebuild]
David Le3ed1d1fa03de
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.mdindex eb8bf819..15ec440d 100644--- a/docs/guides/cut/README.md+++ b/docs/guides/cut/README.md@@ -104,7 +104,7 @@ Some of what the Library holds is lent. Most items are copied when they are usedCloud projects store their doc in Postgres (versioned; a stale autosave 409s and the editor reloads the newer copy) and media in R2: uploads go direct from the browser on presigned URLs (the hosted functions never see the bytes), playback streams on signed range URLs, and a flat per-user quota is enforced at presign time. That quota is visible rather than implicit: a free account editing a cloud project sees what it has used in the editor's top bar, and a presign rejected for space opens an upgrade offer wherever it happened instead of a bare error. The same slot carries the countdown when a subscription is set to cancel, and clicking it opens the billing portal.-A dropped file does not wait for that upload. Because a presign claims the stored name before any bytes move, and the browser can read the file it was handed, an import is measured, named, and placed on the timeline in the same moment it is dropped — playing from the local copy, filmstrip and all — while the bytes go out behind the editor. When this browser can hold a store, the dropped bytes are written into origin-private storage under the claimed name and pinned: the document references the asset at once, a tab closed mid-upload resumes the upload on the next open, and once the cloud confirms the object the pin clears and the local file becomes a read cache. A tab-scoped import — a browser with no store — keeps itself honest through the saved document instead: the import stays out of it, along with the clips that use it, until the upload lands, so a tab closed mid-upload leaves nothing to reopen broken. Export waits on the same line, since a render reads the saved document.+A dropped file does not wait for that upload. Because a presign claims the stored name before any bytes move, and the browser can read the file it was handed, an import is measured, named, and placed on the timeline in the same moment it is dropped — playing from the local copy, filmstrip and all — while the bytes go out behind the editor. When this browser can hold a store, the dropped bytes are written into origin-private storage under the claimed name and pinned: the document references the asset at once, a tab closed mid-upload resumes the upload on the next open, and once the cloud confirms the object the pin clears and the local file becomes a read cache. A tab-scoped import — a browser with no store — keeps itself honest through the saved document instead: the import stays out of it, along with the clips that use it, until the upload lands, so a tab closed mid-upload leaves nothing to reopen broken. Export waits on the same line, since a render reads the saved document. Every asset that lands at rest — a drop, a generation, a freeze frame, a conversion, a template copy — takes its address from one resolver: this browser's own copy when the store holds one, else a signed link on the media origin, else the route URL. A blob URL that fails to read mid-session is re-resolved through the same resolver and the store swap repoints every reader, so a new kind of asset inherits both the address and the healing.The cache runs the other way too: opening a cloud project pulls in the assets this browser is missing, nearest timeline use first. Video caches as fixed-size chunks keyed to the stored object: playback serves the pieces it holds from disk and fetches the rest as byte ranges, so scrubbing warms the exact regions being worked, a half-fetched file keeps every chunk that landed, and the cache carries across the hourly re-signing of media links. Images and audio stream in whole and swap onto local bytes as they land. When the origin's storage quota runs short, chunked video goes first — a lost chunk costs one ranged re-fetch — then the least recently opened projects' whole-file caches; pinned uploads and browser-resident projects are never evicted.diff --git a/site/src/cut/components/SidePanel.tsx b/site/src/cut/components/SidePanel.tsxindex 31a14af5..16c93adc 100644--- a/site/src/cut/components/SidePanel.tsx+++ b/site/src/cut/components/SidePanel.tsx@@ -818,7 +818,7 @@ function ProjectFilesPanel({mediaSrc={(f) => mediaUrl(projectId, f)}drag={{ scope: "project", template: t }}addTitle="Add to timeline"- onAdd={() => addProjectTemplateToTimeline(projectId, t)}+ onAdd={() => void addProjectTemplateToTimeline(projectId, t)}onRename={(name) => useEditor.getState().renameTemplate(t.id, name)}onDelete={() => useEditor.getState().removeTemplate(t.id)}onRefDrop={(r) => {diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsxindex 9dc6cf82..39b97f7f 100644--- a/site/src/cut/components/Timeline.tsx+++ b/site/src/cut/components/Timeline.tsx@@ -2074,7 +2074,7 @@ export function Timeline() {}if (tpl && projectId) {e.preventDefault();- if (tpl.scope === "project") addProjectTemplateToTimeline(projectId, tpl.template, t);+ if (tpl.scope === "project") void addProjectTemplateToTimeline(projectId, tpl.template, t);else void addTemplateToProject(projectId, tpl.template, t).catch(() => {});return;}diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 091c3e92..105326d1 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -105,6 +105,7 @@ import { blobToInlineAudio, refToInlineAudio, visualRefs, type InlineImage } froimport { characterPrompt, stockAspectDims, stockTitle } from "./stock";import { STOCK_IMAGES } from "./stockManifest";import { STOCK_VIDEOS } from "./stockVideoManifest";+import { storedMediaUrl } from "./mediaSync";import { applyOverlayPatchSettled, track0Clips, laneGapAt, getClipSpans, nextFreeStart, overlayLaneOrder, overlayLayers, parkedTransitions, projectDuration, resolveTransitions, totalDuration, useEditor } from "./store";import { playheadAt } from "./playhead";import { renderProjectFrame } from "./exportRender";@@ -160,7 +161,6 @@ import {isTextOverlay,LAYOUTS,MAX_SUBTITLE_LANES,- mediaUrl,nearestAspect,normalizeAspect,overlayAnimStyle,@@ -2269,7 +2269,11 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {if (!res.ok) throw new ToolError(made.error ?? "Could not render the freeze frame.");body = made;}- const asset: MediaAsset = { ...body, url: mediaUrl(projectId, body.fileName), origin: "freeze" };+ const asset: MediaAsset = {+ ...body,+ url: await storedMediaUrl(projectId, body.fileName),+ origin: "freeze",+ };const cur = useEditor.getState();cur.addAsset(asset);cur.addClipFromAsset(asset.id); // lands at the end, selected@@ -2851,7 +2855,7 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {const chatId = chatOwner();const before = new Set(s.assets.map((a) => a.id));if (shelved) await addTemplateToProject(projectId, shelved);- else addProjectTemplateToTimeline(projectId, t);+ else await addProjectTemplateToTimeline(projectId, t);// Chat-fetched media files under the asking thread, like stock/library// imports; the template's clips reference it, so it survives cleanup.for (const a of useEditor.getState().assets) {diff --git a/site/src/cut/lib/backend/browser/registry.test.ts b/site/src/cut/lib/backend/browser/registry.test.tsindex cae9c252..be4005a0 100644--- a/site/src/cut/lib/backend/browser/registry.test.ts+++ b/site/src/cut/lib/backend/browser/registry.test.ts@@ -1,6 +1,7 @@import { describe, expect, test } from "bun:test";import {cancelRevoke,+ forgetRegistered,holdRegistered,registerBlobFile,registeredUrl,@@ -65,6 +66,19 @@ describe("blob-URL registry", () => {expect(registeredUrl(path)).toBe(null);});+ test("forgetting a path lands through a hold and frees it for a fresh mint", () => {+ const path = "/api/cut/projects/p6/media/a.mp4";+ const url = registerBlobFile(path, file("a.mp4"));+ holdRegistered("/api/cut/projects/p6/");+ forgetRegistered(path);+ expect(registeredUrl(path)).toBe(null);+ expect(resolveRegisteredBlob(url)).toBe(null);+ const again = registerBlobFile(path, file("a.mp4"));+ expect(again).not.toBe(url);+ releaseRegistered("/api/cut/projects/p6/");+ revokeRegistered(path);+ });+test("unregistered lookups answer null", () => {expect(registeredUrl("/api/cut/projects/none/media/x.mp4")).toBe(null);expect(resolveRegisteredBlob("blob:nothing")).toBe(null);diff --git a/site/src/cut/lib/backend/browser/registry.ts b/site/src/cut/lib/backend/browser/registry.tsindex ccd34755..5cb0a566 100644--- a/site/src/cut/lib/backend/browser/registry.ts+++ b/site/src/cut/lib/backend/browser/registry.ts@@ -82,6 +82,17 @@ function sweep(prefix: string): void {}}+/** Forget one registration now. Its blob URL failed to read — the File behind+ * it no longer serves anything, held or not — so the next ask for the path+ * mints afresh from what the store holds. */+export function forgetRegistered(path: string): void {+ const entry = byPath.get(path);+ if (!entry) return;+ byPath.delete(path);+ byUrl.delete(entry.url);+ URL.revokeObjectURL(entry.url);+}+/** A subtree coming back into use (its project re-opened while a hold kept it* alive): a revoke still waiting on it no longer applies. */export function cancelRevoke(prefix: string): void {diff --git a/site/src/cut/lib/genvideo/docWriter.ts b/site/src/cut/lib/genvideo/docWriter.tsindex c759c370..03492791 100644--- a/site/src/cut/lib/genvideo/docWriter.ts+++ b/site/src/cut/lib/genvideo/docWriter.ts@@ -15,9 +15,10 @@*/import { apiJson, getBackend, type CutBackend } from "../backend";+import { storedMediaUrl } from "../mediaSync";import { projectBackend } from "../residency";import { footprints, nextFreeStart, placeInRun, RENDERS_CAP, storedAssets, useEditor } from "../store";-import { mediaUrl, SPEED_MIN } from "../types";+import { SPEED_MIN } from "../types";import type { AudioClip, MediaAsset, ProjectDoc, RenderRecord, VideoClip } from "../types";import { fillSlot } from "./fillSlot";@@ -147,7 +148,9 @@ export async function findRunAsset(const doc = await apiJson<ProjectDoc>(res);if (!res.ok) return undefined;const stored = doc.assets.find((a) => a.id === assetId);- return stored ? { ...stored, url: mediaUrl(projectId, stored.fileName, backend) } : undefined;+ return stored+ ? { ...stored, url: await storedMediaUrl(projectId, stored.fileName, backend) }+ : undefined;}/** placeGenClip against a doc: fill a [startSec, endSec)-sized slot on track 0,diff --git a/site/src/cut/lib/importQueue.ts b/site/src/cut/lib/importQueue.tsindex ea966ca9..8ad10714 100644--- a/site/src/cut/lib/importQueue.ts+++ b/site/src/cut/lib/importQueue.ts@@ -21,9 +21,8 @@import { getBackend, type CutBackend } from "./backend";import { resolveRegisteredBlob } from "./backend/browser/registry";import type { PendingImport } from "./media";-import { localMediaUrl } from "./mediaSync";+import { storedMediaUrl } from "./mediaSync";import { useEditor } from "./store";-import { mediaUrl } from "./types";/** Blob URLs owned by the browser store's registry stay alive for the whole* session; only tab-scoped object URLs are this queue's to revoke. */@@ -184,20 +183,11 @@ async function run(job: Job) {jobs.delete(asset.id);// The stored file takes over from the source bytes, under the name the// copy resolved to (a dropped file reserved it up front; a remote import- // learns it here). When the browser store holds the bytes the asset keeps- // playing from disk. Otherwise it lands on the media origin in one move:- // the signed URL is minted before the swap, because the route URL- // re-signs and redirects on every range read and sits on no origin the- // chunk cache keeps, and each move repoints every reader on the asset.- // Filmstrips are self-contained frames and survive the swap; a still's- // single "frame" is the source itself, so it repoints with the asset.- const local = await localMediaUrl(job.projectId, fileName);- const url =- local ??- (await import("./mediaLinks")- .then((m) => m.mintLandedUrl(job.projectId, fileName))- .catch(() => null)) ??- mediaUrl(job.projectId, fileName);+ // learns it here), at the address every stored file plays from. Each move+ // repoints every reader on the asset. Filmstrips are self-contained frames+ // and survive the swap; a still's single "frame" is the source itself, so+ // it repoints with the asset.+ const url = await storedMediaUrl(job.projectId, fileName, job.backend);// The stored copy is the same bytes at a new key: what this session// already read under the source's key — the play so far, the waveform and// filmstrip decodes — carries over before anything opens the new address,diff --git a/site/src/cut/lib/library.ts b/site/src/cut/lib/library.tsindex e9b416ee..08884c7e 100644--- a/site/src/cut/lib/library.ts+++ b/site/src/cut/lib/library.ts@@ -26,6 +26,7 @@ import {listedResidencies,type Residency,} from "./residency";+import { storedMediaUrl } from "./mediaSync";import { useEditor } from "./store";import { playheadAt } from "./playhead";import type {@@ -930,12 +931,13 @@ export async function addTemplateToProject(at?: number,): Promise<void> {const media = await copyTemplateMediaToProject(projectId, template);+ const urls = await Promise.all(media.map((m) => storedMediaUrl(projectId, m.fileName)));const s = useEditor.getState();// Each copied media file (in template.media order) becomes a project asset;// the layer/audio media indices resolve against this array. Enrichment gives// the new clips their filmstrip thumbnails and waveform peaks.- const assetIds = media.map((m) => {+ const assetIds = media.map((m, i) => {const asset: MediaAsset = {id: crypto.randomUUID().slice(0, 8),fileName: m.fileName,@@ -944,7 +946,7 @@ export async function addTemplateToProject(duration: m.duration,width: m.width,height: m.height,- url: mediaUrl(projectId, m.fileName),+ url: urls[i],};s.addAsset(asset);void enrichAsset(asset);@@ -975,13 +977,20 @@ export async function importTemplateToProject(/** Materialize a project template onto the timeline at the playhead. Its media* already live in the project; assets are matched by file name and re-registered* if the Media entry was removed. */-export function addProjectTemplateToTimeline(+export async function addProjectTemplateToTimeline(projectId: string,template: LibraryTemplate,at?: number,) {+ const urls = await Promise.all(+ template.media.map((m) =>+ useEditor.getState().assets.some((a) => a.fileName === m.fileName)+ ? null+ : storedMediaUrl(projectId, m.fileName)+ )+ );const s = useEditor.getState();- const assetIds = template.media.map((m) => {+ const assetIds = template.media.map((m, i) => {const existing = s.assets.find((a) => a.fileName === m.fileName);if (existing) return existing.id;const asset: MediaAsset = {@@ -992,7 +1001,7 @@ export function addProjectTemplateToTimeline(duration: m.duration,width: m.width,height: m.height,- url: mediaUrl(projectId, m.fileName),+ url: urls[i] ?? mediaUrl(projectId, m.fileName),};s.addAsset(asset);void enrichAsset(asset);diff --git a/site/src/cut/lib/media.ts b/site/src/cut/lib/media.tsindex a4a1d329..c046e082 100644--- a/site/src/cut/lib/media.ts+++ b/site/src/cut/lib/media.ts@@ -32,6 +32,7 @@ import {renameLocalMedia,stashCloudMedia,stashUnclaimedMedia,+ storedMediaUrl,} from "./mediaSync";import {createRasterCanvas,@@ -323,10 +324,10 @@ export async function uploadProjectImage(if (!res.ok || !body.fileName) {throw new Error(quotaErrorMessage(res.status, body) ?? body.error ?? failMessage);}- return { ...body, url: mediaUrl(projectId, body.fileName, backend) };+ return { ...body, url: await storedMediaUrl(projectId, body.fileName, backend) };}const stored = await uploadProjectMediaTo(backend, projectId, file, fileName);- const url = mediaUrl(projectId, stored, backend);+ const url = await storedMediaUrl(projectId, stored, backend);const dims = await loadImageMeta(url);return {id: uid(),@@ -968,16 +969,7 @@ export async function assetFromProjectFile(name: string,backend: CutBackend = getBackend()): Promise<MediaAsset> {- // 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 url = await storedMediaUrl(projectId, fileName, backend);const asset: MediaAsset = {id: uid(),fileName,diff --git a/site/src/cut/lib/mediaConvert.ts b/site/src/cut/lib/mediaConvert.tsindex c7139d94..d9c02d4b 100644--- a/site/src/cut/lib/mediaConvert.ts+++ b/site/src/cut/lib/mediaConvert.ts@@ -45,6 +45,7 @@ import { getBackend, hasLocalCompute, type CutBackend } from "./backend";import { resolveRegisteredBlob } from "./backend/browser/registry";import { pollCloudJob } from "./cloudJob";import { enrichAsset, uploadProjectMediaTo } from "./media";+import { storedMediaUrl } from "./mediaSync";import {audioTrackOf,hasUndecodableVideo,@@ -54,7 +55,7 @@ import {withMedia,} from "./mediaRead";import { useEditor } from "./store";-import { mediaUrl, type MediaAsset } from "./types";+import type { MediaAsset } from "./types";/** One file in a project, as the converter addresses it. */export interface ConvertSource {@@ -173,7 +174,7 @@ export async function convertAssetToMp4(const patch: Partial<MediaAsset> = {fileName: made.fileName,name: mp4DisplayName(asset.name),- url: mediaUrl(projectId, made.fileName, backend),+ url: await storedMediaUrl(projectId, made.fileName, backend),duration: made.duration,...(made.width !== undefined ? { width: made.width } : {}),...(made.height !== undefined ? { height: made.height } : {}),diff --git a/site/src/cut/lib/mediaLinks.ts b/site/src/cut/lib/mediaLinks.tsindex c47fb5ab..1836c077 100644--- a/site/src/cut/lib/mediaLinks.ts+++ b/site/src/cut/lib/mediaLinks.ts@@ -130,6 +130,63 @@ export async function mintLandedUrl(projectId: string, fileName: string): Promisreturn minted.urls.get(fileName) ?? null;}+const healingBlobs = new Set<string>();+const blobHealedAt = new Map<string, number>();++/** A blob URL the browser store minted failed to read. The URL was revoked+ * under its readers, or the stored file it snapshots was rewritten or removed+ * — either way every element and decoder on it is dead until the asset moves.+ * Re-mint from the store's copy; when the store has none, or the fresh mint+ * failed just as fast, move the asset onto a signed URL. The store swap+ * repoints every reader. */+export async function healBlobUrl(src: string): Promise<void> {+ if (healingBlobs.has(src)) return;+ healingBlobs.add(src);+ try {+ const { useEditor } = await import("./store");+ const s = useEditor.getState();+ const projectId = s.projectId;+ if (!s.loaded || !projectId) return;+ // A tab-scoped upload plays from bytes only this tab holds: nothing to+ // re-mint from. A store-backed one has its file in the browser store.+ const dead = s.assets.filter((a) => a.url === src && (!a.upload || a.upload.stored));+ if (dead.length === 0) return;+ const { forgetLocalMediaUrl, localMediaUrl, storedMediaUrl } = await import("./mediaSync");+ const urls = new Map<string, string>();+ const uploading = new Map<string, string>();+ for (const a of dead) {+ // A fresh mint that died just as fast means the stored file itself no+ // longer reads: leave it forgotten and resolve past it.+ const healedAt = blobHealedAt.get(a.fileName) ?? 0;+ if (Date.now() - healedAt > ATTEMPT_RESET_MS) forgetLocalMediaUrl(projectId, a.fileName);+ blobHealedAt.set(a.fileName, Date.now());+ if (a.upload) {+ // The object hasn't landed, so no signed URL would answer for it; the+ // store copy is the only address, and the upload's own swap follows+ // when the bytes arrive.+ const local = await localMediaUrl(projectId, a.fileName);+ if (local && local !== src) uploading.set(a.id, local);+ continue;+ }+ urls.set(a.fileName, await storedMediaUrl(projectId, a.fileName));+ }+ const st = useEditor.getState();+ if (st.projectId !== projectId || !st.loaded) return;+ console.debug(+ `[cut-media] blob re-mint: ${urls.size + uploading.size} url(s) moved after a failed read`+ );+ if (urls.size > 0) st.applyMediaUrls(urls);+ for (const [id, url] of uploading) {+ const a = st.assets.find((x) => x.id === id);+ if (!a) continue;+ const thumbs = a.type === "image" && a.thumbs?.every((t) => t === src) ? [url] : a.thumbs;+ st.updateAsset(id, { url, ...(thumbs !== a.thumbs ? { thumbs } : {}) });+ }+ } finally {+ healingBlobs.delete(src);+ }+}+/** A URL whose access expires and can be re-minted: an edge media token* (`?e=<expiry>&s=<signature>`). It heals by re-minting the batch; anything* else does not. */@@ -168,7 +225,11 @@ function retryElement(el: HTMLImageElement | HTMLMediaElement, src: string, atte* expired, and only a re-mint heals that. The store swap moves the pool's* source onto the new URL, which is what gets reads going again. */export function reportMediaUrlError(src: string) {- if (!src || src.startsWith("blob:") || src.startsWith("data:")) return;+ if (!src || src.startsWith("data:")) return;+ if (src.startsWith("blob:")) {+ void healBlobUrl(src);+ return;+ }if (!isExpiringUrl(src)) return;if (Date.now() - lastForcedAt < FORCED_GAP_MS) return;lastForcedAt = Date.now();@@ -185,7 +246,13 @@ export function reportMediaUrlError(src: string) {* element on screen until the tab is reloaded. */export function reportMediaElementError(el: HTMLImageElement | HTMLMediaElement) {const src = el instanceof HTMLImageElement ? el.src : el.currentSrc || el.src;- if (!src || src.startsWith("blob:") || src.startsWith("data:")) return;+ if (!src || src.startsWith("data:")) return;+ if (src.startsWith("blob:")) {+ // No element reload: a dead blob URL stays dead. The store swap is what+ // repoints the element, through the asset it renders.+ void healBlobUrl(src);+ return;+ }const expiring = isExpiringUrl(src);if (expiring && Date.now() - lastForcedAt >= FORCED_GAP_MS) {lastForcedAt = Date.now();diff --git a/site/src/cut/lib/mediaSync.ts b/site/src/cut/lib/mediaSync.tsindex f2c185ac..b3ec7cc6 100644--- a/site/src/cut/lib/mediaSync.ts+++ b/site/src/cut/lib/mediaSync.ts@@ -37,9 +37,15 @@ import {writeFileAt,type PendingUpload,} from "./backend/browser/opfs";-import { registerBlobFile, registeredUrl, revokeRegistered } from "./backend/browser/registry";+import {+ forgetRegistered,+ registerBlobFile,+ registeredUrl,+ revokeRegistered,+} from "./backend/browser/registry";+import { getBackend, type CutBackend } from "./backend";import { dropChunksMatching, evictChunkBytes, prefetchChunks } from "./chunkCache";-import type { AssetType } from "./types";+import { mediaUrl, type AssetType } from "./types";const mediaPath = (projectId: string, fileName: string) =>`/api/cut/projects/${projectId}/media/${encodeURIComponent(fileName)}`;@@ -167,6 +173,35 @@ export async function localMediaUrl(projectId: string, fileName: string): Promisreturn file ? registerBlobFile(path, file) : null;}+/** Forget the blob URL minted for a stored file. It failed to read, so the+ * next resolve mints afresh from the file the store holds now. */+export function forgetLocalMediaUrl(projectId: string, fileName: string): void {+ forgetRegistered(mediaPath(projectId, fileName));+}++/** Where an asset plays a stored project file from, best address first: this+ * browser's own copy, a signed link on the media origin (the one origin the+ * chunk cache keeps), then the route URL, which re-signs and redirects on+ * every read. Every asset that lands at rest — a drop, a generation, a freeze,+ * a conversion, a template copy — is stamped through here, and a blob URL that+ * failed to read is re-resolved through here, so a new kind of asset inherits+ * the same address and the same healing. The engine serves its files itself. */+export async function storedMediaUrl(+ projectId: string,+ fileName: string,+ backend: CutBackend = getBackend()+): Promise<string> {+ if (backend.kind !== "local") {+ const local = await localMediaUrl(projectId, fileName);+ if (local) return local;+ const signed = await import("./mediaLinks")+ .then((m) => m.mintLandedUrl(projectId, fileName))+ .catch(() => null);+ if (signed) return signed;+ }+ return mediaUrl(projectId, fileName, backend);+}+/** A media delete's local half: the file, its chunks, its blob URL, its pin. */export async function dropLocalMedia(projectId: string, fileName: string): Promise<void> {if (!supportsBrowserStore()) return;diff --git a/site/src/cut/lib/stickerCreate.ts b/site/src/cut/lib/stickerCreate.tsindex 1e4b77d8..421a1469 100644--- a/site/src/cut/lib/stickerCreate.ts+++ b/site/src/cut/lib/stickerCreate.ts@@ -12,7 +12,7 @@ import { bytesFromBase64 } from "./bytes";import { makeStickerCutout } from "./cutout";import { promptAndImages } from "./generate";import { hostedPost } from "./hosted";-import { uploadProjectImage } from "./media";+import { enrichAsset, uploadProjectImage } from "./media";import { useEditor } from "./store";import { mediaSlug, type MediaAsset } from "./types";@@ -76,5 +76,6 @@ export async function createCustomSticker(origin: "sticker",});useEditor.getState().addAsset(asset);+ void enrichAsset(asset);return asset;}diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex e7f0d938..bc9bd9b2 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -2245,7 +2245,13 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {// links that expire.if (a.upload || resolveRegisteredBlob(a.url)) return a;const url = urls.get(a.fileName);- return url && url !== a.url ? { ...a, url } : a;+ if (!url || url === a.url) return a;+ // A still's filmstrip is its source URL, so it moves with it.+ const thumbs =+ a.type === "image" && a.thumbs?.length && a.thumbs.every((t) => t === a.url)+ ? [url]+ : a.thumbs;+ return { ...a, url, ...(thumbs !== a.thumbs ? { thumbs } : {}) };}),}));} finally {