using AutoMapper; using FileService.Application.Ports; using FileService.Domain.Entities; using FileService.Domain.IReposities; using IM.Commons; using IM.InitCommon; using MassTransit.Internals; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FileService.Application.UploadFileTask { public class UploadFileTaskService { private readonly IUploadTaskReposity reposity; private readonly IMapper mapper; private readonly IObjectStorageRouter router; private readonly IOptions options; public UploadFileTaskService(IUploadTaskReposity reposity, IMapper mapper, IObjectStorageRouter router, IOptions options) { this.reposity = reposity; this.mapper = mapper; this.router = router; this.options = options; } public async Task> InitTaskAsync(UploadTaskInitCommand command) { CancellationToken cancellationToken = CancellationToken.None; var task = command.ToUploadTask(); var storage = router.Route(options.Value.ProviderCode); var initRes = await storage.InitUploadAsync(new StorageContracts.InitiateUploadCommand( ProviderCode: options.Value.ProviderCode, Bucket: options.Value.Bucket, ObjectKey: options.Value.Endpoint, ContentType:task.ContentType.Value, ContentLength: command.FileSize, null ), cancellationToken); var res = mapper.Map(initRes); res.TaskId = task.Id; return Result.Success(res); } } }