添加私信API
This commit is contained in:
1 parent
6489075781
commit
e74c3c35ea
1 file changed
+59
@@ -19,7 +19,9 @@ function apiFetch(path, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const API = {
|
const API = {
|
||||||
|
// ============================================================
|
||||||
// 认证
|
// 认证
|
||||||
|
// ============================================================
|
||||||
async login(email, password) {
|
async login(email, password) {
|
||||||
const data = await apiFetch('/auth/login', {
|
const data = await apiFetch('/auth/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -54,7 +56,9 @@ const API = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 帖子
|
// 帖子
|
||||||
|
// ============================================================
|
||||||
async getPosts(sort) {
|
async getPosts(sort) {
|
||||||
const data = await apiFetch('/posts?sort=' + (sort || 'latest'));
|
const data = await apiFetch('/posts?sort=' + (sort || 'latest'));
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -82,7 +86,9 @@ const API = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 回复
|
// 回复
|
||||||
|
// ============================================================
|
||||||
async getReplies(postId) {
|
async getReplies(postId) {
|
||||||
const data = await apiFetch('/posts/' + postId + '/replies');
|
const data = await apiFetch('/posts/' + postId + '/replies');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -104,7 +110,9 @@ const API = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 用户管理
|
// 用户管理
|
||||||
|
// ============================================================
|
||||||
async getUsers() {
|
async getUsers() {
|
||||||
const data = await apiFetch('/users');
|
const data = await apiFetch('/users');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -120,7 +128,9 @@ const API = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 举报
|
// 举报
|
||||||
|
// ============================================================
|
||||||
async getReports() {
|
async getReports() {
|
||||||
const data = await apiFetch('/reports');
|
const data = await apiFetch('/reports');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -145,14 +155,18 @@ const API = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 统计
|
// 统计
|
||||||
|
// ============================================================
|
||||||
async getStats() {
|
async getStats() {
|
||||||
const data = await apiFetch('/stats');
|
const data = await apiFetch('/stats');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 友情链接
|
// 友情链接
|
||||||
|
// ============================================================
|
||||||
async getLinks() {
|
async getLinks() {
|
||||||
const data = await apiFetch('/links');
|
const data = await apiFetch('/links');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -174,7 +188,9 @@ const API = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 事件日志
|
// 事件日志
|
||||||
|
// ============================================================
|
||||||
async getEventLogs() {
|
async getEventLogs() {
|
||||||
const data = await apiFetch('/event-logs');
|
const data = await apiFetch('/event-logs');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -190,7 +206,9 @@ const API = {
|
|||||||
} catch (e) { /* 静默失败 */ }
|
} catch (e) { /* 静默失败 */ }
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
// 论坛设置
|
// 论坛设置
|
||||||
|
// ============================================================
|
||||||
async getSettings() {
|
async getSettings() {
|
||||||
const data = await apiFetch('/settings');
|
const data = await apiFetch('/settings');
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
@@ -204,5 +222,46 @@ const API = {
|
|||||||
});
|
});
|
||||||
if (data.error) throw new Error(data.error);
|
if (data.error) throw new Error(data.error);
|
||||||
return data;
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user