feat(admin): implement P4 management console

This commit is contained in:
xqzp2026
2026-09-03 18:01:00 +09:30
parent 691b3a3713
commit b1dd68a14c
27 changed files with 3236 additions and 5 deletions
+26
View File
@@ -0,0 +1,26 @@
let csrfToken = ''
export function setCsrf(value) {
csrfToken = value || ''
}
export async function api(path, options = {}) {
const method = options.method || 'GET'
const response = await fetch(`/api/admin${path}`, {
credentials: 'same-origin',
...options,
headers: {
...(options.body ? { 'Content-Type': 'application/json' } : {}),
...(!['GET', 'HEAD'].includes(method) && csrfToken ? { 'X-CSRF-Token': csrfToken } : {}),
...options.headers,
},
})
if (!response.ok) {
let message = `请求失败(${response.status})`
try { message = (await response.json()).message || message } catch { /* empty response */ }
const error = new Error(message)
error.status = response.status
throw error
}
return response.status === 204 ? null : response.json()
}