-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_apis.html
More file actions
164 lines (143 loc) · 10.3 KB
/
Copy pathtest_apis.html
File metadata and controls
164 lines (143 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API 全接口展示 - GoBlog</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body class="container">
<header>
<h1>API 全功能展示台</h1>
<nav>
<ul>
<li><a href="index.html">返回首页</a></li>
<li><a href="admin_dashboard.html">返回管理员后台</a></li>
<li><a href="user/dashboard.html">返回用户控制台</a></li>
</ul>
</nav>
</header>
<main>
<section id="api-showcase">
<p>此页面旨在展示并实现文档中所有其余未在核心页面展示的 API 接口。</p>
<details>
<summary><strong>1. 日志模块 (Logs)</strong></summary>
<button onclick="testLogList()">获取日志列表 (GET /api/logs)</button>
<button onclick="testLogRead(1)">标记日志已读 (GET /api/logs/:id)</button>
<button onclick="testLogDelete([1])">删除日志 (DELETE /api/logs)</button>
</details>
<details>
<summary><strong>2. 图片模块 (Images)</strong></summary>
<form onsubmit="event.preventDefault(); testImageUpload();">
<input type="file" id="img-file" required>
<button type="submit">上传图片 (POST /api/image)</button>
</form>
<button onclick="testImageList()">图片列表 (GET /api/images)</button>
<button onclick="testImageDelete([1])">删除图片 (DELETE /api/image)</button>
<a href="/api/image?id=1" target="_blank">获取图片文件 (GET /api/image?id=1)</a>
</details>
<details>
<summary><strong>3. 验证码模块 (Captcha)</strong></summary>
<button onclick="testCaptcha()">获取图形验证码 (GET /api/captcha)</button>
</details>
<details>
<summary><strong>4. 用户扩展模块 (User Extra)</strong></summary>
<button onclick="testSendEmail()">发送邮箱验证码 (POST /api/user/send_email)</button>
<button onclick="testResetEmail()">重置邮箱 (PUT /api/user/resetEmail)</button>
<button onclick="testLoginLog()">登录日志列表 (GET /api/user/loginlog)</button>
<button onclick="testRefreshToken()">刷新Token (POST /api/user/token)</button>
</details>
<details>
<summary><strong>5. 文章审核与管理扩展 (Article Extra)</strong></summary>
<button onclick="testAdminUntop(2, 1)">管理员取消他人置顶 (DELETE /api/article/admingTop)</button>
<button onclick="testArticleReviewList()">审核文章列表 (GET /api/article/review)</button>
<button onclick="testArticleReview(1)">审核文章 (POST /api/article/review/:id)</button>
<button onclick="testAdminDeleteArticle([1])">管理员删除文章 (DELETE /api/article/admin)</button>
</details>
<details>
<summary><strong>6. 浏览记录与分类 (History & Category)</strong></summary>
<button onclick="testHistoryList()">浏览记录列表 (GET /api/article/history)</button>
<button onclick="testHistoryDelete([1])">删除浏览记录 (DELETE /api/article/history)</button>
<button onclick="testCategoryList()">分类列表 (GET /api/article/category)</button>
<button onclick="testCategoryCreate()">创建分类 (POST /api/article/category)</button>
<button onclick="testCategoryDelete([1])">删除分类 (DELETE /api/article/category)</button>
</details>
<details>
<summary><strong>7. 收藏夹管理 (Collection)</strong></summary>
<button onclick="testCollectFolderList()">收藏夹列表 (GET /api/article/collect/folder)</button>
<button onclick="testCollectList()">收藏夹文章列表 (GET /api/article/collect/list)</button>
<button onclick="testCollectFolderCreate()">创建收藏夹 (POST /api/article/collect/folder)</button>
<button onclick="testCollectFolderUpdate()">更新收藏夹 (PUT /api/article/collect/folder)</button>
<button onclick="testCollectFolderDelete([1])">删除收藏夹 (DELETE /api/article/collect/folder)</button>
</details>
<details>
<summary><strong>8. 消息与聊天模块 (Message & Chat)</strong></summary>
<button onclick="testMsgConf()">消息配置 (GET /api/msg/conf)</button>
<button onclick="testMsgConfUpdate()">更新消息配置 (POST /api/msg/conf/update)</button>
<button onclick="testChatSession()">会话列表 (GET /api/chat/session)</button>
<button onclick="testChatGet(2)">聊天记录 (GET /api/chat/get)</button>
<button onclick="testChatSend(2)">发送消息 (POST /api/chat/send)</button>
</details>
<div id="test-result" style="margin-top: 20px; border: 1px solid #000; padding: 10px; background: #f0f0f0;">
<p>测试结果将显示在这里...</p>
</div>
</section>
</main>
<hr>
<footer>
<p>© 2024 GoBlog. Powered by Semantic HTML. <a href="#">返回顶部</a></p>
</footer>
<script src="js/api.js"></script>
<script>
const resBox = document.getElementById('test-result');
function showRes(res) {
resBox.innerHTML = `<pre>${JSON.stringify(res, null, 2)}</pre>`;
}
// 1. Logs
async function testLogList() { showRes(await fetchAPI('/logs?page=1&limit=10')); }
async function testLogRead(id) { showRes(await fetchAPI(`/logs/${id}`)); }
async function testLogDelete(ids) { showRes(await fetchAPI('/logs', { method: 'DELETE', body: { IDList: ids } })); }
// 2. Images
async function testImageUpload() {
const file = document.getElementById('img-file').files[0];
if (!file) return alert('请选择文件');
const fd = new FormData();
fd.append('file', file);
showRes(await fetchAPI('/image', { method: 'POST', body: fd }));
}
async function testImageList() { showRes(await fetchAPI('/images?page=1&limit=10')); }
async function testImageDelete(ids) { showRes(await fetchAPI('/image', { method: 'DELETE', body: { IDlist: ids } })); }
// 3. Captcha
async function testCaptcha() { showRes(await fetchAPI('/captcha?target=注册')); }
// 4. User
async function testSendEmail() { showRes(await fetchAPI('/user/send_email', { method: 'POST', body: { type: '注册', email: 'test@example.com', captchaID: '', captchaCode: '' } })); }
async function testResetEmail() { showRes(await fetchAPI('/user/resetEmail', { method: 'PUT', body: { ResetEmailID: '', ResetEmailCode: '', emailID: '', emailCode: '' } })); }
async function testLoginLog() { showRes(await fetchAPI('/user/loginlog?type=user&page=1&limit=10')); }
async function testRefreshToken() { showRes(await fetchAPI('/user/token', { method: 'POST', headers: { 'Authorization': 'Bearer ' + localStorage.getItem('refreshToken') } })); }
// 5. Article Extra
async function testAdminUntop(uid, aid) { showRes(await fetchAPI('/article/admingTop', { method: 'DELETE', body: { userID: uid, articleID: aid } })); }
async function testArticleReviewList() { showRes(await fetchAPI('/article/review?page=1&limit=10')); }
async function testArticleReview(id) { showRes(await fetchAPI(`/article/review/${id}`, { method: 'POST', body: { articleID: id, status: 2, msg: '通过' } })); }
async function testAdminDeleteArticle(ids) { showRes(await fetchAPI('/article/admin', { method: 'DELETE', body: { IDList: ids } })); }
// 6. History & Category
async function testHistoryList() { showRes(await fetchAPI('/article/history?type=user&page=1&limit=10')); }
async function testHistoryDelete(ids) { showRes(await fetchAPI('/article/history', { method: 'DELETE', body: { IDList: ids } })); }
async function testCategoryList() { showRes(await fetchAPI('/article/category?type=self&page=1&limit=10')); }
async function testCategoryCreate() { showRes(await fetchAPI('/article/category', { method: 'POST', body: { id: 0, title: '测试分类' } })); }
async function testCategoryDelete(ids) { showRes(await fetchAPI('/article/category', { method: 'DELETE', body: { IDList: ids } })); }
// 7. Collect Folder
async function testCollectFolderList() { showRes(await fetchAPI('/article/collect/folder?id=1&page=1&limit=10')); }
async function testCollectList() { showRes(await fetchAPI('/article/collect/list?id=1&page=1&limit=10')); }
async function testCollectFolderCreate() { showRes(await fetchAPI('/article/collect/folder', { method: 'POST', body: { title: '测试夹', abstract: '', cover: '' } })); }
async function testCollectFolderUpdate() { showRes(await fetchAPI('/article/collect/folder', { method: 'PUT', body: { id: 1, title: '更新夹', abstract: '', cover: '' } })); }
async function testCollectFolderDelete(ids) { showRes(await fetchAPI('/article/collect/folder', { method: 'DELETE', body: { IDList: ids } })); }
// 8. Message & Chat
async function testMsgConf() { showRes(await fetchAPI('/msg/conf')); }
async function testMsgConfUpdate() { showRes(await fetchAPI('/msg/conf/update', { method: 'POST', body: { openCommentMessage: true, openReplyMessage: true, openDiggMessage: true, openCollectMessage: true, openPrivateMessage: true } })); }
async function testChatSession() { showRes(await fetchAPI('/chat/session?page=1&limit=10')); }
async function testChatGet(uid) { showRes(await fetchAPI(`/chat/get?userID=${uid}&page=1&limit=10`)); }
async function testChatSend(uid) { showRes(await fetchAPI('/chat/send', { method: 'POST', body: { revUserID: uid, msg: { textMsg: { content: 'hello' } } } })); }
</script>
</body>
</html>