## Cloudflare R2 File Drive

A simple FTP-style web UI built with Next.js App Router. Users can register/login (email + password), upload files or entire folders, list them, download via signed URLs, and delete. Files are stored in Cloudflare R2 (S3-compatible); metadata and users are stored in SQLite via Prisma.

## Setup
1) Install deps (already checked in `package-lock.json`):
```bash
npm install
```

2) Copy `env.example` to `.env.local` (or set env vars another way) and fill:
- `DATABASE_URL="file:./dev.db"` (default SQLite)
- `R2_ENDPOINT="https://<account-id>.r2.cloudflarestorage.com"`
- `R2_REGION="auto"`
- `R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY`
- `R2_BUCKET`
- `JWT_SECRET` (long random string)
- `PORT` / `NEXT_PORT` (defaults set to 4000 to avoid 3000)

3) Create DB & Prisma client:
```bash
npx prisma db push
npx prisma generate
```

4) Run dev server on port 4000:
```bash
npm run dev
# overrides: PORT=4500 npm run dev
```

5) Production:
```bash
npm run build
PORT=4000 npm run start
```

## Usage
- Register or log in at `/register` or `/login`.
- Dashboard at `/dashboard`:
  - Upload files or folders (uses `webkitdirectory`; folder structure is preserved in keys).
  - Files are stored under a user-specific prefix in R2; metadata kept in SQLite.
  - Download uses short-lived signed URLs; delete removes from R2 and DB.

## Notes
- Middleware protects `/dashboard` and `/api/files/*`; auth cookie is HttpOnly JWT.
- To change ports, set `PORT`/`NEXT_PORT` or pass `-p` to scripts; defaults avoid 3000.
- R2 endpoint format: `https://<account-id>.r2.cloudflarestorage.com`.
