diff --git a/backend/storage.js b/backend/storage.js index ae993a5..4257508 100644 --- a/backend/storage.js +++ b/backend/storage.js @@ -85,7 +85,7 @@ class LocalStorageClient { // 获取新文件大小 const newFileSize = fs.statSync(localPath).size; - + // 如果目标文件存在,计算实际需要的额外空间 let oldFileSize = 0; if (fs.existsSync(destPath)) { @@ -95,7 +95,7 @@ class LocalStorageClient { // 文件可能已被删除,忽略错误 } } - + // 检查配额:只检查净增量(新文件大小 - 旧文件大小) const netIncrease = newFileSize - oldFileSize; if (netIncrease > 0) { @@ -195,12 +195,12 @@ class LocalStorageClient { */ getFullPath(relativePath) { // 1. 规范化路径,移除 ../ 等危险路径 - let normalized = path.normalize(relativePath || '').replace(/^(\.\.[\/\])+/, ''); + let normalized = path.normalize(relativePath || '').replace(/^(\.\.[\/\\])+/, ''); // 2. ✅ 修复:将绝对路径转换为相对路径(解决Linux环境下的问题) if (path.isAbsolute(normalized)) { // 移除开头的 / 或 Windows 盘符,转为相对路径 - normalized = normalized.replace(/^[\/\]+/, '').replace(/^[a-zA-Z]:/, ''); + normalized = normalized.replace(/^[\/\\]+/, '').replace(/^[a-zA-Z]:/, ''); } // 3. 空字符串或 . 表示根目录