feat: https://github.com/vastsa/FileCodeBox/issues/386 https://github.com/vastsa/FileCodeBox/issues/380
This commit is contained in:
+74
-5
@@ -15,6 +15,29 @@ Some APIs require `Authorization` header for authentication:
|
||||
Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
### Get Token
|
||||
|
||||
When guest upload is disabled in admin panel (`openUpload=0`), you need to login first:
|
||||
|
||||
```bash
|
||||
curl -X POST "http://localhost:12345/admin/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"password": "FileCodeBox2023"}'
|
||||
```
|
||||
|
||||
**Response Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"detail": {
|
||||
"token": "xxx.xxx.xxx",
|
||||
"token_type": "Bearer"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Share API
|
||||
|
||||
### Share Text
|
||||
@@ -29,7 +52,22 @@ Share text content and get a share code.
|
||||
|-----------|------|----------|---------|-------------|
|
||||
| text | string | Yes | - | Text content to share |
|
||||
| expire_value | integer | No | 1 | Expiration time value |
|
||||
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute) |
|
||||
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute/count/forever) |
|
||||
|
||||
**cURL Example:**
|
||||
|
||||
```bash
|
||||
# Guest upload (when openUpload=1)
|
||||
curl -X POST "http://localhost:12345/share/text/" \
|
||||
-F "text=This is the text content to share" \
|
||||
-F "expire_value=1" \
|
||||
-F "expire_style=day"
|
||||
|
||||
# When authentication required (openUpload=0)
|
||||
curl -X POST "http://localhost:12345/share/text/" \
|
||||
-H "Authorization: Bearer xxx.xxx.xxx" \
|
||||
-F "text=This is the text content to share"
|
||||
```
|
||||
|
||||
**Response Example:**
|
||||
|
||||
@@ -38,8 +76,7 @@ Share text content and get a share code.
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"detail": {
|
||||
"code": "abc123",
|
||||
"name": "text.txt"
|
||||
"code": "abc123"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -56,7 +93,32 @@ Upload and share a file, get a share code.
|
||||
|-----------|------|----------|---------|-------------|
|
||||
| file | file | Yes | - | File to upload |
|
||||
| expire_value | integer | No | 1 | Expiration time value |
|
||||
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute) |
|
||||
| expire_style | string | No | "day" | Expiration time unit(day/hour/minute/count/forever) |
|
||||
|
||||
**cURL Example:**
|
||||
|
||||
```bash
|
||||
# Upload file (default 1 day expiration)
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-F "file=@/path/to/file.txt"
|
||||
|
||||
# Upload file (7 days expiration)
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-F "file=@/path/to/file.txt" \
|
||||
-F "expire_value=7" \
|
||||
-F "expire_style=day"
|
||||
|
||||
# Upload file (10 downloads limit)
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-F "file=@/path/to/file.txt" \
|
||||
-F "expire_value=10" \
|
||||
-F "expire_style=count"
|
||||
|
||||
# When authentication required
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-H "Authorization: Bearer xxx.xxx.xxx" \
|
||||
-F "file=@/path/to/file.txt"
|
||||
```
|
||||
|
||||
**Response Example:**
|
||||
|
||||
@@ -75,7 +137,7 @@ Upload and share a file, get a share code.
|
||||
|
||||
**GET** `/share/select/`
|
||||
|
||||
Get file information by share code.
|
||||
Get file information by share code (direct file download).
|
||||
|
||||
**Parameters:**
|
||||
|
||||
@@ -83,6 +145,13 @@ Get file information by share code.
|
||||
|-----------|------|----------|-------------|
|
||||
| code | string | Yes | File share code |
|
||||
|
||||
**cURL Example:**
|
||||
|
||||
```bash
|
||||
# Download file by extraction code
|
||||
curl -L "http://localhost:12345/share/select/?code=abc123" -o downloaded_file
|
||||
```
|
||||
|
||||
**Response Example:**
|
||||
|
||||
```json
|
||||
|
||||
@@ -118,12 +118,53 @@ Content-Type: `multipart/form-data`
|
||||
**cURL example:**
|
||||
|
||||
```bash
|
||||
# Upload file (default 1 day expiration)
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-F "file=@/path/to/file.pdf"
|
||||
|
||||
# Upload file with 7 days expiration
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-F "file=@/path/to/file.pdf" \
|
||||
-F "expire_value=7" \
|
||||
-F "expire_style=day"
|
||||
|
||||
# Upload file with 10 downloads limit
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-F "file=@/path/to/file.pdf" \
|
||||
-F "expire_value=10" \
|
||||
-F "expire_style=count"
|
||||
|
||||
# Share text
|
||||
curl -X POST "http://localhost:12345/share/text/" \
|
||||
-F "text=This is the text content to share"
|
||||
|
||||
# Download file by extraction code
|
||||
curl -L "http://localhost:12345/share/select/?code=YOUR_CODE" -o downloaded_file
|
||||
```
|
||||
|
||||
::: tip When Authentication Required
|
||||
If guest upload is disabled in admin panel (`openUpload=0`), you need to login first:
|
||||
|
||||
```bash
|
||||
# 1. Login to get token
|
||||
curl -X POST "http://localhost:12345/admin/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"password": "FileCodeBox2023"}'
|
||||
|
||||
# Returns: {"code":200,"msg":"success","detail":{"token":"xxx.xxx.xxx","token_type":"Bearer"}}
|
||||
|
||||
# 2. Upload file with token
|
||||
curl -X POST "http://localhost:12345/share/file/" \
|
||||
-H "Authorization: Bearer xxx.xxx.xxx" \
|
||||
-F "file=@/path/to/file.pdf"
|
||||
|
||||
# 3. Share text with token
|
||||
curl -X POST "http://localhost:12345/share/text/" \
|
||||
-H "Authorization: Bearer xxx.xxx.xxx" \
|
||||
-F "text=This is the text content to share"
|
||||
```
|
||||
:::
|
||||
|
||||
|
||||
## Chunked Upload API
|
||||
|
||||
|
||||
Reference in New Issue
Block a user