/* * 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 ServersPage = { async render() { return '
'; }, async mount() { document.getElementById('page-title').textContent = '服务器管理'; document.getElementById('page-actions').innerHTML = Auth.isOwner() ? '' : ''; document.getElementById('btn-add-srv').onclick = () => this.showAdd(); await this.load(); }, async load() { const ct = document.getElementById('page-content'); try { const groups = await API.get('/polls/groups'); const grouped = {}; for (const g of groups) { if (!grouped[g.group_name]) grouped[g.group_name] = []; grouped[g.group_name].push(g); } ct.innerHTML = Object.keys(grouped).length === 0 ? '

暂无服务器分组

' : Object.entries(grouped).map(([group, servers]) => `
${U.esc(group)} ${servers.length} 个子服
${servers.map(s => `
${U.esc(s.server_name)} ${s.alias ? `${U.esc(s.alias)}` : ''} ${Auth.isOwner() ? `` : ''}
`).join('')}
`).join(''); } catch (e) { ct.innerHTML = `
${e.message}
`; } }, showAdd() { U.modal('添加服务器', `
外部 API 可用别名或「分组/子服名」定位此服务器
`); document.getElementById('add-srv-form').onsubmit = async e => { e.preventDefault(); try { await API.post('/polls/groups', { group_name: document.getElementById('as-group').value, server_name: document.getElementById('as-server').value, alias: document.getElementById('as-alias').value.trim(), }); App.closeModal(); this.load(); } catch(ex){alert(ex.message);} }; }, async showEdit(id) { try { const groups = await API.get('/polls/groups'); const s = groups.find(x => x.id === id); if (!s) return alert('未找到'); U.modal('编辑服务器', `
外部 API 可用别名或「分组/子服名」定位此服务器
`); document.getElementById('edit-srv-form').onsubmit = async e => { e.preventDefault(); try { await API.put(`/polls/groups/${id}`, { group_name: document.getElementById('es-group').value, server_name: document.getElementById('es-server').value, alias: document.getElementById('es-alias').value.trim(), }); App.closeModal(); this.load(); } catch(ex){alert(ex.message);} }; } catch (ex) { alert(ex.message); } }, async del(id) { if (!await U.confirm('确认删除?')) return; try { await API.req('DELETE', '/polls/groups/'+id); this.load(); } catch(ex){alert(ex.message);} } };