- 52 JS files (backend + public/js): header with Copyright (C) 2026 Sea Network Technology Studio Author: CangLan <admin@sea-studio.top> + AGPLv3 notice - idempotent (skips if header present), all syntax-checked
48 lines
1.9 KiB
JavaScript
48 lines
1.9 KiB
JavaScript
/*
|
|
* MC Report System
|
|
* Copyright (C) 2026 Sea Network Technology Studio
|
|
* Author: CangLan <admin@sea-studio.top>
|
|
*
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
// 日志模块: 邮件日志 + 系统日志, 写入数据库供后台查看
|
|
// 所有写库操作 try/catch 包裹, 日志失败绝不影响主流程
|
|
const { query } = require('./db');
|
|
|
|
// 系统日志: level = info | warn | error
|
|
async function logSystem(level, source, message, details) {
|
|
try {
|
|
await query(
|
|
'INSERT INTO system_logs(level, source, message, details) VALUES (?,?,?,?)',
|
|
[level || 'info', String(source || '').slice(0, 50), String(message || '').slice(0, 2000),
|
|
details ? JSON.stringify(details).slice(0, 4000) : null]
|
|
);
|
|
} catch { /* 日志失败忽略 */ }
|
|
}
|
|
|
|
// 邮件日志: status = sent | failed
|
|
async function logEmail(to, templateCode, subject, status, error) {
|
|
try {
|
|
await query(
|
|
'INSERT INTO email_logs(to_email, template_code, subject, status, error) VALUES (?,?,?,?,?)',
|
|
[String(to || '').slice(0, 100), String(templateCode || '').slice(0, 50),
|
|
String(subject || '').slice(0, 255), status === 'sent' ? 'sent' : 'failed',
|
|
error ? String(error).slice(0, 2000) : null]
|
|
);
|
|
} catch { /* 日志失败忽略 */ }
|
|
}
|
|
|
|
module.exports = { logSystem, logEmail };
|