feat: 实现安全存储和批量导入功能增强
refactor(前端): 重构认证和存储逻辑使用secureStorage feat(前端): 添加安全存储工具和日志工具 feat(前端): 增强批量导入功能支持服务器和交换机设备 fix(后端): 改进设备端口和网卡批量导入接口 docs: 更新导入模板和操作说明
This commit is contained in:
Binary file not shown.
@@ -165,13 +165,22 @@ router.post('/batch', async (req, res) => {
|
||||
const portData = ports[i];
|
||||
|
||||
try {
|
||||
if (!portData.portId || !portData.deviceId || !portData.portName) {
|
||||
if (!portData.portId || !(portData.deviceId || portData.deviceSn) || !portData.portName) {
|
||||
throw new Error('缺少必填字段');
|
||||
}
|
||||
|
||||
const device = await Device.findByPk(portData.deviceId, { transaction });
|
||||
if (!device) {
|
||||
throw new Error(`设备 ${portData.deviceId} 不存在`);
|
||||
let device;
|
||||
if (portData.deviceSn) {
|
||||
device = await Device.findOne({ where: { serialNumber: portData.deviceSn }, transaction });
|
||||
if (!device) {
|
||||
throw new Error(`设备SN ${portData.deviceSn} 不存在`);
|
||||
}
|
||||
portData.deviceId = device.deviceId;
|
||||
} else {
|
||||
device = await Device.findByPk(portData.deviceId, { transaction });
|
||||
if (!device) {
|
||||
throw new Error(`设备ID ${portData.deviceId} 不存在`);
|
||||
}
|
||||
}
|
||||
|
||||
const isServer = device.type && device.type.toLowerCase().includes('server');
|
||||
|
||||
@@ -172,14 +172,22 @@ router.get('/:nicId/ports', async (req, res) => {
|
||||
|
||||
router.get('/find', async (req, res) => {
|
||||
try {
|
||||
const { deviceId, name } = req.query;
|
||||
const { deviceId, deviceSn, name } = req.query;
|
||||
|
||||
if (!deviceId || !name) {
|
||||
return res.status(400).json({ error: '缺少设备ID或网卡名称' });
|
||||
if ((!deviceId && !deviceSn) || !name) {
|
||||
return res.status(400).json({ error: '缺少设备ID/SN或网卡名称' });
|
||||
}
|
||||
|
||||
let device;
|
||||
if (deviceSn) {
|
||||
device = await Device.findOne({ where: { serialNumber: deviceSn } });
|
||||
if (!device) {
|
||||
return res.json({ nicId: null });
|
||||
}
|
||||
}
|
||||
|
||||
const networkCard = await NetworkCard.findOne({
|
||||
where: { deviceId, name },
|
||||
where: { deviceId: device ? device.deviceId : deviceId, name },
|
||||
});
|
||||
|
||||
if (!networkCard) {
|
||||
@@ -265,13 +273,22 @@ router.post('/batch', async (req, res) => {
|
||||
const cardData = networkCards[i];
|
||||
|
||||
try {
|
||||
if (!cardData.deviceId || !cardData.name) {
|
||||
throw new Error('缺少必填字段:设备ID和网卡名称');
|
||||
if (!(cardData.deviceId || cardData.deviceSn) || !cardData.name) {
|
||||
throw new Error('缺少必填字段:设备ID/SN和网卡名称');
|
||||
}
|
||||
|
||||
const device = await Device.findByPk(cardData.deviceId, { transaction });
|
||||
if (!device) {
|
||||
throw new Error(`设备 ${cardData.deviceId} 不存在`);
|
||||
let device;
|
||||
if (cardData.deviceSn) {
|
||||
device = await Device.findOne({ where: { serialNumber: cardData.deviceSn }, transaction });
|
||||
if (!device) {
|
||||
throw new Error(`设备SN ${cardData.deviceSn} 不存在`);
|
||||
}
|
||||
cardData.deviceId = device.deviceId;
|
||||
} else {
|
||||
device = await Device.findByPk(cardData.deviceId, { transaction });
|
||||
if (!device) {
|
||||
throw new Error(`设备ID ${cardData.deviceId} 不存在`);
|
||||
}
|
||||
}
|
||||
|
||||
const isServer = device.type && device.type.toLowerCase().includes('server');
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# This file ensures the temp directory is tracked by Git
|
||||
# All temporary files in this directory are ignored
|
||||
@@ -0,0 +1,2 @@
|
||||
# This file ensures the uploads directory is tracked by Git
|
||||
# All user-uploaded files in this directory are ignored
|
||||
Reference in New Issue
Block a user