This commit is contained in:
2026-05-09 19:35:25 +08:00
5 changed files with 30 additions and 8 deletions
@@ -1,5 +1,6 @@
using AutoMapper;
using FileService.Application.Ports;
using FileService.Application.StorageContracts;
using FileService.Domain.Entities;
using FileService.Domain.IReposities;
using IM.Commons;
@@ -23,6 +24,7 @@ namespace FileService.Application.UploadFileTask
private readonly IObjectStorageRouter router = router;
private readonly IOptions<StorageOptions> options = options;
private readonly IStorageRedisCache redis = redis;
private readonly IObjectStoragePort storage = router.Route(options.Value.DefaultProviderCode);
public async Task<Result<TaskInitResponse>> InitTaskAsync(UploadTaskInitCommand command)
{
@@ -60,5 +62,25 @@ namespace FileService.Application.UploadFileTask
return Result.Success(res);
}
public async Task<Result<PresignedUrl>> GenerateUrlAsync(string sessionId, int partNum, Guid userId, CancellationToken token = default)
{
var taskCache = await redis.GetAsync(sessionId);
if(taskCache is null)
{
return Result.Fail<PresignedUrl>(ResultCode.CHUNK_NOT_FOUND);
}
var presignUrl = await storage.GenerateUploadUrlAsync(new GenerateUploadUrlCommand(
ProviderCode: taskCache.ProviderCode,
Bucket: taskCache.Bucket,
ObjectKey: taskCache.ObjectKey,
UploadSessionId: taskCache.UploadSessionId,
PartNumber: partNum,
ExpiresIn: options.Value.Providers[options.Value.DefaultProviderCode].UploadUrlExpiresIn
), token);
return Result.Success(presignUrl);
}
}
}