snapshot of https://github.com/tldraw/tldraw.git (main, 2026-09-23; blobs > 131072B omitted)
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
This commit is contained in:
1
apps/dotcom/asset-upload-worker/.gitignore
vendored
Normal file
1
apps/dotcom/asset-upload-worker/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
tmp-assets
|
||||
27
apps/dotcom/asset-upload-worker/README.md
Normal file
27
apps/dotcom/asset-upload-worker/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# dotcom-asset-upload
|
||||
|
||||
Asset uploading for tldraw.com.
|
||||
|
||||
## License
|
||||
|
||||
The code in this folder is Copyright (c) 2024-present tldraw Inc. The tldraw SDK is provided under the [tldraw license](https://github.com/tldraw/tldraw/blob/main/LICENSE.md).
|
||||
|
||||
## Trademarks
|
||||
|
||||
Copyright (c) 2024-present tldraw Inc. The tldraw name and logo are trademarks of tldraw. Please see our [trademark guidelines](https://github.com/tldraw/tldraw/blob/main/TRADEMARKS.md) for info on acceptable usage.
|
||||
|
||||
## Distributions
|
||||
|
||||
You can find tldraw on npm [here](https://www.npmjs.com/package/@tldraw/tldraw?activeTab=versions).
|
||||
|
||||
## Contribution
|
||||
|
||||
Found a bug? Please [submit an issue](https://github.com/tldraw/tldraw/issues/new).
|
||||
|
||||
## Community
|
||||
|
||||
Have questions, comments or feedback? [Join our discord](https://discord.tldraw.com/?utm_source=github&utm_medium=readme&utm_campaign=sociallink). For the latest news and release notes, visit [tldraw.dev](https://tldraw.dev).
|
||||
|
||||
## Contact
|
||||
|
||||
Find us on Twitter/X at [@tldraw](https://twitter.com/tldraw).
|
||||
28
apps/dotcom/asset-upload-worker/package.json
Normal file
28
apps/dotcom/asset-upload-worker/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "dotcom-asset-upload",
|
||||
"description": "A Cloudflare Worker to upload and serve images",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"author": {
|
||||
"name": "tldraw GB Ltd.",
|
||||
"email": "hello@tldraw.com"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"dev": "yarn run -T tsx ../../../internal/scripts/workers/dev.ts --persist-to tmp-assets --inspector-port 9449",
|
||||
"test-ci": "yarn run -T vitest run --passWithNoTests",
|
||||
"test": "yarn run -T vitest --passWithNoTests",
|
||||
"test-coverage": "yarn run -T vitest run --coverage --passWithNoTests",
|
||||
"lint": "yarn run -T tsx ../../../internal/scripts/lint.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tldraw/worker-shared": "workspace:*",
|
||||
"itty-router": "^5.0.18"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20260302.0",
|
||||
"@types/ws": "^8.18.1",
|
||||
"lazyrepo": "0.0.0-alpha.27",
|
||||
"wrangler": "^4.75.0"
|
||||
}
|
||||
}
|
||||
13
apps/dotcom/asset-upload-worker/src/types.ts
Normal file
13
apps/dotcom/asset-upload-worker/src/types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { R2Bucket, WorkerVersionMetadata } from '@cloudflare/workers-types'
|
||||
|
||||
export interface Environment {
|
||||
// bindings
|
||||
UPLOADS: R2Bucket
|
||||
CF_VERSION_METADATA: WorkerVersionMetadata
|
||||
|
||||
// environment variables
|
||||
TLDRAW_ENV: string | undefined
|
||||
SENTRY_DSN: string | undefined
|
||||
IS_LOCAL: string | undefined
|
||||
WORKER_NAME: string | undefined
|
||||
}
|
||||
50
apps/dotcom/asset-upload-worker/src/worker.ts
Normal file
50
apps/dotcom/asset-upload-worker/src/worker.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/// <reference no-default-lib="true"/>
|
||||
/// <reference types="@cloudflare/workers-types" />
|
||||
|
||||
import {
|
||||
blockUnknownOrigins,
|
||||
createRouter,
|
||||
handleApiRequest,
|
||||
handleUserAssetGet,
|
||||
handleUserAssetUpload,
|
||||
isAllowedOrigin,
|
||||
notFound,
|
||||
} from '@tldraw/worker-shared'
|
||||
import { WorkerEntrypoint } from 'cloudflare:workers'
|
||||
import { cors } from 'itty-router'
|
||||
import { Environment } from './types'
|
||||
|
||||
const { preflight, corsify } = cors({ origin: isAllowedOrigin })
|
||||
|
||||
export default class Worker extends WorkerEntrypoint<Environment> {
|
||||
readonly router = createRouter<Environment>()
|
||||
.all('*', preflight)
|
||||
.all('*', blockUnknownOrigins)
|
||||
.get('/uploads/:objectName', async (request) => {
|
||||
return handleUserAssetGet({
|
||||
request,
|
||||
bucket: this.env.UPLOADS,
|
||||
objectName: request.params.objectName,
|
||||
context: this.ctx,
|
||||
})
|
||||
})
|
||||
.post('/uploads/:objectName', async (request) => {
|
||||
return handleUserAssetUpload({
|
||||
headers: request.headers,
|
||||
body: request.body,
|
||||
bucket: this.env.UPLOADS,
|
||||
objectName: request.params.objectName,
|
||||
})
|
||||
})
|
||||
.all('*', notFound)
|
||||
|
||||
override async fetch(request: Request) {
|
||||
return handleApiRequest({
|
||||
router: this.router,
|
||||
request,
|
||||
env: this.env,
|
||||
ctx: this.ctx,
|
||||
after: corsify,
|
||||
})
|
||||
}
|
||||
}
|
||||
7
apps/dotcom/asset-upload-worker/tsconfig.json
Normal file
7
apps/dotcom/asset-upload-worker/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../internal/config/tsconfig.base.json",
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist", ".tsbuild*"],
|
||||
"compilerOptions": { "noEmit": true, "emitDeclarationOnly": false },
|
||||
"references": [{ "path": "../../../packages/worker-shared" }]
|
||||
}
|
||||
10
apps/dotcom/asset-upload-worker/vitest.config.ts
Normal file
10
apps/dotcom/asset-upload-worker/vitest.config.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/// <reference types="vitest" />
|
||||
import { mergeConfig } from 'vitest/config'
|
||||
import baseConfig from '../../../internal/config/vitest/node-preset'
|
||||
|
||||
export default mergeConfig(baseConfig, {
|
||||
test: {
|
||||
environment: 'node',
|
||||
passWithNoTests: true,
|
||||
},
|
||||
})
|
||||
81
apps/dotcom/asset-upload-worker/wrangler.toml
Normal file
81
apps/dotcom/asset-upload-worker/wrangler.toml
Normal file
@@ -0,0 +1,81 @@
|
||||
main = "src/worker.ts"
|
||||
compatibility_date = "2024-06-20"
|
||||
|
||||
[dev]
|
||||
port = 8788
|
||||
|
||||
[[analytics_engine_datasets]]
|
||||
binding = "MEASURE"
|
||||
|
||||
#################### Environment names ####################
|
||||
# dev should never actually get deployed anywhere
|
||||
[env.dev]
|
||||
name = 'tldraw-assets-dev'
|
||||
|
||||
# we don't have a hard-coded name for preview. we instead have to generate it at build time and append it to this file.
|
||||
|
||||
# staging is the same as a preview on main:
|
||||
[env.staging]
|
||||
name = "main-tldraw-assets"
|
||||
|
||||
# production gets the proper name
|
||||
[env.production]
|
||||
name = "tldraw-assets"
|
||||
|
||||
#################### Assets R2 bucket ####################
|
||||
# in dev, we write to the preview bucket and need a `preview_bucket_name`
|
||||
[[env.dev.r2_buckets]]
|
||||
binding = 'UPLOADS'
|
||||
bucket_name = 'uploads-preview'
|
||||
preview_bucket_name = 'uploads-preview'
|
||||
|
||||
# in preview and staging we write to the preview bucket
|
||||
[[env.preview.r2_buckets]]
|
||||
binding = 'UPLOADS'
|
||||
bucket_name = 'uploads-preview'
|
||||
|
||||
[[env.staging.r2_buckets]]
|
||||
binding = 'UPLOADS'
|
||||
bucket_name = 'uploads-preview'
|
||||
|
||||
# in production, we write to the main bucket
|
||||
[[env.production.r2_buckets]]
|
||||
binding = "UPLOADS"
|
||||
bucket_name = "uploads"
|
||||
|
||||
#################### Analytics engine ####################
|
||||
# analytics engine has the same configuration in all environments:
|
||||
[[env.dev.analytics_engine_datasets]]
|
||||
binding = "MEASURE"
|
||||
|
||||
[[env.preview.analytics_engine_datasets]]
|
||||
binding = "MEASURE"
|
||||
|
||||
[[env.staging.analytics_engine_datasets]]
|
||||
binding = "MEASURE"
|
||||
|
||||
[[env.production.analytics_engine_datasets]]
|
||||
binding = "MEASURE"
|
||||
|
||||
#################### Routes ####################
|
||||
# in production, we use a custom domain. others get a default *.tldraw.workers.dev domain
|
||||
[[env.production.routes]]
|
||||
pattern = 'assets.tldraw.xyz'
|
||||
custom_domain = true
|
||||
zone_name = 'tldraw.xyz'
|
||||
|
||||
#################### Version metadata ####################
|
||||
[version_metadata]
|
||||
binding = "CF_VERSION_METADATA"
|
||||
|
||||
[env.dev.version_metadata]
|
||||
binding = "CF_VERSION_METADATA"
|
||||
|
||||
[env.preview.version_metadata]
|
||||
binding = "CF_VERSION_METADATA"
|
||||
|
||||
[env.staging.version_metadata]
|
||||
binding = "CF_VERSION_METADATA"
|
||||
|
||||
[env.production.version_metadata]
|
||||
binding = "CF_VERSION_METADATA"
|
||||
Reference in New Issue
Block a user