This commit is contained in:
2026-06-02 16:25:57 +08:00
24 changed files with 285 additions and 53 deletions
@@ -1,4 +1,6 @@
using FileService.Application.Ports;
using FileService.Domain.IReposities;
using IM.Application.Abstractions;
using IM.Commons.IntegrationEvents;
using MassTransit;
using System;
@@ -12,18 +14,23 @@ namespace FileService.Application.EventHandler
public class UploadTaskCompleteEventHandler : IConsumer<UploadTaskCompleteEvent>
{
private readonly IObjectStorageRouter router;
private readonly IStorageRedisCache cache;
private readonly IUploadFileReposity uploadFile;
private readonly IUnitOfWork uwork;
private readonly IStorageRedisCache storageCache;
public UploadTaskCompleteEventHandler(IObjectStorageRouter router, IStorageRedisCache cache)
public UploadTaskCompleteEventHandler(IObjectStorageRouter router, IUploadFileReposity uploadFile, IUnitOfWork uwork, IStorageRedisCache storageCache)
{
this.router = router;
this.cache = cache;
this.uploadFile = uploadFile;
this.uwork = uwork;
this.storageCache = storageCache;
}
public async Task Consume(ConsumeContext<UploadTaskCompleteEvent> context)
{
var @event = context.Message;
var storage = router.Route(@event.ProviderCode);
var taskCache = await storageCache.GetAsync(@event.SessionId);
if(@event.ProviderCode == "Local")
{
await storage.CompleteUploadAsync(new StorageContracts.CompleteUploadCommand(
@@ -39,6 +46,14 @@ namespace FileService.Application.EventHandler
Checksum: s.Checksum
)).ToList()
), context.CancellationToken);
uploadFile.Create(new Domain.Entities.UploadFile(
ownerId: @event.OperatorId,
fileName: @event.FileName,
fileSize: taskCache.FileSize,
contentType: @event.ContentType,
new Domain.ValueObjects.StorageLocation(taskCache.ProviderCode, taskCache.Bucket, taskCache.ObjectKey, taskCache.Region),
checkSum: new Domain.ValueObjects.CheckSum("md5", @event.CheckSun)
));
}
}
}