Skip to content

gitflarePublicPartly agent-ready50

cf-r2-drop

Drag-and-drop file sharing on Cloudflare R2: multipart uploads, expiring share links, previews, download counts, lifecycle expiry.

main
Serve the share page from the extensionless asset path0e4544f
Markdown84 lines3.4 KB

cf-r2-drop

Drag-and-drop file sharing on Cloudflare. It shows R2 multipart uploads from the browser through a Worker, HMAC-signed expiring links, range-aware downloads, and a SQLite Durable Object that enforces download limits and revocation. The UI identity is "Courier at dusk": near-black with a warm amber accent.

Deploy to Cloudflare

Architecture

flowchart LR
  B[Browser] -->|POST /api/uploads| W[Worker]
  B -->|PUT parts/n, 4 in parallel| W
  B -->|POST complete| W
  W -->|createMultipartUpload / uploadPart / complete| R[(R2 FILES)]
  B -->|GET /s/token, /d/token| W
  W -->|verify HMAC, increment| D[Links Durable Object]
  W -->|stream, Range| R
  C[Cron trigger daily] --> W
  W -->|delete expired| R

Signed link flow: the Worker signs objectKey.expiresAt.limit with LINK_SECRET, verifies the signature on every request, then asks the Links Durable Object to atomically count the download before streaming. See docs/ARCHITECTURE.md.

Features

  • Files of 10 MB or more upload as 8 MB parts, 4 in parallel, 3 retries with backoff. Smaller files use one PUT.
  • Progress, speed, pause, resume and cancel.
  • Share card: copy link, expiry (1 h, 24 h, 7 d), download limit (1, 5, 25, unlimited), QR code.
  • /s/<token> share page with countdown, downloads left, image and PDF preview.
  • /my lists links created in this browser, with live counts and Revoke.
  • A daily cron deletes objects whose expiresAt has passed.

Local development

npm install
cp .dev.vars.example .dev.vars   # set LINK_SECRET
npm run dev

Tests

npm test            # vitest run
npm run typecheck   # tsc --noEmit

Deploy

npx wrangler secret put LINK_SECRET
npm run deploy                 # top level
npm run deploy:staging         # --env staging
npx wrangler deploy --env production

Bucket names are cf-r2-drop-files, with -staging and -production suffixes. Create them first with wrangler r2 bucket create <name>.

R2 lifecycle rule

Delete objects after 7 days and abort incomplete multipart uploads after 1 day, using scripts/lifecycle.json:

npx wrangler r2 bucket lifecycle set cf-r2-drop-files --file scripts/lifecycle.json

The cron is the precise expiry. The lifecycle rule is the backstop.

Configuration

NameKindPurpose
LINK_SECRETsecretHMAC-SHA256 key for share links. Use 32 or more random bytes. Changing it invalidates all links.
FILESR2 bindingObject storage.
LINKSDurable Object bindingDownload counts and revocation (SQLite).
ASSETSassets bindingStatic UI from public/.
ENVIRONMENTvardev, staging, production or preview.
cron 0 3 * * *triggerDaily cleanup of expired objects.

Limits: 5 GB per file, 100 MB per single PUT.

Costs

R2 has a free tier for storage and operations, and egress is free. Each multipart file costs one operation per part plus create and complete. Workers and Durable Objects bill by request and duration. Check Cloudflare's current pricing pages.

Screenshots

To be added.

Built with Gitflare

This project was built by coordinated agents in Gitflare. Each agent owned one part (server, UI, docs), and the parts were merged and tested together.

License

Apache-2.0. See LICENSE.