From a43901564b41cfaee07b0576f3f335c0d07c60a3 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 13 Mar 2025 16:35:29 +0100 Subject: [PATCH] Manga Cover request retrieve sizing from query instead of body --- API/APIEndpointRecords/CoverFormatRequestRecord.cs | 13 ------------- API/Controllers/MangaController.cs | 11 +++++------ 2 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 API/APIEndpointRecords/CoverFormatRequestRecord.cs diff --git a/API/APIEndpointRecords/CoverFormatRequestRecord.cs b/API/APIEndpointRecords/CoverFormatRequestRecord.cs deleted file mode 100644 index 36eaa0f..0000000 --- a/API/APIEndpointRecords/CoverFormatRequestRecord.cs +++ /dev/null @@ -1,13 +0,0 @@ -using SixLabors.ImageSharp; - -namespace API.APIEndpointRecords; - -public record CoverFormatRequestRecord(Size size) -{ - public bool Validate() - { - if (size.Height <= 0 || size.Width <= 0 || size.Height > 65535 || size.Width > 65535) //JPEG max size - return false; - return true; - } -} \ No newline at end of file diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index 33c8074..69bd6ba 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -92,7 +92,8 @@ public class MangaController(PgsqlContext context) : Controller /// Returns Cover of Manga /// /// Manga-ID - /// Formatting/Resizing Request + /// If width is provided, height needs to also be provided + /// If height is provided, width needs to also be provided /// JPEG Image /// Cover not loaded /// The formatting-request was invalid @@ -102,7 +103,7 @@ public class MangaController(PgsqlContext context) : Controller [ProducesResponseType(Status204NoContent)] [ProducesResponseType(Status400BadRequest)] [ProducesResponseType(Status404NotFound)] - public IActionResult GetCover(string MangaId, [FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)]CoverFormatRequestRecord? formatRequest) + public IActionResult GetCover(string MangaId, [FromQuery]int? width, [FromQuery]int? height) { Manga? m = context.Manga.Find(MangaId); if (m is null) @@ -112,14 +113,12 @@ public class MangaController(PgsqlContext context) : Controller Image image = Image.Load(m.CoverFileNameInCache); - if (formatRequest is not null) + if (width is { } w && height is { } h) { - if(!formatRequest.Validate()) - return BadRequest(); image.Mutate(i => i.ApplyProcessor(new ResizeProcessor(new ResizeOptions() { Mode = ResizeMode.Max, - Size = formatRequest.size + Size = new Size(w, h) }, image.Size))); }