This commit is contained in:
2026-05-09 20:14:55 +08:00
5 changed files with 47 additions and 18 deletions
@@ -19,6 +19,6 @@ namespace FileService.Application.UploadFile
public StorageLocation StorageLocation { get; set; }
public CheckSum CheckSum { get; set; }
public DateTimeOffset Created { get; set; }
public DateTimeOffset Updated { get; set;
public DateTimeOffset Updated { get; set; }
}
}
@@ -44,6 +44,8 @@ namespace FileService.Application.UploadFileTask
var res = mapper.Map<TaskInitResponse>(initRes);
res.TaskId = task.Id;
task.StartUpload();
reposity.Create(task);
await redis.SetAsync(new StorageContracts.UploadRuntimeCache(
@@ -83,9 +85,31 @@ namespace FileService.Application.UploadFileTask
return Result.Success(presignUrl);
}
//public async Task<Result<UploadTaskResponse>> CompleteTaskAsync()
//{
// var taskCache = await redis.GetAsync()
//}
public async Task<Result<UploadTaskResponse>> CompleteTaskAsync(UploadTaskCompleteCommand command, CancellationToken cancellationToken = default)
{
var taskCache = await redis.GetAsync(command.UploadSessionId);
if(taskCache is null)
{
return Result.Fail<UploadTaskResponse>(ResultCode.CHUNK_NOT_FOUND);
}
var task = await reposity.FindByIdAsync(Guid.Parse(taskCache.TaskId));
var res = await storage.CompleteUploadAsync(new CompleteUploadCommand(
ProviderCode: taskCache.ProviderCode,
Bucket: taskCache.Bucket,
Region: taskCache.Region,
ObjectKey: taskCache.ObjectKey,
UploadSessionId: taskCache.UploadSessionId,
Parts: command.Parts
), cancellationToken);
task.CompleteUpload(new Domain.ValueObjects.StorageLocation(
taskCache.ProviderCode, taskCache.Bucket,
taskCache.ObjectKey, taskCache.Region
));
return Result.Success(mapper.Map<UploadTaskResponse>(task));
}
}
}
@@ -1,4 +1,5 @@
using System;
using FileService.Application.StorageContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -6,5 +7,5 @@ using System.Threading.Tasks;
namespace FileService.Application.UploadFileTask
{
public record UploadTaskCompleteCommand(string UploadSessionId, Guid userId,);
public record UploadTaskCompleteCommand(string UploadSessionId, Guid userId, IReadOnlyList<UploadPart> Parts);
}