fix(remote-backup): 移除调试日志并改进协议类型验证

refactor(migrations): 添加设备字段options配置迁移
This commit is contained in:
zhang1106
2026-03-23 11:09:36 +08:00
parent 66807b1660
commit f51c39284b
3 changed files with 81 additions and 36 deletions
+4 -13
View File
@@ -802,7 +802,6 @@ router.delete('/remote/targets/:id', (req, res) => {
router.post('/remote/test', async (req, res) => {
try {
const config = req.body;
console.log(`[RemoteBackup] 收到连接测试请求:`, JSON.stringify(config));
if (!config.host || !config.port || !config.username) {
return res.status(400).json({
@@ -812,21 +811,13 @@ router.post('/remote/test', async (req, res) => {
}
if (!config.protocol) {
const port = parseInt(config.port);
if (port === 22 || port === 2222) {
config.protocol = 'sftp';
} else if (port === 445 || port === 139 || port === 443) {
config.protocol = 'smb';
} else if (port === 80 || port === 443 || config.url) {
config.protocol = 'webdav';
} else {
config.protocol = 'ftp';
}
console.log(`[RemoteBackup] 推断协议类型: ${config.protocol} (基于端口 ${config.port})`);
return res.status(400).json({
success: false,
message: '请提供协议类型(protocol',
});
}
const result = await testRemoteConnection(config);
console.log(`[RemoteBackup] 连接测试结果:`, JSON.stringify(result));
if (result.success) {
res.json({
+55
View File
@@ -94,6 +94,11 @@ const migrations = [
name: '设备字段系统标记',
description: '为 deviceFields 表添加 isSystem 字段,标记系统字段不可删除',
migrate: migrateDeviceFieldsIsSystem
},
{
name: '设备字段Options配置',
description: '确保 deviceFields 表的 type 和 status 字段有正确的 options 配置',
migrate: migrateDeviceFieldsOptions
}
];
@@ -632,6 +637,56 @@ async function migrateDeviceFieldsIsSystem() {
console.log(' 设备字段系统标记迁移完成');
}
async function migrateDeviceFieldsOptions() {
const DeviceField = require('../models/DeviceField');
if (!(await tableExists('deviceFields'))) {
console.log(' deviceFields 表不存在,跳过');
return;
}
const deviceTypeOptions = [
{ value: 'server', label: '服务器' },
{ value: 'switch', label: '交换机' },
{ value: 'router', label: '路由器' },
{ value: 'storage', label: '存储设备' },
{ value: 'other', label: '其他设备' }
];
const statusOptions = [
{ value: 'running', label: '运行中' },
{ value: 'maintenance', label: '维护中' },
{ value: 'offline', label: '离线' },
{ value: 'fault', label: '故障' }
];
const typeField = await DeviceField.findOne({ where: { fieldName: 'type' } });
if (typeField) {
if (!typeField.options || typeField.options.length === 0) {
await typeField.update({ options: deviceTypeOptions });
console.log(' 已更新 type 字段的 options');
} else {
console.log(' type 字段 options 已存在,跳过');
}
} else {
console.log(' type 字段不存在,跳过');
}
const statusField = await DeviceField.findOne({ where: { fieldName: 'status' } });
if (statusField) {
if (!statusField.options || statusField.options.length === 0) {
await statusField.update({ options: statusOptions });
console.log(' 已更新 status 字段的 options');
} else {
console.log(' status 字段 options 已存在,跳过');
}
} else {
console.log(' status 字段不存在,跳过');
}
console.log(' 设备字段 Options 配置迁移完成');
}
async function migrateIdleDeviceAndBusiness() {
const queryInterface = sequelize.getQueryInterface();
const dialect = sequelize.getDialect();
@@ -296,7 +296,6 @@ const RemoteBackupSettings = () => {
await form.validateFields();
const values = form.getFieldsValue(true);
console.log('[TestConnection] getFieldsValue(true):', JSON.stringify(values));
const response = await api.post('/backup/remote/test', values);
if (response?.success) {