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);
}
@@ -2,7 +2,10 @@
using FileService.Application.StorageContracts;
using FileService.Domain.ValueObjects;
using IM.Commons;
using IM.InitCommon;
using MassTransit;
using MassTransit.Configuration;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -11,14 +14,10 @@ using System.Threading.Tasks;
namespace FileService.Infrastructure.Storage
{
public class LocalStorageAdapter : IObjectStoragePort
public class LocalStorageAdapter(IRedisService redis, IOptions<StorageOptions> options) : IObjectStoragePort
{
private readonly IRedisService redis;
public LocalStorageAdapter(IRedisService redis)
{
this.redis = redis;
}
private readonly IRedisService redis = redis;
private readonly IOptions<StorageOptions> options = options;
public string ProviderCode => "Local";
@@ -27,9 +26,14 @@ namespace FileService.Infrastructure.Storage
throw new NotImplementedException();
}
public Task<PresignedUrl> GenerateUploadUrlAsync(GenerateUploadUrlCommand command, CancellationToken token)
public async Task<PresignedUrl> GenerateUploadUrlAsync(GenerateUploadUrlCommand command, CancellationToken token)
{
throw new NotImplementedException();
var baseUrl = options.Value.Providers[options.Value.DefaultProviderCode].LocalUploadApiBaseUrl;
return new PresignedUrl(
baseUrl + $"?partNumber={command.PartNumber}",
new Dictionary<string, string>(),
ExpiresAt: DateTimeOffset.Now.Add(options.Value.Providers[options.Value.DefaultProviderCode].UploadUrlExpiresIn)
);
}
public async Task<InitiateUploadResult> InitUploadAsync(InitiateUploadCommand command, CancellationToken token)
@@ -9,7 +9,7 @@ namespace FileService.WebApi.Controllers.File
[ApiController]
public class FileController : ControllerBase
{
[HttpGet]
public async
//[HttpGet]
//public async
}
}