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>
|
||||||
/// Метод получения файла справки
|
/// Метод получения файла справки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="urlPage"></param>
|
/// <param name="pageKey"></param>
|
||||||
/// <param name="idCategory"></param>
|
/// <param name="idCategory"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage,
|
Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey,
|
||||||
int idCategory,
|
int idCategory,
|
||||||
CancellationToken cancellationToken);
|
CancellationToken cancellationToken);
|
||||||
}
|
}
|
@ -78,20 +78,23 @@ public class HelpPageService : IHelpPageService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод получения файла справки
|
/// Метод получения файла справки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="urlPage"></param>
|
/// <param name="pageKey"></param>
|
||||||
/// <param name="idCategory"></param>
|
/// <param name="idCategory"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="ArgumentInvalidException"></exception>
|
/// <exception cref="NotFoundException"></exception>
|
||||||
public async Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage,
|
public async Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey,
|
||||||
int idCategory,
|
int idCategory,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
urlPage = WebUtility.UrlDecode(urlPage);
|
pageKey = WebUtility.UrlDecode(pageKey);
|
||||||
|
|
||||||
var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(urlPage,
|
var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(pageKey,
|
||||||
idCategory,
|
idCategory,
|
||||||
cancellationToken) ?? throw new ArgumentInvalidException("Справки не существует", nameof(idCategory));
|
cancellationToken);
|
||||||
|
|
||||||
|
if(helpPage is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
string filePath = fileStorageRepository.GetFilePath(directoryNameHelpPageFiles,
|
string filePath = fileStorageRepository.GetFilePath(directoryNameHelpPageFiles,
|
||||||
helpPage.IdCategory.ToString(),
|
helpPage.IdCategory.ToString(),
|
||||||
|
@ -89,14 +89,10 @@ public class HelpPageController : ControllerBase
|
|||||||
idCategory,
|
idCategory,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
||||||
using var fileStream = file.stream;
|
if (!file.HasValue)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
var memoryStream = new MemoryStream();
|
return File(file.Value.stream, "application/pdf", file.Value.fileName);
|
||||||
await fileStream.CopyToAsync(memoryStream,
|
|
||||||
cancellationToken);
|
|
||||||
memoryStream.Position = 0;
|
|
||||||
|
|
||||||
return File(memoryStream, "application/pdf", file.fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user