mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Returns a clean validation error when a theme install archive cannot be parsed
This commit is contained in:
1 parent
1d85ff8ed9
commit
07bc20a9e6
1 file changed
+15
-1
+15
-1
@@ -6,6 +6,7 @@ using Lumina.Domain.Common.Primitives;
|
|||||||
using Lumina.Presentation.Api.Common.Routes.Themes;
|
using Lumina.Presentation.Api.Common.Routes.Themes;
|
||||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -47,7 +48,20 @@ public class InstallThemeEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IRe
|
|||||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
IFormFile? archive = HttpContext.Request.Form.Files.FirstOrDefault();
|
// a multipart body without any part cannot be parsed as a form, so a malformed upload is treated as a missing archive
|
||||||
|
IFormFile? archive = null;
|
||||||
|
if (HttpContext.Request.HasFormContentType)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
archive = HttpContext.Request.Form.Files.FirstOrDefault();
|
||||||
|
}
|
||||||
|
catch (InvalidDataException)
|
||||||
|
{
|
||||||
|
archive = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InstallThemeCommand command = new(archive?.OpenReadStream(), archive?.FileName);
|
InstallThemeCommand command = new(archive?.OpenReadStream(), archive?.FileName);
|
||||||
Result<ThemeResponse> result = await _installThemeCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
|
Result<ThemeResponse> result = await _installThemeCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
|
||||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||||
|
|||||||
Reference in new issue
Block a user