mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-15 12:53:17 +02:00
Manga Cover request retrieve sizing from query instead of body
This commit is contained in:
parent
34ec185125
commit
a43901564b
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -92,7 +92,8 @@ public class MangaController(PgsqlContext context) : Controller
|
|||||||
/// Returns Cover of Manga
|
/// Returns Cover of Manga
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="MangaId">Manga-ID</param>
|
/// <param name="MangaId">Manga-ID</param>
|
||||||
/// <param name="formatRequest">Formatting/Resizing Request</param>
|
/// <param name="width">If width is provided, height needs to also be provided</param>
|
||||||
|
/// <param name="height">If height is provided, width needs to also be provided</param>
|
||||||
/// <response code="200">JPEG Image</response>
|
/// <response code="200">JPEG Image</response>
|
||||||
/// <response code="204">Cover not loaded</response>
|
/// <response code="204">Cover not loaded</response>
|
||||||
/// <response code="400">The formatting-request was invalid</response>
|
/// <response code="400">The formatting-request was invalid</response>
|
||||||
@ -102,7 +103,7 @@ public class MangaController(PgsqlContext context) : Controller
|
|||||||
[ProducesResponseType(Status204NoContent)]
|
[ProducesResponseType(Status204NoContent)]
|
||||||
[ProducesResponseType(Status400BadRequest)]
|
[ProducesResponseType(Status400BadRequest)]
|
||||||
[ProducesResponseType(Status404NotFound)]
|
[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);
|
Manga? m = context.Manga.Find(MangaId);
|
||||||
if (m is null)
|
if (m is null)
|
||||||
@ -112,14 +113,12 @@ public class MangaController(PgsqlContext context) : Controller
|
|||||||
|
|
||||||
Image image = Image.Load(m.CoverFileNameInCache);
|
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()
|
image.Mutate(i => i.ApplyProcessor(new ResizeProcessor(new ResizeOptions()
|
||||||
{
|
{
|
||||||
Mode = ResizeMode.Max,
|
Mode = ResizeMode.Max,
|
||||||
Size = formatRequest.size
|
Size = new Size(w, h)
|
||||||
}, image.Size)));
|
}, image.Size)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user