feat: add user role system and public joke submission API
- Add AdminUser role field (admin/submitter) - User management in admin panel - Public joke submission API (no auth required) - Document submission methods for external workers Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ceed63fcb0
commit
aecf1f1f15
@@ -0,0 +1,203 @@
|
||||
# 笑话提交接口文档
|
||||
|
||||
## 接口地址
|
||||
|
||||
```
|
||||
基础地址:http://39.104.58.51
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 提交笑话
|
||||
|
||||
### 接口 1:单条提交
|
||||
|
||||
```
|
||||
POST /api/jokes/submit
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X POST http://39.104.58.51/api/jokes/submit \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"title":"笑话标题","content":"笑话内容..."}'
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{"success":true,"id":1280,"message":"已提交,ID: 1280"}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 接口 2:批量提交
|
||||
|
||||
```
|
||||
POST /api/jokes/submit/batch
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
**请求示例:**
|
||||
|
||||
```bash
|
||||
curl -X POST http://39.104.58.51/api/jokes/submit/batch \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jokes": [
|
||||
{"title":"标题1","content":"内容1"},
|
||||
{"title":"标题2","content":"内容2"},
|
||||
{"title":"标题3","content":"内容3"}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
**响应示例:**
|
||||
```json
|
||||
{"success":true,"count":3,"message":"已提交 3 条笑话"}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 编程语言示例
|
||||
|
||||
### Python
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
BASE_URL = "http://39.104.58.51"
|
||||
|
||||
# 单条提交
|
||||
def submit_joke(title, content):
|
||||
resp = requests.post(f"{BASE_URL}/api/jokes/submit", json={
|
||||
"title": title,
|
||||
"content": content
|
||||
})
|
||||
return resp.json()
|
||||
|
||||
# 批量提交
|
||||
def submit_jokes_batch(jokes):
|
||||
resp = requests.post(f"{BASE_URL}/api/jokes/submit/batch", json={
|
||||
"jokes": jokes # jokes 是 [{"title":..., "content":...}, ...]
|
||||
})
|
||||
return resp.json()
|
||||
|
||||
|
||||
# 使用示例
|
||||
if __name__ == "__main__":
|
||||
# 单条
|
||||
result = submit_joke("标题", "内容")
|
||||
|
||||
# 批量
|
||||
jokes = [
|
||||
{"title": "笑话1", "content": "内容1"},
|
||||
{"title": "笑话2", "content": "内容2"},
|
||||
{"title": "笑话3", "content": "内容3"},
|
||||
]
|
||||
result = submit_jokes_batch(jokes)
|
||||
print(result)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### JavaScript / Node.js
|
||||
|
||||
```javascript
|
||||
const BASE_URL = "http://39.104.58.51";
|
||||
|
||||
// 单条提交
|
||||
async function submitJoke(title, content) {
|
||||
const resp = await fetch(`${BASE_URL}/api/jokes/submit`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ title, content })
|
||||
});
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
// 批量提交
|
||||
async function submitJokesBatch(jokes) {
|
||||
const resp = await fetch(`${BASE_URL}/api/jokes/submit/batch`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ jokes })
|
||||
});
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
(async () => {
|
||||
// 单条
|
||||
console.log(await submitJoke("标题", "内容"));
|
||||
|
||||
// 批量
|
||||
const jokes = [
|
||||
{ title: "笑话1", content: "内容1" },
|
||||
{ title: "笑话2", content: "内容2" },
|
||||
];
|
||||
console.log(await submitJokesBatch(jokes));
|
||||
})();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Java
|
||||
|
||||
```java
|
||||
import java.net.http.*;
|
||||
import java.net.URI;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
public class JokeSubmit {
|
||||
static final String BASE_URL = "http://39.104.58.51";
|
||||
|
||||
public static String post(String path, String body) throws Exception {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(BASE_URL + path))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
return client.send(request, HttpResponse.BodyHandlers.ofString()).body();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// 单条提交
|
||||
System.out.println(post("/api/jokes/submit",
|
||||
"{\"title\":\"标题\",\"content\":\"内容\"}"));
|
||||
|
||||
// 批量提交
|
||||
String batch = """
|
||||
{"jokes":[
|
||||
{"title":"笑话1","content":"内容1"},
|
||||
{"title":"笑话2","content":"内容2"}
|
||||
]}""";
|
||||
System.out.println(post("/api/jokes/submit/batch", batch));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **无需登录**:此接口公开,无需认证即可提交
|
||||
2. **自动审核**:提交后笑话进入「待审核」状态
|
||||
3. **字段说明**:
|
||||
- `title`:笑话标题(必填)
|
||||
- `content`:笑话正文(必填)
|
||||
4. **批量限制**:建议单次不超过 100 条
|
||||
5. **编码**:确保使用 UTF-8 编码
|
||||
|
||||
---
|
||||
|
||||
## 状态码
|
||||
|
||||
| 状态码 | 说明 |
|
||||
|--------|------|
|
||||
| 200 | 提交成功 |
|
||||
| 400 | 请求格式错误 |
|
||||
| 500 | 服务器内部错误 |
|
||||
Reference in New Issue
Block a user