TRM-coding | 78aa966 | 2025-06-17 23:40:10 +0800 | [diff] [blame] | 1 | const BASE = 'http://10.126.59.25:5713' // 后端地址 |
| 2 | |
| 3 | /** |
| 4 | * 获取待审核的帖子列表 |
| 5 | * POST /apostlist |
| 6 | * @param {number|string} userId 平台管理员的用户 ID |
| 7 | * @returns Promise<[ {id, title, status}, … ]> |
| 8 | */ |
| 9 | export async function fetchPosts(userId) { |
| 10 | const res = await fetch(`${BASE}/apostlist`, { |
| 11 | method: 'POST', |
| 12 | headers: { 'Content-Type': 'application/json' }, |
| 13 | body: JSON.stringify({ userid: userId }) |
| 14 | }) |
| 15 | if (!res.ok) throw new Error(`fetchPosts: ${res.status}`) |
| 16 | return res.json() |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * 审核通过 |
| 21 | * POST /areview |
| 22 | */ |
| 23 | export async function approvePost(postId, userId) { |
| 24 | const res = await fetch(`${BASE}/areview`, { |
| 25 | method: 'POST', |
| 26 | headers: { 'Content-Type': 'application/json' }, |
| 27 | body: JSON.stringify({ userid: userId, postid: postId, status: 'published' }) |
| 28 | }) |
| 29 | if (!res.ok) throw new Error(`approvePost: ${res.status}`) |
| 30 | return res.json() |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * 驳回 |
| 35 | * POST /areview |
| 36 | */ |
| 37 | export async function rejectPost(postId, userId) { |
| 38 | const res = await fetch(`${BASE}/areview`, { |
| 39 | method: 'POST', |
| 40 | headers: { 'Content-Type': 'application/json' }, |
| 41 | body: JSON.stringify({ userid: userId, postid: postId, status: 'rejected' }) |
| 42 | }) |
| 43 | if (!res.ok) throw new Error(`rejectPost: ${res.status}`) |
| 44 | return res.json() |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * 获取单个帖子详情 |
| 49 | * POST /agetpost |
| 50 | * @param {number|string} postId 帖子 ID |
| 51 | * @param {number|string} userId 平台管理员的用户 ID |
| 52 | * @returns Promise<{id, title, content, status}> |
| 53 | */ |
| 54 | export async function fetchPost(postId, userId) { |
| 55 | const res = await fetch(`${BASE}/agetpost`, { |
| 56 | method: 'POST', |
| 57 | headers: { 'Content-Type': 'application/json' }, |
| 58 | body: JSON.stringify({ userid: userId, postid: postId }) |
| 59 | }) |
| 60 | if (!res.ok) throw new Error(`fetchPost: ${res.status}`) |
| 61 | return res.json() |
| 62 | } |