{"path":"README.md","content":"# cf-r2-drop\n\nDrag-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.\n\n[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/nexarq-ai/cf-r2-drop)\n\n## Architecture\n\n```mermaid\nflowchart LR\n  B[Browser] -->|POST /api/uploads| W[Worker]\n  B -->|PUT parts/n, 4 in parallel| W\n  B -->|POST complete| W\n  W -->|createMultipartUpload / uploadPart / complete| R[(R2 FILES)]\n  B -->|GET /s/token, /d/token| W\n  W -->|verify HMAC, increment| D[Links Durable Object]\n  W -->|stream, Range| R\n  C[Cron trigger daily] --> W\n  W -->|delete expired| R\n```\n\nSigned 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](docs/ARCHITECTURE.md).\n\n## Features\n- Files of 10 MB or more upload as 8 MB parts, 4 in parallel, 3 retries with backoff. Smaller files use one PUT.\n- Progress, speed, pause, resume and cancel.\n- Share card: copy link, expiry (1 h, 24 h, 7 d), download limit (1, 5, 25, unlimited), QR code.\n- `/s/<token>` share page with countdown, downloads left, image and PDF preview.\n- `/my` lists links created in this browser, with live counts and Revoke.\n- A daily cron deletes objects whose `expiresAt` has passed.\n\n## Local development\n```sh\nnpm install\ncp .dev.vars.example .dev.vars   # set LINK_SECRET\nnpm run dev\n```\n\n## Tests\n```sh\nnpm test            # vitest run\nnpm run typecheck   # tsc --noEmit\n```\n\n## Deploy\n```sh\nnpx wrangler secret put LINK_SECRET\nnpm run deploy                 # top level\nnpm run deploy:staging         # --env staging\nnpx wrangler deploy --env production\n```\nBucket names are `cf-r2-drop-files`, with `-staging` and `-production` suffixes. Create them first with `wrangler r2 bucket create <name>`.\n\n### R2 lifecycle rule\nDelete objects after 7 days and abort incomplete multipart uploads after 1 day, using `scripts/lifecycle.json`:\n```sh\nnpx wrangler r2 bucket lifecycle set cf-r2-drop-files --file scripts/lifecycle.json\n```\nThe cron is the precise expiry. The lifecycle rule is the backstop.\n\n## Configuration\n| Name | Kind | Purpose |\n|------|------|---------|\n| `LINK_SECRET` | secret | HMAC-SHA256 key for share links. Use 32 or more random bytes. Changing it invalidates all links. |\n| `FILES` | R2 binding | Object storage. |\n| `LINKS` | Durable Object binding | Download counts and revocation (SQLite). |\n| `ASSETS` | assets binding | Static UI from `public/`. |\n| `ENVIRONMENT` | var | `dev`, `staging`, `production` or `preview`. |\n| cron `0 3 * * *` | trigger | Daily cleanup of expired objects. |\n\nLimits: 5 GB per file, 100 MB per single PUT.\n\n## Costs\nR2 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.\n\n## Screenshots\nTo be added.\n\n## Built with Gitflare\nThis project was built by coordinated agents in Gitflare. Each agent owned one part (server, UI, docs), and the parts were merged and tested together.\n\n## License\nApache-2.0. See [LICENSE](LICENSE).\n","commitSha":"0e4544f45e7e0ed38d82a575b9941e5c0b6c96d5"}