fix: 修复后端12个+前端5个高优先级问题
后端: - devices.js: 修复 newRackId 重复声明、批量移动加事务、ID生成改MAX聚合 - tickets.js: 添加工单状态机校验、req.body白名单过滤 - roles.js: init-roles 添加 authMiddleware - backup.js: 备份列表只读4KB头部,压缩文件超1MB跳过 - consumables.js: SN查询改用数据库LIKE替代全表扫描 - consumableRecords.js: 出入库加 SELECT FOR UPDATE 行级锁 - inventory.js: not_found 状态判断从 abnormal if 内移到 else if - idleDevices.js: 删除重复的 batch-restore 路由定义(182行) - cables.js: 接线冲突检测增加反向端口检查 前端: - AuthContext.jsx: 初始化时调用 fetchProfile 验证token、Error提取message - api/index.js: backupAPI.download 返回Promise、checkAdmin改POST - Login.jsx: checkIsFirstUser 静默处理错误 - DeviceManagement.jsx: 导出 currentPage scope 使用 currentPageDevices
This commit is contained in:
@@ -127,13 +127,23 @@ router.get('/list', async (req, res) => {
|
||||
};
|
||||
|
||||
try {
|
||||
// 读取文件头部的元数据信息
|
||||
// 只读取文件头部(前 4KB)提取元数据,避免大文件内存溢出
|
||||
let content;
|
||||
if (isCompressed) {
|
||||
const compressed = fs.readFileSync(filePath);
|
||||
// 限制解压大小,超过 1MB 的备份不解析元数据
|
||||
if (compressed.length > 1024 * 1024) {
|
||||
metadata.description = '(文件过大,跳过元数据解析)';
|
||||
return metadata;
|
||||
}
|
||||
content = zlib.gunzipSync(compressed).toString('utf8');
|
||||
} else {
|
||||
content = fs.readFileSync(filePath, 'utf8');
|
||||
// 只读取前 4KB
|
||||
const fd = fs.openSync(filePath, 'r');
|
||||
const buf = Buffer.alloc(4096);
|
||||
const bytesRead = fs.readSync(fd, buf, 0, 4096, 0);
|
||||
fs.closeSync(fd);
|
||||
content = buf.slice(0, bytesRead).toString('utf8');
|
||||
}
|
||||
|
||||
const backupData = JSON.parse(content);
|
||||
|
||||
Reference in New Issue
Block a user