Add Get All Templates to ImageManipulation
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
Reference in New Issue
Block a user