fix(racks): 确保导入文件时临时目录存在
在文件导入路由中添加检查并创建临时目录的逻辑,防止因目录不存在导致的文件保存失败
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user