Add Get All Templates to ImageManipulation

main
exsersewo 2 years ago
parent 99122bf508
commit 2da300a197
Signed by: exsersewo
GPG Key ID: 9C6DDF9AC9BA14A0
  1. 10
      src/Controllers/ImageManipulationController.cs
  2. 9
      src/Managers/ImageManager.Manipulation.cs
  3. 6
      src/Managers/Models/ImageManipulationImage.cs

@ -47,7 +47,15 @@ public class ImageManipulationController : BaseController<ImageManipulationContr
/// TOP TEXT ///
/// ///
/// BOTTOM TEXT ///
/// ------------- ///
/// ------------- ///
[HttpGet]
[EndpointMetrics("image.generate.get.templates")]
[ProducesResponseType(typeof(IEnumerable<ImageGenerationEndpointRead>), StatusCodes.Status200OK)]
public Task<object> GetTemplates()
{
return Task.FromResult(HttpContext.Send(EventResult.FromSuccess(ImageManager.GetManipulationEndpoints())));
}
[HttpGet("{template}")]
[EndpointMetrics("image.manipulation.generate")]
[ProducesResponseType(typeof(Stream), StatusCodes.Status200OK, "image/png")]

@ -17,6 +17,15 @@ public static partial class ImageManager
ManipulationEndpoints = configuration.GetSection("ImageManipulation:Templates").Get<List<ImageManipulationImage>>();
}
public static IEnumerable<ImageManipulationImageRead> GetManipulationEndpoints()
{
return ManipulationEndpoints.Select(e => new ImageManipulationImageRead
{
Name = e.Name,
TextRequired = e.TextPositions.Count()
});
}
public static async Task<object> GenerateMemeImageAsync(string template, string[] texts)
{
ImageManipulationImage imageTemplate = ManipulationEndpoints.FirstOrDefault(e => e.Name.ToLowerInvariant().Equals(template.ToLowerInvariant()));

@ -6,4 +6,10 @@ public class ImageManipulationImage : ImageEndpoint
{
[JsonPropertyName("textpositions"), ConfigurationKeyName("textpositions")]
public ICollection<PositionRect> TextPositions { get; set; }
}
public class ImageManipulationImageRead : ImageEndpoint
{
[JsonPropertyName("textrequired"), ConfigurationKeyName("textrequired")]
public int TextRequired { get; set; }
}
Loading…
Cancel
Save