#region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail; using Lumina.Contracts.Responses.FileManagement; using Lumina.Presentation.Api.Common.ModelBinders; using Lumina.Presentation.Api.Common.Utilities; using Lumina.Presentation.Api.Core.Controllers.Common; using Mediator; using Microsoft.AspNetCore.Mvc; using System.Threading; using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Api.Core.Controllers.FileManagement; /// /// Controller for managing file system items thumbnails. /// [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/[controller]")] public class ThumbnailsController : ApiController { #region ================================================================== FIELD MEMBERS ================================================================================ private readonly ISender _mediator; #endregion #region ====================================================================== CTOR ===================================================================================== /// /// Initializes a new instance of the class. /// /// Injected service for mediating commands and queries. public ThumbnailsController(ISender mediator) { _mediator = mediator; } #endregion #region ===================================================================== METHODS =================================================================================== /// /// Gets the thumbnail of a file identified by of . /// /// The path of the file for which to get the thumbnail. /// The quality to use for the thumbnail. /// Cancellation token that can be used to stop the execution. [HttpGet("get-thumbnail")] public async Task GetThumbnail([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [FromQuery] int quality, CancellationToken cancellationToken) { ErrorOr getResult = await _mediator.Send(new GetThumbnailQuery(path, quality), cancellationToken); return getResult.Match(result => File(result.Bytes, MimeTypes.GetMimeType(result.Type)), errors => Problem(errors)); } #endregion }