Update api.js
This commit is contained in:
1 parent
d381f5b033
commit
43a45162e1
1 file changed
+247
@@ -64,3 +64,250 @@ const API = {
|
|||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getPost(postId) {
|
||||||
|
const data = await apiFetch('/posts/' + postId);
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async createPost(title, content, images) {
|
||||||
|
const data = await apiFetch('/posts', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ title, content, images: images || [] })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async deletePost(postId) {
|
||||||
|
const data = await apiFetch('/posts/' + postId, { method: 'DELETE' });
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 回复
|
||||||
|
// ============================================================
|
||||||
|
async getReplies(postId) {
|
||||||
|
const data = await apiFetch('/posts/' + postId + '/replies');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async createReply(postId, content) {
|
||||||
|
const data = await apiFetch('/posts/' + postId + '/replies', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ content })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteReply(replyId) {
|
||||||
|
const data = await apiFetch('/replies/' + replyId, { method: 'DELETE' });
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 用户管理
|
||||||
|
// ============================================================
|
||||||
|
async getUsers() {
|
||||||
|
const data = await apiFetch('/users');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateUserRole(userId, role) {
|
||||||
|
const data = await apiFetch('/users/' + userId + '/role', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ role })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 举报
|
||||||
|
// ============================================================
|
||||||
|
async getReports() {
|
||||||
|
const data = await apiFetch('/reports');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async createReport(postId, reason) {
|
||||||
|
const data = await apiFetch('/reports', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ post_id: postId, reason })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateReport(reportId, status, note) {
|
||||||
|
const data = await apiFetch('/reports/' + reportId, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ status, note })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 统计
|
||||||
|
// ============================================================
|
||||||
|
async getStats() {
|
||||||
|
const data = await apiFetch('/stats');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 友情链接
|
||||||
|
// ============================================================
|
||||||
|
async getLinks() {
|
||||||
|
const data = await apiFetch('/links');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async addLink(title, url) {
|
||||||
|
const data = await apiFetch('/links', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ title, url })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteLink(id) {
|
||||||
|
const data = await apiFetch('/links/' + id, { method: 'DELETE' });
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 事件日志
|
||||||
|
// ============================================================
|
||||||
|
async getEventLogs() {
|
||||||
|
const data = await apiFetch('/event-logs');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async logEvent(action) {
|
||||||
|
try {
|
||||||
|
await apiFetch('/event-logs', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ action })
|
||||||
|
});
|
||||||
|
} catch (e) { /* 静默失败 */ }
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 论坛设置
|
||||||
|
// ============================================================
|
||||||
|
async getSettings() {
|
||||||
|
const data = await apiFetch('/settings');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateSettings(forum_name) {
|
||||||
|
const data = await apiFetch('/settings', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ forum_name })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 私信
|
||||||
|
// ============================================================
|
||||||
|
async getConversations() {
|
||||||
|
const data = await apiFetch('/conversations');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async getOrCreateConversation(other_user_id) {
|
||||||
|
const data = await apiFetch('/conversations', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ other_user_id })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async getMessages(conversationId) {
|
||||||
|
const data = await apiFetch('/conversations/' + conversationId + '/messages');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async sendMessage(conversationId, content) {
|
||||||
|
const data = await apiFetch('/conversations/' + conversationId + '/messages', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ content })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async markMessageRead(messageId) {
|
||||||
|
const data = await apiFetch('/messages/' + messageId + '/read', {
|
||||||
|
method: 'PUT'
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// 自定义页面
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
async getCustomPages() {
|
||||||
|
const data = await apiFetch('/custom-pages');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async getCustomPage(name) {
|
||||||
|
const data = await apiFetch('/custom-pages/' + encodeURIComponent(name));
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async getAdminCustomPages() {
|
||||||
|
const data = await apiFetch('/admin/custom-pages');
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async createCustomPage(name, title, content, sort_order) {
|
||||||
|
const data = await apiFetch('/admin/custom-pages', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ name, title, content, sort_order })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async updateCustomPage(id, title, content, sort_order, enabled) {
|
||||||
|
const data = await apiFetch('/admin/custom-pages/' + id, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ title, content, sort_order, enabled })
|
||||||
|
});
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteCustomPage(id) {
|
||||||
|
const data = await apiFetch('/admin/custom-pages/' + id, { method: 'DELETE' });
|
||||||
|
if (data.error) throw new Error(data.error);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in new issue
Block a user