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 StorageLocation StorageLocation { get; set; }
public CheckSum CheckSum { get; set; } public CheckSum CheckSum { get; set; }
public DateTimeOffset Created { 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); var res = mapper.Map<TaskInitResponse>(initRes);
res.TaskId = task.Id; res.TaskId = task.Id;
task.StartUpload();
reposity.Create(task); reposity.Create(task);
await redis.SetAsync(new StorageContracts.UploadRuntimeCache( await redis.SetAsync(new StorageContracts.UploadRuntimeCache(
@@ -83,9 +85,31 @@ namespace FileService.Application.UploadFileTask
return Result.Success(presignUrl); return Result.Success(presignUrl);
} }
//public async Task<Result<UploadTaskResponse>> CompleteTaskAsync() public async Task<Result<UploadTaskResponse>> CompleteTaskAsync(UploadTaskCompleteCommand command, CancellationToken cancellationToken = default)
//{ {
// var taskCache = await redis.GetAsync() 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -6,5 +7,5 @@ using System.Threading.Tasks;
namespace FileService.Application.UploadFileTask 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.Application.StorageContracts;
using FileService.Domain.ValueObjects; using FileService.Domain.ValueObjects;
using IM.Commons; using IM.Commons;
using IM.InitCommon;
using MassTransit; using MassTransit;
using MassTransit.Configuration;
using Microsoft.Extensions.Options;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -11,14 +14,10 @@ using System.Threading.Tasks;
namespace FileService.Infrastructure.Storage namespace FileService.Infrastructure.Storage
{ {
public class LocalStorageAdapter : IObjectStoragePort public class LocalStorageAdapter(IRedisService redis, IOptions<StorageOptions> options) : IObjectStoragePort
{ {
private readonly IRedisService redis; private readonly IRedisService redis = redis;
private readonly IOptions<StorageOptions> options = options;
public LocalStorageAdapter(IRedisService redis)
{
this.redis = redis;
}
public string ProviderCode => "Local"; public string ProviderCode => "Local";
@@ -27,9 +26,14 @@ namespace FileService.Infrastructure.Storage
throw new NotImplementedException(); 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) public async Task<InitiateUploadResult> InitUploadAsync(InitiateUploadCommand command, CancellationToken token)
@@ -9,7 +9,7 @@ namespace FileService.WebApi.Controllers.File
[ApiController] [ApiController]
public class FileController : ControllerBase public class FileController : ControllerBase
{ {
[HttpGet] //[HttpGet]
public async //public async
} }
} }