fix(racks): 确保导入文件时临时目录存在

在文件导入路由中添加检查并创建临时目录的逻辑,防止因目录不存在导致的文件保存失败
This commit is contained in:
zhang1106
2026-02-06 13:38:24 +08:00
parent 258b7af7c8
commit cbbc969b64
+7 -1
View File
@@ -218,8 +218,14 @@ router.post('/import', async (req, res) => {
const file = req.files.file; const file = req.files.file;
// 确保temp目录存在
const tempDir = path.join(__dirname, '../temp');
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
// 保存临时文件 // 保存临时文件
const tempFilePath = path.join(__dirname, '../temp', `${Date.now()}_${file.name}`); const tempFilePath = path.join(tempDir, `${Date.now()}_${file.name}`);
try { try {
await file.mv(tempFilePath); await file.mv(tempFilePath);
} catch (saveError) { } catch (saveError) {