Add workflows + second public R2 bucket#234
Open
Judyzc wants to merge 4 commits intocloudflare:mainfrom
Open
Conversation
… public asset domain for safe assets
…k serving existing tests
b06ec4c to
1917897
Compare
…1 and R2 calls, renamed files, checked if Cloudflare Workflow works with astro dev (hot reload) and staging
1917897 to
60a95a6
Compare
Judyzc
commented
Mar 30, 2026
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| "name": "telescopetest-io", | ||
| "account_id": "4b1c95badf17540db82cd8b431ae3eb0", | ||
| "main": "./src/worker.ts", |
Contributor
Author
There was a problem hiding this comment.
./src/worker.ts is required to export AiContentRatingWorkflow as a named export alongside Astro's request handler — the standard @astrojs/cloudflare/entrypoints/server entrypoint doesn't support additional exports (https://docs.astro.build/en/guides/integrations-guide/cloudflare/#changed-custom-entrypoint-api).
Judyzc
commented
Mar 31, 2026
| if (!listed.objects || listed.objects.length === 0) { | ||
| // Paginate R2 list() — returns at most 1000 objects per call | ||
| // https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#r2listoptions | ||
| let listed = await bucket.list({ prefix }); |
Contributor
Author
There was a problem hiding this comment.
Now get R2 assets from public bucket if safe (bypass Worker completely).
Judyzc
commented
Mar 31, 2026
| // Try public bucket first — SAFE files are copied here by the workflow, no rating check needed. | ||
| // Serve directly (no redirect) since fetch() calls can't follow cross-origin redirects (CORS). | ||
| const publicFile = hasPublicBucket() | ||
| ? await env.PUBLIC_RESULTS_BUCKET!.get(key).catch(() => null) |
Contributor
Author
There was a problem hiding this comment.
Now get R2 assets from public bucket if safe (bypass Worker completely).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses (fixes) #209. Tested on staging.
High-level explanation of changes:
New upload flows for different environments:
Dev, AI off (default)
Dev, AI on (.dev.vars override)
Staging
Production
Follow-up
We'll need some kind of one-time script or process to move all the current R2 files that are safe into the public bucket. Right now, the code has a fallback to use D1/the Worker if the asset isn't in the public bucket. This is so the PR doesn't break any existing results/functionality when merged.
But I think ideally we'd do this process: (1) merge this PR (with fallback code) -> (2) run one-time script to move files -> (3) clean up fallback code