54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using WeatherForecast.Services;
|
|
using DomainResults.Mvc;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ImageController : ControllerBase {
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IImageService _imageService;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="imgeService"></param>
|
|
public ImageController(
|
|
IAuthorizationService authorizationService,
|
|
IImageService imgeService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_imageService = imgeService;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="width"></param>
|
|
/// <param name="height"></param>
|
|
/// <param name="imageId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("{siteId}/{width}x{height}/{imageId}")]
|
|
public IActionResult Get([FromRoute] Guid siteId, [FromRoute] int width, [FromRoute] int height, [FromRoute] Guid imageId) {
|
|
|
|
var (file, result) = _imageService.Get(siteId, width, height, imageId);
|
|
|
|
if (!result.IsSuccess || file == null)
|
|
return result.ToActionResult();
|
|
|
|
var stream = new MemoryStream(file.Bytes);
|
|
return new FileStreamResult(stream, file.ContentType) {
|
|
FileDownloadName = file.Name
|
|
};
|
|
}
|
|
|
|
}
|