Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cloudflare/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public/
# Wrangler
.wrangler/
.dev.vars
wrangler.staging.toml
wrangler.local.toml

# Frontend
frontend/node_modules/
Expand Down
5 changes: 4 additions & 1 deletion cloudflare/src/routes/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ uploadRoutes.post('/uploads/presign', async (c) => {

const db = c.get('db');
const user = c.get('user');
const s3 = createS3Client(c.env);
// S3 client is only needed in non-dev mode (presigned direct-to-R2 upload).
// Lazy-construct inside the else branch below so dev mode (proxy-put) works
// without R2_ACCESS_KEY_ID / R2_SECRET_ACCESS_KEY secrets.
const cleanExt = ext.replace(/^\./, '');
const sessionId = crypto.randomUUID();
const tempKey = `tmp/${crypto.randomUUID()}.${cleanExt}`;
Expand Down Expand Up @@ -128,6 +130,7 @@ uploadRoutes.post('/uploads/presign', async (c) => {
if (isDev) {
presignedUrl = `/api/uploads/proxy-put/${sessionId}`;
} else {
const s3 = createS3Client(c.env);
presignedUrl = await generatePresignedPutUrl(s3, c.env, tempKey, {
contentType: mimetype,
});
Expand Down
Loading