feat: initial cfdav project with webdav+r2+d1 and pages admin docs
This commit is contained in:
150
README.md
Normal file
150
README.md
Normal file
@@ -0,0 +1,150 @@
|
||||
# cfdav
|
||||
|
||||
A minimal WebDAV → Cloudflare R2 service built on Cloudflare Workers + Hono, with D1 metadata and a small admin UI (Cloudflare Pages).
|
||||
|
||||
## ✅ Project Purpose
|
||||
- Provide a **lightweight WebDAV gateway** backed by Cloudflare R2
|
||||
- Support **multi-user isolation** (each user sees only their own file tree)
|
||||
- Offer a **simple admin UI** to manage users (add/delete)
|
||||
|
||||
---
|
||||
|
||||
## ✅ Features
|
||||
- WebDAV endpoints: OPTIONS, PROPFIND, GET, HEAD, PUT, MKCOL, DELETE, MOVE, COPY, LOCK, UNLOCK, PROPPATCH
|
||||
- Basic Auth (multi-user in D1; bootstrap admin supported)
|
||||
- Metadata stored in D1 (SQLite)
|
||||
- File content stored in R2 (binding: FILES)
|
||||
- Windows WebDAV compatibility headers (DAV + MS-Author-Via)
|
||||
- Admin UI (Cloudflare Pages) for user management
|
||||
|
||||
---
|
||||
|
||||
## ✅ Deployment Flow (Production)
|
||||
|
||||
### 1) Install
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### 2) Configure `wrangler.toml`
|
||||
Edit `wrangler.toml` and fill real IDs:
|
||||
```toml
|
||||
[[d1_databases]]
|
||||
binding = "DB"
|
||||
database_name = "cfdav-db"
|
||||
database_id = "YOUR_D1_DATABASE_ID"
|
||||
|
||||
[[r2_buckets]]
|
||||
binding = "FILES"
|
||||
bucket_name = "YOUR_R2_BUCKET"
|
||||
|
||||
[vars]
|
||||
ENVIRONMENT = "production"
|
||||
BASIC_USER = "YOUR_BOOTSTRAP_EMAIL"
|
||||
BASIC_PASS = "YOUR_BOOTSTRAP_PASSWORD"
|
||||
```
|
||||
|
||||
### 3) Create D1 + apply migrations
|
||||
```bash
|
||||
wrangler d1 create cfdav-db
|
||||
wrangler d1 migrations apply cfdav-db --remote
|
||||
```
|
||||
|
||||
### 4) Create R2 bucket
|
||||
```bash
|
||||
wrangler r2 bucket create <your-bucket-name>
|
||||
```
|
||||
|
||||
### 5) Deploy Worker
|
||||
```bash
|
||||
wrangler deploy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ Admin UI (Cloudflare Pages)
|
||||
|
||||
### 1) Create Pages Project
|
||||
```bash
|
||||
wrangler pages project create cfdav-admin --production-branch main
|
||||
```
|
||||
|
||||
### 2) Deploy static UI
|
||||
```bash
|
||||
cd web
|
||||
wrangler pages deploy . --project-name cfdav-admin
|
||||
```
|
||||
|
||||
### 3) Login
|
||||
- API Base: `https://<your-worker-domain>`
|
||||
- Email/Password: your admin account
|
||||
|
||||
---
|
||||
|
||||
## ✅ User Management
|
||||
|
||||
### Bootstrap admin
|
||||
If `users` table is empty, first login with:
|
||||
- `BASIC_USER`
|
||||
- `BASIC_PASS`
|
||||
|
||||
This account will be auto-created as **admin**.
|
||||
|
||||
### Create user via UI
|
||||
Open the Pages admin UI and create users from the form.
|
||||
|
||||
### Create user via CLI (optional)
|
||||
```bash
|
||||
node tools/hash.mjs <password>
|
||||
wrangler d1 execute cfdav-db --remote --command \
|
||||
"INSERT INTO users (id,email,password_hash,is_admin,created_at) VALUES ('<uuid>','user@example.com','<HASH>',0,'<ISO>')"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ WebDAV Usage
|
||||
|
||||
### Endpoint
|
||||
```
|
||||
https://<your-worker-domain>/dav/
|
||||
```
|
||||
|
||||
### Example (curl)
|
||||
```bash
|
||||
# upload
|
||||
curl -u user@example.com:password -T ./file.txt https://<your-domain>/dav/file.txt
|
||||
|
||||
# list
|
||||
curl -u user@example.com:password -X PROPFIND -H 'Depth: 1' https://<your-domain>/dav/
|
||||
|
||||
# download
|
||||
curl -u user@example.com:password https://<your-domain>/dav/file.txt
|
||||
```
|
||||
|
||||
### Windows Mount (Explorer)
|
||||
- 右键“此电脑” → “映射网络驱动器” → 地址:
|
||||
`https://<your-domain>/dav/`
|
||||
- 账号:邮箱
|
||||
- 密码:对应密码
|
||||
|
||||
### macOS Finder
|
||||
- Finder → “前往” → “连接服务器”
|
||||
- 输入:`https://<your-domain>/dav/`
|
||||
|
||||
---
|
||||
|
||||
## ✅ Required Config Parameters
|
||||
- **Cloudflare API Token** (Workers + D1 + R2 + Pages权限)
|
||||
- **CLOUDFLARE_ACCOUNT_ID**
|
||||
- `D1 database_id`
|
||||
- `R2 bucket_name`
|
||||
- `BASIC_USER` / `BASIC_PASS`
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
- WebDAV endpoint: `/dav`
|
||||
- Admin API: `/api/admin/users`
|
||||
- R2 binding: `FILES`
|
||||
- D1 binding: `DB`
|
||||
|
||||
Reference in New Issue
Block a user