forked from ddrilling/AsbCloudServer
HelpPageService.GetFileStreamAsync удалил ArgumentInvalidException. Заменил возвращаемый тип на Nullable.
This commit is contained in:
parent
963da559e2
commit
84d84fb504
@ -27,11 +27,11 @@ public interface IHelpPageService
|
||||
/// <summary>
|
||||
/// Метод получения файла справки
|
||||
/// </summary>
|
||||
/// <param name="urlPage"></param>
|
||||
/// <param name="pageKey"></param>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage,
|
||||
Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey,
|
||||
int idCategory,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
@ -78,20 +78,23 @@ public class HelpPageService : IHelpPageService
|
||||
/// <summary>
|
||||
/// Метод получения файла справки
|
||||
/// </summary>
|
||||
/// <param name="urlPage"></param>
|
||||
/// <param name="pageKey"></param>
|
||||
/// <param name="idCategory"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentInvalidException"></exception>
|
||||
public async Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage,
|
||||
/// <exception cref="NotFoundException"></exception>
|
||||
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(),
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user