From e8d053f28ddb9ddb2776c5cc36fefcb89babc2ca Mon Sep 17 00:00:00 2001 From: Claude Opus Date: Sun, 18 Jan 2026 21:49:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=AE=9E=E7=8E=B0=E5=B9=B6=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=87=8D=E5=A4=8D=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - LocalStorageClient 和 OssStorageClient 添加 formatSize() 方法 - 删除 mkdir() 中重复的 PutObjectCommand 导入 - 统一使用共享的 formatFileSize() 函数 Co-Authored-By: Claude Opus 4.5 --- backend/storage.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/storage.js b/backend/storage.js index e1fc94a..8014a8b 100644 --- a/backend/storage.js +++ b/backend/storage.js @@ -321,6 +321,13 @@ class LocalStorageClient { // 更新内存中的值 this.user.local_storage_used = newUsed; } + + /** + * 格式化文件大小 + */ + formatSize(bytes) { + return formatFileSize(bytes); + } } // ===== OSS存储客户端 ===== @@ -538,7 +545,7 @@ class OssStorageClient { }); await this.s3Client.send(command); - console.log(`[OSS存储] 上传成功: ${key} (${this.formatSize(fileSize)})`); + console.log(`[OSS存储] 上传成功: ${key} (${formatFileSize(fileSize)})`); // 关闭流 if (!fileStream.destroyed) { @@ -744,7 +751,6 @@ class OssStorageClient { // OSS 中文件夹通过以斜杠结尾的空对象模拟 const folderKey = key.endsWith('/') ? key : `${key}/`; - const { PutObjectCommand } = require('@aws-sdk/client-s3'); const command = new PutObjectCommand({ Bucket: bucket, Key: folderKey, @@ -788,6 +794,13 @@ class OssStorageClient { return `${baseUrl}/${key}`; } + /** + * 格式化文件大小 + */ + formatSize(bytes) { + return formatFileSize(bytes); + } + /** * 关闭连接(S3Client 无需显式关闭) */