diff --git a/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs b/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs index 713d930..c966232 100644 --- a/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs +++ b/Apps.XtrfCustomerPortal/Actions/ProjectActions.cs @@ -6,6 +6,7 @@ using Apps.XtrfCustomerPortal.Utilities.Extensions; using Blackbird.Applications.Sdk.Common; using Blackbird.Applications.Sdk.Common.Actions; +using Blackbird.Applications.Sdk.Common.Files; using Blackbird.Applications.Sdk.Common.Invocation; using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces; using RestSharp; @@ -124,6 +125,31 @@ public async Task CreateProject([ActionParameter] CreateProject return new ProjectResponse(projectDto); } + [Action("Download project files", Description = "Download project translation files")] + public async Task DownloadProjectFiles([ActionParameter] ProjectIdentifier projectIdentifier) + { + var taskFilesDto = await Client.ExecuteRequestAsync($"/projects/{projectIdentifier.ProjectId}/files", Method.Get, null); + var files = taskFilesDto.TasksFiles.SelectMany(x => x.Output?.Files ?? new List()).ToList(); + + var fileReferences = new List(); + foreach (var file in files) + { + var invoicePdf = await Client.ExecuteRequestAsync($"/projects/files/{file.Id}", Method.Get, null, "application/octet-stream"); + var rawBytes = invoicePdf.RawBytes!; + + var stream = new MemoryStream(rawBytes); + stream.Position = 0; + + var fileReference = await fileManagementClient.UploadAsync(stream, "application/octet-stream", file.Name); + fileReferences.Add(fileReference); + } + + return new DownloadProjectFilesResponse + { + Files = fileReferences + }; + } + private async Task> FetchProjectsWithPagination(string endpoint) { var allProjects = new List(); diff --git a/Apps.XtrfCustomerPortal/Actions/QuoteActions.cs b/Apps.XtrfCustomerPortal/Actions/QuoteActions.cs index b85ac23..ad42292 100644 --- a/Apps.XtrfCustomerPortal/Actions/QuoteActions.cs +++ b/Apps.XtrfCustomerPortal/Actions/QuoteActions.cs @@ -6,10 +6,8 @@ using Apps.XtrfCustomerPortal.Utilities.Extensions; using Blackbird.Applications.Sdk.Common; using Blackbird.Applications.Sdk.Common.Actions; -using Blackbird.Applications.Sdk.Common.Files; using Blackbird.Applications.Sdk.Common.Invocation; using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces; -using Blackbird.Applications.Sdk.Utils.Extensions.Files; using RestSharp; namespace Apps.XtrfCustomerPortal.Actions; diff --git a/Apps.XtrfCustomerPortal/Models/Dtos/TaskFilesDto.cs b/Apps.XtrfCustomerPortal/Models/Dtos/TaskFilesDto.cs new file mode 100644 index 0000000..f3525e3 --- /dev/null +++ b/Apps.XtrfCustomerPortal/Models/Dtos/TaskFilesDto.cs @@ -0,0 +1,67 @@ +namespace Apps.XtrfCustomerPortal.Models.Dtos; + +public class TaskFilesDto +{ + public int Id { get; set; } + public string IdNumber { get; set; } + public List TasksFiles { get; set; } + public bool OutputFilesAsZipDownloadable { get; set; } + + public class TaskFile + { + public int Id { get; set; } + public string IdNumber { get; set; } + public LanguageCombination LanguageCombination { get; set; } + public FileGroup InputWorkfiles { get; set; } + public FileGroup InputResources { get; set; } + public FileGroup? Output { get; set; } + public bool OutputFilesAsZipDownloadable { get; set; } + } + + public class LanguageCombination + { + public Language SourceLanguage { get; set; } + public Language TargetLanguage { get; set; } + } + + public class Language + { + public int Id { get; set; } + public string Symbol { get; set; } + public string Name { get; set; } + public string DisplayName { get; set; } + } + + public class FileGroup + { + public string Name { get; set; } + public List Directories { get; set; } + public List Files { get; set; } + } + + public class Directory + { + public string Name { get; set; } + public List Directories { get; set; } + public List Files { get; set; } + } + + public class File + { + public string Name { get; set; } + public int Id { get; set; } + public bool Downloadable { get; set; } + public string Category { get; set; } + public bool Zip { get; set; } + public FileStats FileStats { get; set; } + } + + public class FileStats + { + public int CharactersWithSpaces { get; set; } + public int CharactersWithoutSpaces { get; set; } + public int Words { get; set; } + public int Lines { get; set; } + public int Pages { get; set; } + } +} \ No newline at end of file diff --git a/Apps.XtrfCustomerPortal/Models/Responses/Projects/DownloadProjectFilesResponse.cs b/Apps.XtrfCustomerPortal/Models/Responses/Projects/DownloadProjectFilesResponse.cs new file mode 100644 index 0000000..6f72cff --- /dev/null +++ b/Apps.XtrfCustomerPortal/Models/Responses/Projects/DownloadProjectFilesResponse.cs @@ -0,0 +1,8 @@ +using Blackbird.Applications.Sdk.Common.Files; + +namespace Apps.XtrfCustomerPortal.Models.Responses.Projects; + +public class DownloadProjectFilesResponse +{ + public List Files { get; set; } = new(); +} \ No newline at end of file