Add Get All Templates to ImageManipulation

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

@ -48,6 +48,14 @@ public class ImageManipulationController : BaseController<ImageManipulationContr
/// /// /// ///
/// BOTTOM 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}")] [HttpGet("{template}")]
[EndpointMetrics("image.manipulation.generate")] [EndpointMetrics("image.manipulation.generate")]
[ProducesResponseType(typeof(Stream), StatusCodes.Status200OK, "image/png")] [ProducesResponseType(typeof(Stream), StatusCodes.Status200OK, "image/png")]

@ -17,6 +17,15 @@ public static partial class ImageManager
ManipulationEndpoints = configuration.GetSection("ImageManipulation:Templates").Get<List<ImageManipulationImage>>(); 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) public static async Task<object> GenerateMemeImageAsync(string template, string[] texts)
{ {
ImageManipulationImage imageTemplate = ManipulationEndpoints.FirstOrDefault(e => e.Name.ToLowerInvariant().Equals(template.ToLowerInvariant())); ImageManipulationImage imageTemplate = ManipulationEndpoints.FirstOrDefault(e => e.Name.ToLowerInvariant().Equals(template.ToLowerInvariant()));

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