diff --git a/backend/storage.js b/backend/storage.js index cc42b1b..43a5ec8 100644 --- a/backend/storage.js +++ b/backend/storage.js @@ -83,9 +83,24 @@ class LocalStorageClient { async put(localPath, remotePath) { const destPath = this.getFullPath(remotePath); - // 检查配额 - const fileSize = fs.statSync(localPath).size; - this.checkQuota(fileSize); + // 获取新文件大小 + const newFileSize = fs.statSync(localPath).size; + + // 如果目标文件存在,计算实际需要的额外空间 + let oldFileSize = 0; + if (fs.existsSync(destPath)) { + try { + oldFileSize = fs.statSync(destPath).size; + } catch (err) { + // 文件可能已被删除,忽略错误 + } + } + + // 检查配额:只检查净增量(新文件大小 - 旧文件大小) + const netIncrease = newFileSize - oldFileSize; + if (netIncrease > 0) { + this.checkQuota(netIncrease); + } // 确保目标目录存在 const destDir = path.dirname(destPath); @@ -108,8 +123,10 @@ class LocalStorageClient { // 重命名临时文件为目标文件 fs.renameSync(tempPath, destPath); - // 更新已使用空间 - this.updateUsedSpace(fileSize); + // 更新已使用空间(使用净增量) + if (netIncrease !== 0) { + this.updateUsedSpace(netIncrease); + } } catch (error) { // 清理临时文件 if (fs.existsSync(tempPath)) {