fix: duplicate res.json crash + missing try/catch in bans POST
This commit is contained in:
@@ -27,6 +27,7 @@ router.get('/min-duration', authenticate, async (req, res) => {
|
||||
});
|
||||
|
||||
router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
||||
try {
|
||||
const { player_name, player_uid, reason, type, duration, ticket_id, expires_at, source } = req.body;
|
||||
if (!player_name) return res.status(400).json({ error: '玩家名为必填' });
|
||||
|
||||
@@ -44,7 +45,10 @@ router.post('/', authenticate, requireRole('owner'), async (req, res) => {
|
||||
[ticket_id, req.user.id, `【处罚记录】${type==='ban'?'封禁':type==='mute'?'禁言':type==='warn'?'警告':'其他'}: ${player_name}${duration?' 时长:'+duration:''}${reason?' 原因:'+reason:''}`]);
|
||||
}
|
||||
res.status(201).json({ id: r.insertId });
|
||||
res.status(201).json({ id: r.insertId });
|
||||
} catch (err) {
|
||||
console.error('[bans]', err);
|
||||
res.status(500).json({ error: '添加失败: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.put('/:id', authenticate, requireRole('owner'), async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user