diff --git a/src/client/multiplayerAssetStore.tsx b/src/client/multiplayerAssetStore.tsx index 070ec7c..d2c8b4c 100644 --- a/src/client/multiplayerAssetStore.tsx +++ b/src/client/multiplayerAssetStore.tsx @@ -1,17 +1,12 @@ import { TLAssetStore, uniqueId } from 'tldraw' +import { WORKER_URL } from '../components/Board' -const WORKER_URL = process.env.TLDRAW_WORKER_URL - -// How does our server handle assets like images and videos? export const multiplayerAssetStore: TLAssetStore = { - // to upload an asset, we... async upload(_asset, file) { - // ...create a unique name & URL... const id = uniqueId() const objectName = `${id}-${file.name}`.replace(/[^a-zA-Z0-9.]/g, '-') const url = `${WORKER_URL}/uploads/${objectName}` - // ...POST it to out worker to upload it... const response = await fetch(url, { method: 'POST', body: file, @@ -21,12 +16,9 @@ export const multiplayerAssetStore: TLAssetStore = { throw new Error(`Failed to upload asset: ${response.statusText}`) } - // ...and return the URL to be stored with the asset record. return url }, - // to retrieve an asset, we can just use the same URL. you could customize this to add extra - // auth, or to serve optimized versions / sizes of the asset. resolve(asset) { return asset.props.src }, diff --git a/src/components/Board.tsx b/src/components/Board.tsx index 4408973..bd1334e 100644 --- a/src/components/Board.tsx +++ b/src/components/Board.tsx @@ -26,7 +26,7 @@ import { components, uiOverrides } from '@/ui-overrides' import { useCameraControls } from '@/hooks/useCameraControls' //const WORKER_URL = `https://jeffemmett-canvas.jeffemmett.workers.dev` -export const WORKER_URL = 'https://jeffemmett-canvas.jeffemmett.workers.dev'; +export const WORKER_URL = import.meta.env.VITE_TLDRAW_WORKER_URL || 'https://jeffemmett-canvas.jeffemmett.workers.dev'; const shapeUtils = [ChatBoxShape, VideoChatShape, EmbedShape] const tools = [ChatBoxTool, VideoChatTool, EmbedTool]; // Array of tools diff --git a/vite.config.ts b/vite.config.ts index ba7d3f4..516221a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,9 @@ import { viteStaticCopy } from 'vite-plugin-static-copy'; export default defineConfig({ define: { - 'process.env.TLDRAW_WORKER_URL': JSON.stringify(process.env.TLDRAW_WORKER_URL || 'https://jeffemmett-canvas.jeffemmett.workers.dev') + 'process.env.TLDRAW_WORKER_URL': JSON.stringify( + process.env.VITE_TLDRAW_WORKER_URL || 'https://jeffemmett-canvas.jeffemmett.workers.dev' + ) }, plugins: [ react(),