From 5b3fc7dffe381589a2d2e489d1871aca2e635fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mime=20=C4=8Cuvalo?= Date: Mon, 17 Jun 2024 11:58:37 +0100 Subject: [PATCH] assets: fix up videos with indexedDB (#3954) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whoops, the logic needs to check for `asset:` first before videos. ### Change Type - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff - [x] `bugfix` — Bug fix - [ ] `feature` — New feature - [ ] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know --- apps/dotcom/src/utils/assetHandler.ts | 12 ++++++------ .../tldraw/src/lib/defaultExternalContentHandlers.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/dotcom/src/utils/assetHandler.ts b/apps/dotcom/src/utils/assetHandler.ts index 83a165b0a..1e9c98569 100644 --- a/apps/dotcom/src/utils/assetHandler.ts +++ b/apps/dotcom/src/utils/assetHandler.ts @@ -15,12 +15,6 @@ export const resolveAsset = async (asset: TLAsset | null | undefined, context: AssetContextProps) => { if (!asset || !asset.props.src) return null - // We don't deal with videos at the moment. - if (asset.type === 'video') return asset.props.src - - // Assert it's an image to make TS happy. - if (asset.type !== 'image') return null - // Retrieve a local image from the DB. if (persistenceKey && asset.props.src.startsWith('asset:')) { return await objectURLCache.get( @@ -29,6 +23,12 @@ export const resolveAsset = ) } + // We don't deal with videos at the moment. + if (asset.type === 'video') return asset.props.src + + // Assert it's an image to make TS happy. + if (asset.type !== 'image') return null + // Don't try to transform data: URLs, yikes. if (!asset.props.src.startsWith('http:') && !asset.props.src.startsWith('https:')) return asset.props.src diff --git a/packages/tldraw/src/lib/defaultExternalContentHandlers.ts b/packages/tldraw/src/lib/defaultExternalContentHandlers.ts index 3c024b739..75d2c29e3 100644 --- a/packages/tldraw/src/lib/defaultExternalContentHandlers.ts +++ b/packages/tldraw/src/lib/defaultExternalContentHandlers.ts @@ -580,12 +580,6 @@ export const defaultResolveAsset = (persistenceKey?: string) => async (asset: TLAsset | null | undefined) => { if (!asset || !asset.props.src) return null - // We don't deal with videos at the moment. - if (asset.type === 'video') return asset.props.src - - // Assert it's an image to make TS happy. - if (asset.type !== 'image') return null - // Retrieve a local image from the DB. if (persistenceKey && asset.props.src.startsWith('asset:')) { return await objectURLCache.get( @@ -594,6 +588,12 @@ export const defaultResolveAsset = ) } + // We don't deal with videos at the moment. + if (asset.type === 'video') return asset.props.src + + // Assert it's an image to make TS happy. + if (asset.type !== 'image') return null + return asset.props.src }