Skip to content

Commit 81ee640

Browse files
committed
feat: #386 #380
1 parent e87bcfc commit 81ee640

40 files changed

+728
-100
lines changed

docs/api/index.md

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515
Authorization: Bearer <token>
1616
```
1717

18+
### 获取 Token
19+
20+
当管理面板关闭了游客上传(`openUpload=0`)时,需要先登录获取 token:
21+
22+
```bash
23+
curl -X POST "http://localhost:12345/admin/login" \
24+
-H "Content-Type: application/json" \
25+
-d '{"password": "FileCodeBox2023"}'
26+
```
27+
28+
**响应示例:**
29+
30+
```json
31+
{
32+
"code": 200,
33+
"msg": "success",
34+
"detail": {
35+
"token": "xxx.xxx.xxx",
36+
"token_type": "Bearer"
37+
}
38+
}
39+
```
40+
1841
## 分享接口
1942

2043
### 分享文本
@@ -29,7 +52,22 @@ Authorization: Bearer <token>
2952
|-------|------|------|--------|------|
3053
| text | string || - | 要分享的文本内容 |
3154
| expire_value | integer || 1 | 过期时间值 |
32-
| expire_style | string || "day" | 过期时间单位(day/hour/minute) |
55+
| expire_style | string || "day" | 过期时间单位(day/hour/minute/count/forever) |
56+
57+
**cURL 示例:**
58+
59+
```bash
60+
# 游客上传(openUpload=1 时)
61+
curl -X POST "http://localhost:12345/share/text/" \
62+
-F "text=这是要分享的文本内容" \
63+
-F "expire_value=1" \
64+
-F "expire_style=day"
65+
66+
# 需要认证时(openUpload=0 时)
67+
curl -X POST "http://localhost:12345/share/text/" \
68+
-H "Authorization: Bearer xxx.xxx.xxx" \
69+
-F "text=这是要分享的文本内容"
70+
```
3371

3472
**响应示例:**
3573

@@ -38,8 +76,7 @@ Authorization: Bearer <token>
3876
"code": 200,
3977
"msg": "success",
4078
"detail": {
41-
"code": "abc123",
42-
"name": "text.txt"
79+
"code": "abc123"
4380
}
4481
}
4582
```
@@ -56,7 +93,32 @@ Authorization: Bearer <token>
5693
|-------|------|------|--------|------|
5794
| file | file || - | 要上传的文件 |
5895
| expire_value | integer || 1 | 过期时间值 |
59-
| expire_style | string || "day" | 过期时间单位(day/hour/minute) |
96+
| expire_style | string || "day" | 过期时间单位(day/hour/minute/count/forever) |
97+
98+
**cURL 示例:**
99+
100+
```bash
101+
# 上传文件(默认1天有效期)
102+
curl -X POST "http://localhost:12345/share/file/" \
103+
-F "file=@/path/to/file.txt"
104+
105+
# 上传文件(7天有效期)
106+
curl -X POST "http://localhost:12345/share/file/" \
107+
-F "file=@/path/to/file.txt" \
108+
-F "expire_value=7" \
109+
-F "expire_style=day"
110+
111+
# 上传文件(可下载10次)
112+
curl -X POST "http://localhost:12345/share/file/" \
113+
-F "file=@/path/to/file.txt" \
114+
-F "expire_value=10" \
115+
-F "expire_style=count"
116+
117+
# 需要认证时
118+
curl -X POST "http://localhost:12345/share/file/" \
119+
-H "Authorization: Bearer xxx.xxx.xxx" \
120+
-F "file=@/path/to/file.txt"
121+
```
60122

61123
**响应示例:**
62124

@@ -75,14 +137,21 @@ Authorization: Bearer <token>
75137

76138
**GET** `/share/select/`
77139

78-
通过分享码获取文件信息。
140+
通过分享码获取文件信息(直接下载文件)
79141

80142
**请求参数:**
81143

82144
| 参数名 | 类型 | 必填 | 描述 |
83145
|-------|------|------|------|
84146
| code | string || 文件分享码 |
85147

148+
**cURL 示例:**
149+
150+
```bash
151+
# 通过取件码下载文件
152+
curl -L "http://localhost:12345/share/select/?code=abc123" -o downloaded_file
153+
```
154+
86155
**响应示例:**
87156

88157
```json

docs/en/api/index.md

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ Some APIs require `Authorization` header for authentication:
1515
Authorization: Bearer <token>
1616
```
1717

18+
### Get Token
19+
20+
When guest upload is disabled in admin panel (`openUpload=0`), you need to login first:
21+
22+
```bash
23+
curl -X POST "http://localhost:12345/admin/login" \
24+
-H "Content-Type: application/json" \
25+
-d '{"password": "FileCodeBox2023"}'
26+
```
27+
28+
**Response Example:**
29+
30+
```json
31+
{
32+
"code": 200,
33+
"msg": "success",
34+
"detail": {
35+
"token": "xxx.xxx.xxx",
36+
"token_type": "Bearer"
37+
}
38+
}
39+
```
40+
1841
## Share API
1942

2043
### Share Text
@@ -29,7 +52,22 @@ Share text content and get a share code.
2952
|-----------|------|----------|---------|-------------|
3053
| text | string | Yes | - | Text content to share |
3154
| expire_value | integer | No | 1 | Expiration time value |
32-
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute) |
55+
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute/count/forever) |
56+
57+
**cURL Example:**
58+
59+
```bash
60+
# Guest upload (when openUpload=1)
61+
curl -X POST "http://localhost:12345/share/text/" \
62+
-F "text=This is the text content to share" \
63+
-F "expire_value=1" \
64+
-F "expire_style=day"
65+
66+
# When authentication required (openUpload=0)
67+
curl -X POST "http://localhost:12345/share/text/" \
68+
-H "Authorization: Bearer xxx.xxx.xxx" \
69+
-F "text=This is the text content to share"
70+
```
3371

3472
**Response Example:**
3573

@@ -38,8 +76,7 @@ Share text content and get a share code.
3876
"code": 200,
3977
"msg": "success",
4078
"detail": {
41-
"code": "abc123",
42-
"name": "text.txt"
79+
"code": "abc123"
4380
}
4481
}
4582
```
@@ -56,7 +93,32 @@ Upload and share a file, get a share code.
5693
|-----------|------|----------|---------|-------------|
5794
| file | file | Yes | - | File to upload |
5895
| expire_value | integer | No | 1 | Expiration time value |
59-
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute) |
96+
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute/count/forever) |
97+
98+
**cURL Example:**
99+
100+
```bash
101+
# Upload file (default 1 day expiration)
102+
curl -X POST "http://localhost:12345/share/file/" \
103+
-F "file=@/path/to/file.txt"
104+
105+
# Upload file (7 days expiration)
106+
curl -X POST "http://localhost:12345/share/file/" \
107+
-F "file=@/path/to/file.txt" \
108+
-F "expire_value=7" \
109+
-F "expire_style=day"
110+
111+
# Upload file (10 downloads limit)
112+
curl -X POST "http://localhost:12345/share/file/" \
113+
-F "file=@/path/to/file.txt" \
114+
-F "expire_value=10" \
115+
-F "expire_style=count"
116+
117+
# When authentication required
118+
curl -X POST "http://localhost:12345/share/file/" \
119+
-H "Authorization: Bearer xxx.xxx.xxx" \
120+
-F "file=@/path/to/file.txt"
121+
```
60122

61123
**Response Example:**
62124

@@ -75,14 +137,21 @@ Upload and share a file, get a share code.
75137

76138
**GET** `/share/select/`
77139

78-
Get file information by share code.
140+
Get file information by share code (direct file download).
79141

80142
**Parameters:**
81143

82144
| Parameter | Type | Required | Description |
83145
|-----------|------|----------|-------------|
84146
| code | string | Yes | File share code |
85147

148+
**cURL Example:**
149+
150+
```bash
151+
# Download file by extraction code
152+
curl -L "http://localhost:12345/share/select/?code=abc123" -o downloaded_file
153+
```
154+
86155
**Response Example:**
87156

88157
```json

docs/en/guide/upload.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,52 @@ Content-Type: `multipart/form-data`
118118
**cURL example:**
119119

120120
```bash
121+
# Upload file (default 1 day expiration)
122+
curl -X POST "http://localhost:12345/share/file/" \
123+
-F "file=@/path/to/file.pdf"
124+
125+
# Upload file with 7 days expiration
121126
curl -X POST "http://localhost:12345/share/file/" \
122127
-F "file=@/path/to/file.pdf" \
123128
-F "expire_value=7" \
124129
-F "expire_style=day"
130+
131+
# Upload file with 10 downloads limit
132+
curl -X POST "http://localhost:12345/share/file/" \
133+
-F "file=@/path/to/file.pdf" \
134+
-F "expire_value=10" \
135+
-F "expire_style=count"
136+
137+
# Share text
138+
curl -X POST "http://localhost:12345/share/text/" \
139+
-F "text=This is the text content to share"
140+
141+
# Download file by extraction code
142+
curl -L "http://localhost:12345/share/select/?code=YOUR_CODE" -o downloaded_file
143+
```
144+
145+
::: tip When Authentication Required
146+
If guest upload is disabled in admin panel (`openUpload=0`), you need to login first:
147+
148+
```bash
149+
# 1. Login to get token
150+
curl -X POST "http://localhost:12345/admin/login" \
151+
-H "Content-Type: application/json" \
152+
-d '{"password": "FileCodeBox2023"}'
153+
154+
# Returns: {"code":200,"msg":"success","detail":{"token":"xxx.xxx.xxx","token_type":"Bearer"}}
155+
156+
# 2. Upload file with token
157+
curl -X POST "http://localhost:12345/share/file/" \
158+
-H "Authorization: Bearer xxx.xxx.xxx" \
159+
-F "file=@/path/to/file.pdf"
160+
161+
# 3. Share text with token
162+
curl -X POST "http://localhost:12345/share/text/" \
163+
-H "Authorization: Bearer xxx.xxx.xxx" \
164+
-F "text=This is the text content to share"
125165
```
166+
:::
126167

127168

128169
## Chunked Upload API

docs/guide/upload.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,52 @@ Content-Type: `multipart/form-data`
118118
**cURL 示例:**
119119

120120
```bash
121+
# 上传文件(默认1天有效期)
122+
curl -X POST "http://localhost:12345/share/file/" \
123+
-F "file=@/path/to/file.pdf"
124+
125+
# 上传文件并指定有效期(7天)
121126
curl -X POST "http://localhost:12345/share/file/" \
122127
-F "file=@/path/to/file.pdf" \
123128
-F "expire_value=7" \
124129
-F "expire_style=day"
130+
131+
# 上传文件并指定有效期(可下载10次)
132+
curl -X POST "http://localhost:12345/share/file/" \
133+
-F "file=@/path/to/file.pdf" \
134+
-F "expire_value=10" \
135+
-F "expire_style=count"
136+
137+
# 分享文本
138+
curl -X POST "http://localhost:12345/share/text/" \
139+
-F "text=这是要分享的文本内容"
140+
141+
# 通过取件码下载文件
142+
curl -L "http://localhost:12345/share/select/?code=取件码" -o downloaded_file
143+
```
144+
145+
::: tip 需要认证时
146+
如果管理面板关闭了游客上传(`openUpload=0`),需要先登录获取 token:
147+
148+
```bash
149+
# 1. 登录获取 token
150+
curl -X POST "http://localhost:12345/admin/login" \
151+
-H "Content-Type: application/json" \
152+
-d '{"password": "FileCodeBox2023"}'
153+
154+
# 返回: {"code":200,"msg":"success","detail":{"token":"xxx.xxx.xxx","token_type":"Bearer"}}
155+
156+
# 2. 使用 token 上传文件
157+
curl -X POST "http://localhost:12345/share/file/" \
158+
-H "Authorization: Bearer xxx.xxx.xxx" \
159+
-F "file=@/path/to/file.pdf"
160+
161+
# 3. 使用 token 分享文本
162+
curl -X POST "http://localhost:12345/share/text/" \
163+
-H "Authorization: Bearer xxx.xxx.xxx" \
164+
-F "text=这是要分享的文本内容"
125165
```
166+
:::
126167

127168
## 分片上传 API
128169

0 commit comments

Comments
 (0)