fix: 完善存储客户端实现并删除重复导入
- LocalStorageClient 和 OssStorageClient 添加 formatSize() 方法 - 删除 mkdir() 中重复的 PutObjectCommand 导入 - 统一使用共享的 formatFileSize() 函数 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 无需显式关闭)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user