/* * 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)}
`}
使用流程: 创建客户端后, 用 Client ID + SecretPOST /api/external/auth/session 换取 SESSION, 之后所有接口用 Authorization: Bearer <SESSION>。完整说明见右上角「接口文档」。
`; } 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);} } };