From 84d84fb504788dcb0e60f979b1c67ff4eea727cc Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 26 Jul 2023 17:53:25 +0500 Subject: [PATCH] =?UTF-8?q?HelpPageService.GetFileStreamAsync=20=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20ArgumentInvalidException.=20?= =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=20=D0=BD=D0=B0=20Nullable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IHelpPageService.cs | 4 ++-- .../Services/HelpPageService.cs | 15 +++++++++------ AsbCloudWebApi/Controllers/HelpPageController.cs | 10 +++------- 3 files changed, 14 insertions(+), 15 deletions(-) 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); } ///