fix vite and asset upload
This commit is contained in:
parent
d555910c77
commit
1cd7208ddf
|
|
@ -1,17 +1,12 @@
|
||||||
import { TLAssetStore, uniqueId } from 'tldraw'
|
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 = {
|
export const multiplayerAssetStore: TLAssetStore = {
|
||||||
// to upload an asset, we...
|
|
||||||
async upload(_asset, file) {
|
async upload(_asset, file) {
|
||||||
// ...create a unique name & URL...
|
|
||||||
const id = uniqueId()
|
const id = uniqueId()
|
||||||
const objectName = `${id}-${file.name}`.replace(/[^a-zA-Z0-9.]/g, '-')
|
const objectName = `${id}-${file.name}`.replace(/[^a-zA-Z0-9.]/g, '-')
|
||||||
const url = `${WORKER_URL}/uploads/${objectName}`
|
const url = `${WORKER_URL}/uploads/${objectName}`
|
||||||
|
|
||||||
// ...POST it to out worker to upload it...
|
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: file,
|
body: file,
|
||||||
|
|
@ -21,12 +16,9 @@ export const multiplayerAssetStore: TLAssetStore = {
|
||||||
throw new Error(`Failed to upload asset: ${response.statusText}`)
|
throw new Error(`Failed to upload asset: ${response.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...and return the URL to be stored with the asset record.
|
|
||||||
return url
|
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) {
|
resolve(asset) {
|
||||||
return asset.props.src
|
return asset.props.src
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import { components, uiOverrides } from '@/ui-overrides'
|
||||||
import { useCameraControls } from '@/hooks/useCameraControls'
|
import { useCameraControls } from '@/hooks/useCameraControls'
|
||||||
|
|
||||||
//const WORKER_URL = `https://jeffemmett-canvas.jeffemmett.workers.dev`
|
//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 shapeUtils = [ChatBoxShape, VideoChatShape, EmbedShape]
|
||||||
const tools = [ChatBoxTool, VideoChatTool, EmbedTool]; // Array of tools
|
const tools = [ChatBoxTool, VideoChatTool, EmbedTool]; // Array of tools
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ import { viteStaticCopy } from 'vite-plugin-static-copy';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
define: {
|
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: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue