Adds initial ASP.NET Core MVC replacement for Blazor WASM

This commit is contained in:
BinaryAlley committed 2024-09-26 19:58:08 +03:00
1 parent 5409200c7a
commit 193861c9c5
56 files changed
+505 -4139

No files matched your search

@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Enums.PhotoLibrary;
using System.Collections.Frozen;
using System.Collections.Generic;
#endregion
namespace Lumina.Presentation.Api.Common.Utilities;
/// <summary>
/// Utility class for converting from domain image types to known image mime types.
/// </summary>
public static class MimeTypes
{
#region ================================================================== FIELD MEMBERS ================================================================================
private static readonly FrozenDictionary<ImageType, string> s_imageTypeToMimeType = new Dictionary<ImageType, string>
{
{ ImageType.BMP, "image/bmp" },
{ ImageType.GIF, "image/gif" },
{ ImageType.PNG, "image/png" },
{ ImageType.TIFF, "image/tiff" },
{ ImageType.JPEG, "image/jpeg" },
{ ImageType.JPEG_CANON, "image/jpeg" },
{ ImageType.JPEG_UNKNOWN, "image/jpeg" },
{ ImageType.PICT, "image/x-pict" },
{ ImageType.ICO, "image/x-icon" },
{ ImageType.PSD, "image/vnd.adobe.photoshop" },
{ ImageType.JPEG2000, "image/jp2" },
{ ImageType.AVIF, "image/avif" },
{ ImageType.WEBP, "image/webp" },
{ ImageType.TGA, "image/x-tga" },
{ ImageType.SVG, "image/svg+xml" }
}.ToFrozenDictionary();
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the mime type of <paramref name="type"/>.
/// </summary>
/// <param name="type">The domain image type for which to get the mime type.</param>
/// <returns>The mime type for <paramref name="type"/>.</returns>
public static string GetMimeType(ImageType type)
{
return s_imageTypeToMimeType.TryGetValue(type, out string? mimeType) ? mimeType : "application/octet-stream";
}
#endregion
}
@@ -0,0 +1,52 @@
#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;
/// <summary>
/// Controller for managing file system items thumbnails.
/// </summary>
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class ThumbnailsController : ApiController
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly ISender _mediator;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="ThumbnailsController"/> class.
/// </summary>
/// <param name="mediator">Injected service for mediating commands and queries.</param>
public ThumbnailsController(ISender mediator)
{
_mediator = mediator;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the thumbnail of a file identified by of <paramref name="path"/>.
/// </summary>
/// <param name="path">The path of the file for which to get the thumbnail.</param>
/// <param name="quality">The quality to use for the thumbnail.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpGet("get-thumbnail")]
public async Task<IActionResult> GetThumbnail([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [FromQuery] int quality, CancellationToken cancellationToken)
{
ErrorOr<ThumbnailResponse> getResult = await _mediator.Send(new GetThumbnailQuery(path, quality), cancellationToken);
return getResult.Match(result => File(result.Bytes, MimeTypes.GetMimeType(result.Type)), errors => Problem(errors));
}
#endregion
}