Skip to content

Commit 459031f

Browse files
authored
Merge pull request #15 from zy84338719/update
Update
2 parents b413818 + 1d5dcf6 commit 459031f

File tree

21 files changed

+3082
-1349
lines changed

21 files changed

+3082
-1349
lines changed

docs/API-README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,93 @@ http://localhost:8080/swagger/doc.json
3939
go install github.com/swaggo/swag/cmd/swag@latest
4040

4141
# 生成/更新 Swagger 文档
42+
43+
## 🧰 API 模式(/api/v1)
44+
45+
API 模式面向 CLI 工具与自动化脚本,仅开放文件上传/下载及分片管理等核心能力。所有请求必须携带有效的 API Key,系统会拒绝使用普通用户 Token 的请求。
46+
47+
### ✅ 支持的接口
48+
49+
| 方法 | 路径 | 描述 |
50+
|------|------|------|
51+
| `POST` | `/api/v1/share/text` | 分享文本内容 |
52+
| `POST` | `/api/v1/share/file` | 上传并分享文件 |
53+
| `GET` | `/api/v1/share/{code}` | 查询分享详情 |
54+
| `GET` | `/api/v1/share/{code}/download` | 下载分享内容 |
55+
| `POST` | `/api/v1/chunks/upload/init` | 初始化分片上传 |
56+
| `POST` | `/api/v1/chunks/upload/chunk/{upload_id}/{chunk_index}` | 上传单个分片 |
57+
| `POST` | `/api/v1/chunks/upload/complete/{upload_id}` | 合并分片并生成分享 |
58+
| `GET` | `/api/v1/chunks/upload/status/{upload_id}` | 查询上传进度 |
59+
| `POST` | `/api/v1/chunks/upload/verify/{upload_id}/{chunk_index}` | 校验分片是否存在 |
60+
| `DELETE` | `/api/v1/chunks/upload/cancel/{upload_id}` | 取消分片上传 |
61+
62+
> 📌 **提示**:API Key 仅可访问 `/api/v1/...` 路由,不具备用户中心(/user/*)权限。
63+
64+
### 🔑 请求示例
65+
66+
所有示例均假设你已经通过 `/user/api-keys` 生成密钥,并使用 `X-API-Key` 头发送:
67+
68+
```bash
69+
# 分享文本
70+
curl -X POST "http://localhost:8080/api/v1/share/text" \
71+
-H "X-API-Key: <YOUR_API_KEY>" \
72+
-F "text=Hello API Mode" \
73+
-F "expire_value=1" \
74+
-F "expire_style=day"
75+
76+
# 上传文件
77+
curl -X POST "http://localhost:8080/api/v1/share/file" \
78+
-H "X-API-Key: <YOUR_API_KEY>" \
79+
80+
-F "expire_value=7" \
81+
-F "expire_style=day"
82+
83+
# 根据分享码下载
84+
curl -L -H "X-API-Key: <YOUR_API_KEY>" \
85+
"http://localhost:8080/api/v1/share/{code}/download" -o downloaded.bin
86+
```
87+
88+
### 📦 分片上传脚本示例
89+
90+
```bash
91+
# 1. 初始化上传
92+
UPLOAD_INFO=$(curl -s -X POST "http://localhost:8080/api/v1/chunks/upload/init" \
93+
-H "X-API-Key: <YOUR_API_KEY>" \
94+
-H "Content-Type: application/json" \
95+
-d '{
96+
"file_name": "large.zip",
97+
"file_size": 10485760,
98+
"chunk_size": 1048576,
99+
"file_hash": "example-hash"
100+
}')
101+
UPLOAD_ID=$(echo "$UPLOAD_INFO" | jq -r '.detail.upload_id')
102+
103+
# 2. 上传分片(以第 0 块为例)
104+
curl -X POST "http://localhost:8080/api/v1/chunks/upload/chunk/$UPLOAD_ID/0" \
105+
-H "X-API-Key: <YOUR_API_KEY>" \
106+
107+
108+
# 3. 合并分片
109+
curl -X POST "http://localhost:8080/api/v1/chunks/upload/complete/$UPLOAD_ID" \
110+
-H "X-API-Key: <YOUR_API_KEY>" \
111+
-H "Content-Type: application/json" \
112+
-d '{
113+
"expire_value": 7,
114+
"expire_style": "day",
115+
"require_auth": false
116+
}'
117+
118+
# 4. 查询进度(可选)
119+
curl -H "X-API-Key: <YOUR_API_KEY>" \
120+
"http://localhost:8080/api/v1/chunks/upload/status/$UPLOAD_ID"
121+
122+
# 5. 取消上传(可选)
123+
curl -X DELETE -H "X-API-Key: <YOUR_API_KEY>" \
124+
"http://localhost:8080/api/v1/chunks/upload/cancel/$UPLOAD_ID"
125+
```
126+
127+
> 🧪 **建议**:使用 `jq` 或自编脚本解析响应,提取 `detail.code``detail.share_url` 等字段,便于自动化处理。
128+
42129
swag init
43130
```
44131

0 commit comments

Comments
 (0)