|
|
@@ -168,14 +168,20 @@ export class FileService extends GenericCrudService<File> {
|
|
|
key: string;
|
|
|
parts: Array<{ partNumber: number; etag: string }>;
|
|
|
}) {
|
|
|
- try {
|
|
|
- logger.db('Starting multipart upload completion:', {
|
|
|
- uploadId: data.uploadId,
|
|
|
- bucket: data.bucket,
|
|
|
- key: data.key,
|
|
|
- partsCount: data.parts.length
|
|
|
- });
|
|
|
+ logger.db('Starting multipart upload completion:', {
|
|
|
+ uploadId: data.uploadId,
|
|
|
+ bucket: data.bucket,
|
|
|
+ key: data.key,
|
|
|
+ partsCount: data.parts.length
|
|
|
+ });
|
|
|
|
|
|
+ // 查找文件记录
|
|
|
+ const file = await this.repository.findOneBy({ path: data.key });
|
|
|
+ if (!file) {
|
|
|
+ throw new Error('文件记录不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
// 完成MinIO分片上传 - 注意格式转换
|
|
|
const result = await this.minioService.completeMultipartUpload(
|
|
|
data.bucket,
|
|
|
@@ -183,27 +189,21 @@ export class FileService extends GenericCrudService<File> {
|
|
|
data.uploadId,
|
|
|
data.parts.map(part => ({ PartNumber: part.partNumber, ETag: part.etag }))
|
|
|
);
|
|
|
-
|
|
|
- // 查找文件记录并更新
|
|
|
- const file = await this.repository.findOneBy({ path: data.key });
|
|
|
- if (!file) {
|
|
|
- throw new Error('文件记录不存在');
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
// 更新文件大小等信息
|
|
|
file.size = result.size;
|
|
|
file.updatedAt = new Date();
|
|
|
await this.repository.save(file);
|
|
|
-
|
|
|
+
|
|
|
// 生成文件访问URL
|
|
|
const url = this.minioService.getFileUrl(data.bucket, data.key);
|
|
|
-
|
|
|
+
|
|
|
logger.db('Multipart upload completed successfully:', {
|
|
|
fileId: file.id,
|
|
|
size: result.size,
|
|
|
key: data.key
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
return {
|
|
|
fileId: file.id,
|
|
|
url,
|