/* * 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 express = require('express'); const { query } = require('../db'); const { authenticate, requireRole } = require('../middleware/auth'); const router = express.Router(); // ---- 邮件日志(admin/owner 可查) ---- router.get('/emails', authenticate, requireRole('owner', 'admin'), async (req, res) => { try { const { status, email, limit } = req.query; let q = 'SELECT * FROM email_logs WHERE 1=1'; const p = []; if (status === 'sent' || status === 'failed') { q += ' AND status = ?'; p.push(status); } if (email) { q += ' AND to_email LIKE ?'; p.push(`%${email}%`); } q += ' ORDER BY id DESC LIMIT ?'; p.push(Math.min(parseInt(limit) || 100, 500)); const rows = await query(q, p); res.json(rows); } catch (e) { res.status(500).json({ error: e.message }); } }); // ---- 系统日志(admin/owner 可查) ---- router.get('/system', authenticate, requireRole('owner', 'admin'), async (req, res) => { try { const { level, source, limit } = req.query; let q = 'SELECT * FROM system_logs WHERE 1=1'; const p = []; if (['info', 'warn', 'error'].includes(level)) { q += ' AND level = ?'; p.push(level); } if (source) { q += ' AND source LIKE ?'; p.push(`%${source}%`); } q += ' ORDER BY id DESC LIMIT ?'; p.push(Math.min(parseInt(limit) || 100, 500)); const rows = await query(q, p); res.json(rows); } catch (e) { res.status(500).json({ error: e.message }); } }); module.exports = router;