refactor: 统一代码风格并迁移至 ESLint 新配置

style(backend): 格式化模型文件代码
style(frontend): 调整组件代码格式
chore: 删除旧 ESLint 配置并添加新配置
refactor(backend): 重构模型定义语法
style: 统一箭头函数和对象属性简写
This commit is contained in:
zhang1106
2026-03-27 19:12:16 +08:00
parent 6a8d4144ff
commit 63f0cb570e
166 changed files with 15483 additions and 11170 deletions
+42 -29
View File
@@ -1,10 +1,9 @@
const BackupLog = require('../models/BackupLog');
const fs = require('fs');
async function createLogEntry(options) {
const { logType, description, backupType, includeFiles, compressed } = options;
try {
const log = await BackupLog.create({
logType: logType || 'manual',
@@ -13,7 +12,7 @@ async function createLogEntry(options) {
backupType: backupType || 'full',
includeFiles: includeFiles || false,
compressed: compressed || false,
startTime: new Date()
startTime: new Date(),
});
return log;
} catch (error) {
@@ -25,30 +24,40 @@ async function createLogEntry(options) {
async function updateLogStatus(logId, status, options = {}) {
try {
const updateData = { status };
if (status === 'running') {
updateData.startTime = new Date();
}
if (status === 'success' || status === 'failed') {
updateData.endTime = new Date();
const log = await BackupLog.findByPk(logId);
if (log && log.startTime) {
updateData.duration = new Date() - new Date(log.startTime);
}
}
if (options.filename) updateData.filename = options.filename;
if (options.filePath) updateData.filePath = options.filePath;
if (options.fileSize) updateData.fileSize = options.fileSize;
if (options.errorMessage) updateData.errorMessage = options.errorMessage;
if (options.remoteUploads) updateData.remoteUploads = options.remoteUploads;
if (options.filename) {
updateData.filename = options.filename;
}
if (options.filePath) {
updateData.filePath = options.filePath;
}
if (options.fileSize) {
updateData.fileSize = options.fileSize;
}
if (options.errorMessage) {
updateData.errorMessage = options.errorMessage;
}
if (options.remoteUploads) {
updateData.remoteUploads = options.remoteUploads;
}
await BackupLog.update(updateData, {
where: { id: logId }
where: { id: logId },
});
return true;
} catch (error) {
console.error('更新备份日志失败:', error);
@@ -60,25 +69,29 @@ async function getBackupLogs(options = {}) {
try {
const { page = 1, pageSize = 20, logType, status } = options;
const where = {};
if (logType) where.logType = logType;
if (status) where.status = status;
if (logType) {
where.logType = logType;
}
if (status) {
where.status = status;
}
const offset = (page - 1) * pageSize;
const { count, rows } = await BackupLog.findAndCountAll({
where,
order: [['createdAt', 'DESC']],
limit: pageSize,
offset
offset,
});
return {
logs: rows,
total: count,
page,
pageSize,
totalPages: Math.ceil(count / pageSize)
totalPages: Math.ceil(count / pageSize),
};
} catch (error) {
console.error('获取备份日志失败:', error);
@@ -99,15 +112,15 @@ async function deleteOldLogs(days = 30) {
try {
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - days);
const deletedCount = await BackupLog.destroy({
where: {
createdAt: {
[require('sequelize').Op.lt]: cutoffDate
}
}
[require('sequelize').Op.lt]: cutoffDate,
},
},
});
console.log(`删除了 ${deletedCount} 条旧备份日志`);
return deletedCount;
} catch (error) {
@@ -121,5 +134,5 @@ module.exports = {
updateLogStatus,
getBackupLogs,
getBackupLogById,
deleteOldLogs
deleteOldLogs,
};