fix: add source field to bans + display in list
This commit is contained in:
@@ -254,6 +254,7 @@ async function initSchema(connection) {
|
|||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
player_name VARCHAR(50) NOT NULL,
|
player_name VARCHAR(50) NOT NULL,
|
||||||
player_uid VARCHAR(50),
|
player_uid VARCHAR(50),
|
||||||
|
source VARCHAR(10) DEFAULT '',
|
||||||
reason TEXT,
|
reason TEXT,
|
||||||
type ENUM('ban','mute','warn','other') NOT NULL DEFAULT 'ban',
|
type ENUM('ban','mute','warn','other') NOT NULL DEFAULT 'ban',
|
||||||
duration VARCHAR(20) DEFAULT '',
|
duration VARCHAR(20) DEFAULT '',
|
||||||
@@ -287,7 +288,8 @@ async function migrateAdditions(db) {
|
|||||||
try { await db.execute("ALTER TABLE tickets MODIFY status ENUM('pending','processing','awaiting_info','appealing','resolved','rejected','closed') NOT NULL"); } catch {}
|
try { await db.execute("ALTER TABLE tickets MODIFY status ENUM('pending','processing','awaiting_info','appealing','resolved','rejected','closed') NOT NULL"); } catch {}
|
||||||
try { await db.execute("ALTER TABLE users ADD COLUMN source ENUM('netease','skin') NOT NULL DEFAULT 'netease'"); } catch {}
|
try { await db.execute("ALTER TABLE users ADD COLUMN source ENUM('netease','skin') NOT NULL DEFAULT 'netease'"); } catch {}
|
||||||
try { await db.execute(`CREATE TABLE IF NOT EXISTS user_servers (user_id INT NOT NULL, group_name VARCHAR(100) NOT NULL, server_name VARCHAR(100) NOT NULL, UNIQUE KEY uk_user_server (user_id, group_name, server_name), INDEX idx_user (user_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
try { await db.execute(`CREATE TABLE IF NOT EXISTS user_servers (user_id INT NOT NULL, group_name VARCHAR(100) NOT NULL, server_name VARCHAR(100) NOT NULL, UNIQUE KEY uk_user_server (user_id, group_name, server_name), INDEX idx_user (user_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
||||||
try { await db.execute(`CREATE TABLE IF NOT EXISTS bans (id INT AUTO_INCREMENT PRIMARY KEY, player_name VARCHAR(50) NOT NULL, player_uid VARCHAR(50), reason TEXT, type ENUM('ban','mute','warn','other') NOT NULL DEFAULT 'ban', duration VARCHAR(20) DEFAULT '', ticket_id INT, created_by INT, status ENUM('active','expired','appealed','lifted') NOT NULL DEFAULT 'active', created_at DATETIME DEFAULT CURRENT_TIMESTAMP, expires_at DATETIME) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
try { await db.execute(`CREATE TABLE IF NOT EXISTS bans (id INT AUTO_INCREMENT PRIMARY KEY, player_name VARCHAR(50) NOT NULL, player_uid VARCHAR(50), source VARCHAR(10) DEFAULT '', reason TEXT, type ENUM('ban','mute','warn','other') NOT NULL DEFAULT 'ban', duration VARCHAR(20) DEFAULT '', ticket_id INT, created_by INT, status ENUM('active','expired','appealed','lifted') NOT NULL DEFAULT 'active', created_at DATETIME DEFAULT CURRENT_TIMESTAMP, expires_at DATETIME) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
||||||
|
try { await db.execute("ALTER TABLE bans ADD COLUMN source VARCHAR(10) DEFAULT ''"); } catch {}
|
||||||
|
|
||||||
try { await db.execute(`CREATE TABLE IF NOT EXISTS polls (id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(200) NOT NULL, description TEXT, options JSON NOT NULL, group_name VARCHAR(100) NOT NULL DEFAULT '', server_name VARCHAR(100) NOT NULL DEFAULT '', start_time DATETIME, end_time DATETIME, active TINYINT(1) NOT NULL DEFAULT 1, created_by INT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, INDEX idx_active (active), INDEX idx_group_server (group_name, server_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
try { await db.execute(`CREATE TABLE IF NOT EXISTS polls (id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(200) NOT NULL, description TEXT, options JSON NOT NULL, group_name VARCHAR(100) NOT NULL DEFAULT '', server_name VARCHAR(100) NOT NULL DEFAULT '', start_time DATETIME, end_time DATETIME, active TINYINT(1) NOT NULL DEFAULT 1, created_by INT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, INDEX idx_active (active), INDEX idx_group_server (group_name, server_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
||||||
try { await db.execute(`CREATE TABLE IF NOT EXISTS poll_votes (id INT AUTO_INCREMENT PRIMARY KEY, poll_id INT NOT NULL, user_id INT NOT NULL, option_index INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_poll_user (poll_id, user_id), INDEX idx_poll (poll_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
try { await db.execute(`CREATE TABLE IF NOT EXISTS poll_votes (id INT AUTO_INCREMENT PRIMARY KEY, poll_id INT NOT NULL, user_id INT NOT NULL, option_index INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_poll_user (poll_id, user_id), INDEX idx_poll (poll_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ router.get('/min-duration', authenticate, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
||||||
const { player_name, player_uid, reason, type, duration, ticket_id, expires_at } = req.body;
|
const { player_name, player_uid, reason, type, duration, ticket_id, expires_at, source } = req.body;
|
||||||
if (!player_name) return res.status(400).json({ error: '玩家名为必填' });
|
if (!player_name) return res.status(400).json({ error: '玩家名为必填' });
|
||||||
|
|
||||||
const durDays = parseDuration(duration);
|
const durDays = parseDuration(duration);
|
||||||
@@ -37,8 +37,8 @@ router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
|||||||
return res.status(400).json({ error: `该玩家已有${parseDuration(prev.duration)}天处罚记录,新处罚时长不可少于上次(需 ≥ ${parseDuration(prev.duration)}天)` });
|
return res.status(400).json({ error: `该玩家已有${parseDuration(prev.duration)}天处罚记录,新处罚时长不可少于上次(需 ≥ ${parseDuration(prev.duration)}天)` });
|
||||||
}
|
}
|
||||||
|
|
||||||
const r = await query('INSERT INTO bans(player_name, player_uid, reason, type, duration, ticket_id, created_by, expires_at) VALUES (?,?,?,?,?,?,?,?)',
|
const r = await query('INSERT INTO bans(player_name, player_uid, source, reason, type, duration, ticket_id, created_by, expires_at) VALUES (?,?,?,?,?,?,?,?,?)',
|
||||||
[player_name, player_uid||'', reason||'', type||'ban', duration||'', ticket_id||null, req.user.id, expires_at||null]);
|
[player_name, player_uid||'', source||'', reason||'', type||'ban', duration||'', ticket_id||null, req.user.id, expires_at||null]);
|
||||||
if (ticket_id) {
|
if (ticket_id) {
|
||||||
await query("INSERT INTO responses(ticket_id, user_id, content, is_staff) VALUES (?,?,?,1)",
|
await query("INSERT INTO responses(ticket_id, user_id, content, is_staff) VALUES (?,?,?,1)",
|
||||||
[ticket_id, req.user.id, `【处罚记录】${type==='ban'?'封禁':type==='mute'?'禁言':type==='warn'?'警告':'其他'}: ${player_name}${duration?' 时长:'+duration:''}${reason?' 原因:'+reason:''}`]);
|
[ticket_id, req.user.id, `【处罚记录】${type==='ban'?'封禁':type==='mute'?'禁言':type==='warn'?'警告':'其他'}: ${player_name}${duration?' 时长:'+duration:''}${reason?' 原因:'+reason:''}`]);
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ const BansPage = {
|
|||||||
|
|
||||||
ct.innerHTML = bans.length === 0
|
ct.innerHTML = bans.length === 0
|
||||||
? '<div class="empty"><i class="fas fa-ban"></i><p>暂无封禁记录</p></div>'
|
? '<div class="empty"><i class="fas fa-ban"></i><p>暂无封禁记录</p></div>'
|
||||||
: `<div class="card table-wrap"><table><thead><tr><th>玩家</th><th>UID</th><th>类型</th><th>原因</th><th>时长</th><th>状态</th><th>时间</th>${Auth.isOwner()?'<th>操作</th>':''}</tr></thead><tbody>${bans.map(b => `
|
: `<div class="card table-wrap"><table><thead><tr><th>玩家</th><th>UID</th><th>来源</th><th>类型</th><th>原因</th><th>时长</th><th>状态</th><th>时间</th>${Auth.isOwner()?'<th>操作</th>':''}</tr></thead><tbody>${bans.map(b => `
|
||||||
<tr>
|
<tr>
|
||||||
<td>${isStaff ? U.esc(b.player_name) : maskName(b.player_name)}</td>
|
<td>${isStaff ? U.esc(b.player_name) : maskName(b.player_name)}</td>
|
||||||
<td class="ts">${isStaff ? U.esc(b.player_uid||'-') : maskUid(b.player_uid)}</td>
|
<td class="ts">${isStaff ? U.esc(b.player_uid||'-') : maskUid(b.player_uid)}</td>
|
||||||
|
<td class="ts">${b.source==='netease'?'网易':b.source==='skin'?'皮肤站':b.source||'-'}</td>
|
||||||
<td>${b.type==='ban'?'<span class="badge bg-urgent">封禁</span>':b.type==='mute'?'<span class="badge bg-medium">禁言</span>':'<span class="badge bg-player">警告</span>'}</td>
|
<td>${b.type==='ban'?'<span class="badge bg-urgent">封禁</span>':b.type==='mute'?'<span class="badge bg-medium">禁言</span>':'<span class="badge bg-player">警告</span>'}</td>
|
||||||
<td class="ts">${U.esc((b.reason||'').substring(0,50))}</td>
|
<td class="ts">${U.esc((b.reason||'').substring(0,50))}</td>
|
||||||
<td>${b.duration||'永久'}</td>
|
<td>${b.duration||'永久'}</td>
|
||||||
@@ -37,7 +38,7 @@ const BansPage = {
|
|||||||
U.modal('添加封禁', `
|
U.modal('添加封禁', `
|
||||||
<form id="ban-form">
|
<form id="ban-form">
|
||||||
<div class="grid-2"><div class="form-group"><label>玩家名 *</label><input id="ban-name" required></div><div class="form-group"><label>UID</label><input id="ban-uid"></div></div>
|
<div class="grid-2"><div class="form-group"><label>玩家名 *</label><input id="ban-name" required></div><div class="form-group"><label>UID</label><input id="ban-uid"></div></div>
|
||||||
<div class="grid-2"><div class="form-group"><label>类型</label><select id="ban-type" onchange="BansPage.checkMinDuration()"><option value="ban">封禁</option><option value="mute">禁言</option><option value="warn">警告</option></select></div><div class="form-group"><label>时长</label><select id="ban-dur"><option value="">永久</option><option value="3天">3天</option><option value="7天">7天</option><option value="30天">30天</option></select></div></div>
|
<div class="grid-2"><div class="form-group"><label>来源</label><select id="ban-source"><option value="">未知</option><option value="netease">网易端</option><option value="skin">皮肤站</option></select></div><div class="form-group"><label>类型</label><select id="ban-type" onchange="BansPage.checkMinDuration()"><option value="ban">封禁</option><option value="mute">禁言</option><option value="warn">警告</option></select></div></div>
|
||||||
<div class="form-group"><label>原因</label><textarea id="ban-reason" rows="2"></textarea></div>
|
<div class="form-group"><label>原因</label><textarea id="ban-reason" rows="2"></textarea></div>
|
||||||
<div class="modal-f"><button type="button" class="btn btn-o" data-action="App:closeModal">取消</button><button type="submit" class="btn btn-p">添加</button></div>
|
<div class="modal-f"><button type="button" class="btn btn-o" data-action="App:closeModal">取消</button><button type="submit" class="btn btn-p">添加</button></div>
|
||||||
</form>
|
</form>
|
||||||
@@ -45,7 +46,7 @@ const BansPage = {
|
|||||||
document.getElementById('ban-form').onsubmit = async e => {
|
document.getElementById('ban-form').onsubmit = async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await API.post('/bans', { player_name: document.getElementById('ban-name').value, player_uid: document.getElementById('ban-uid').value, type: document.getElementById('ban-type').value, duration: document.getElementById('ban-dur').value, reason: document.getElementById('ban-reason').value });
|
await API.post('/bans', { player_name: document.getElementById('ban-name').value, player_uid: document.getElementById('ban-uid').value, source: document.getElementById('ban-source').value, type: document.getElementById('ban-type').value, duration: document.getElementById('ban-dur').value, reason: document.getElementById('ban-reason').value });
|
||||||
App.closeModal(); this.load();
|
App.closeModal(); this.load();
|
||||||
} catch(ex) { alert(ex.message); }
|
} catch(ex) { alert(ex.message); }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user