fix(remote-backup): 移除调试日志并改进协议类型验证
refactor(migrations): 添加设备字段options配置迁移
This commit is contained in:
@@ -802,7 +802,6 @@ router.delete('/remote/targets/:id', (req, res) => {
|
|||||||
router.post('/remote/test', async (req, res) => {
|
router.post('/remote/test', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const config = req.body;
|
const config = req.body;
|
||||||
console.log(`[RemoteBackup] 收到连接测试请求:`, JSON.stringify(config));
|
|
||||||
|
|
||||||
if (!config.host || !config.port || !config.username) {
|
if (!config.host || !config.port || !config.username) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
@@ -812,21 +811,13 @@ router.post('/remote/test', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!config.protocol) {
|
if (!config.protocol) {
|
||||||
const port = parseInt(config.port);
|
return res.status(400).json({
|
||||||
if (port === 22 || port === 2222) {
|
success: false,
|
||||||
config.protocol = 'sftp';
|
message: '请提供协议类型(protocol)',
|
||||||
} 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})`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await testRemoteConnection(config);
|
const result = await testRemoteConnection(config);
|
||||||
console.log(`[RemoteBackup] 连接测试结果:`, JSON.stringify(result));
|
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ const migrations = [
|
|||||||
name: '设备字段系统标记',
|
name: '设备字段系统标记',
|
||||||
description: '为 deviceFields 表添加 isSystem 字段,标记系统字段不可删除',
|
description: '为 deviceFields 表添加 isSystem 字段,标记系统字段不可删除',
|
||||||
migrate: migrateDeviceFieldsIsSystem
|
migrate: migrateDeviceFieldsIsSystem
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '设备字段Options配置',
|
||||||
|
description: '确保 deviceFields 表的 type 和 status 字段有正确的 options 配置',
|
||||||
|
migrate: migrateDeviceFieldsOptions
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -632,6 +637,56 @@ async function migrateDeviceFieldsIsSystem() {
|
|||||||
console.log(' 设备字段系统标记迁移完成');
|
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() {
|
async function migrateIdleDeviceAndBusiness() {
|
||||||
const queryInterface = sequelize.getQueryInterface();
|
const queryInterface = sequelize.getQueryInterface();
|
||||||
const dialect = sequelize.getDialect();
|
const dialect = sequelize.getDialect();
|
||||||
|
|||||||
@@ -296,7 +296,6 @@ const RemoteBackupSettings = () => {
|
|||||||
|
|
||||||
await form.validateFields();
|
await form.validateFields();
|
||||||
const values = form.getFieldsValue(true);
|
const values = form.getFieldsValue(true);
|
||||||
console.log('[TestConnection] getFieldsValue(true):', JSON.stringify(values));
|
|
||||||
const response = await api.post('/backup/remote/test', values);
|
const response = await api.post('/backup/remote/test', values);
|
||||||
|
|
||||||
if (response?.success) {
|
if (response?.success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user