diff --git a/AsbCloudApp/Services/IHelpPageService.cs b/AsbCloudApp/Services/IHelpPageService.cs index 04051521..4fd675d7 100644 --- a/AsbCloudApp/Services/IHelpPageService.cs +++ b/AsbCloudApp/Services/IHelpPageService.cs @@ -27,11 +27,11 @@ public interface IHelpPageService /// /// Метод получения файла справки /// - /// + /// /// /// /// - Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage, + Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey, int idCategory, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/HelpPageService.cs b/AsbCloudInfrastructure/Services/HelpPageService.cs index 689ccbd2..0e8f40ee 100644 --- a/AsbCloudInfrastructure/Services/HelpPageService.cs +++ b/AsbCloudInfrastructure/Services/HelpPageService.cs @@ -78,20 +78,23 @@ public class HelpPageService : IHelpPageService /// /// Метод получения файла справки /// - /// + /// /// /// /// - /// - public async Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage, + /// + public async Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey, int idCategory, CancellationToken cancellationToken) { - urlPage = WebUtility.UrlDecode(urlPage); + pageKey = WebUtility.UrlDecode(pageKey); - var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(urlPage, + var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(pageKey, idCategory, - cancellationToken) ?? throw new ArgumentInvalidException("Справки не существует", nameof(idCategory)); + cancellationToken); + + if(helpPage is null) + return null; string filePath = fileStorageRepository.GetFilePath(directoryNameHelpPageFiles, helpPage.IdCategory.ToString(), diff --git a/AsbCloudWebApi/Controllers/HelpPageController.cs b/AsbCloudWebApi/Controllers/HelpPageController.cs index c3a538a1..e27f0f5f 100644 --- a/AsbCloudWebApi/Controllers/HelpPageController.cs +++ b/AsbCloudWebApi/Controllers/HelpPageController.cs @@ -89,14 +89,10 @@ public class HelpPageController : ControllerBase idCategory, cancellationToken); - using var fileStream = file.stream; + if (!file.HasValue) + return NotFound(); - var memoryStream = new MemoryStream(); - await fileStream.CopyToAsync(memoryStream, - cancellationToken); - memoryStream.Position = 0; - - return File(memoryStream, "application/pdf", file.fileName); + return File(file.Value.stream, "application/pdf", file.Value.fileName); } ///