/* * MC Report System * Copyright (C) 2026 Sea Network Technology Studio * Author: CangLan * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ const ExternalApiPage = { async render() { return '
'; }, async mount() { document.getElementById('page-title').textContent = '外部API'; document.getElementById('page-actions').innerHTML = ''; await this.load(); }, async load() { const ct = document.getElementById('page-content'); try { const clients = await API.get('/external/clients'); ct.innerHTML = `
API 客户端
${clients.length === 0 ? '

暂无客户端

' : `
${clients.map(c => ` `).join('')}
#名称Client ID状态创建时间操作
${c.id} ${U.esc(c.name)} ${U.esc(c.client_id)} ${c.active ? '启用' : '停用'} ${U.date(c.created_at)}
`}
鉴权流程: 先调 POST /api/external/auth/sessionx-api-client-id + x-api-secret 换取 SESSION(24小时有效), 之后所有接口请求头用 Authorization: Bearer <SESSION>。secret 仅创建时显示一次,请立即保存。
接口速览(除换取SESSION外, 均需 Bearer SESSION)
方法路径说明
POST/api/external/auth/sessionID+Secret 换取 SESSION(唯一使用 ID+Secret 的接口)
POST/api/external/auth/register插件注册账号(需 SESSION)
POST/api/external/tickets提交工单(举报/建议/申诉),返回 id + tracking_token;可带 server(别名或「分组/子服」)
GET/api/external/tickets/track?token=xxx按追踪码查工单状态 + 回复,从提交到结束全程可查
GET/api/external/all-tickets?server=&status=&type=&page=&limit=工单列表(可按子服过滤)
GET/api/external/all-tickets/:id工单详情(含回复/附件)
GET/api/external/bans?server=&status=&player=拉取封禁列表
POST/api/external/bans新增封禁(可带 server)
GET/api/external/reported-players?server=被举报人统计
GET/api/external/servers服务器列表(含别名)
GET/api/external/stats?server=工单统计
POST/api/external/clients创建客户端(需登录态, 本页操作)

完整请求/响应示例见 docs/API.md 外部API章节。

`; } catch (e) { ct.innerHTML = `
${e.message}
`; } }, async showCreate() { U.modal('创建 API 客户端', `
`); document.getElementById('apikey-form').onsubmit = async e => { e.preventDefault(); try { const r = await API.post('/external/clients', { name: document.getElementById('ak-name').value }); App.closeModal(); U.modal('客户端已创建', `

请立即保存以下凭据(secret 只显示一次):

Client ID: ${U.esc(r.client_id)}
Secret: ${U.esc(r.secret)}
`); this.load(); } catch(ex){alert(ex.message);} }; }, async toggle(id, active) { try { await API.put(`/external/clients/${id}`, { active: !!active }); this.load(); } catch(ex){alert(ex.message);} }, async del(id) { if (!await U.confirm('确认删除该客户端?')) return; try { await API.delete(`/external/clients/${id}`); this.load(); } catch(ex){alert(ex.message);} } };