Add Get All Templates to ImageManipulation

This commit is contained in:
2023-01-20 10:37:11 +00:00
parent 99122bf508
commit 2da300a197
3 changed files with 24 additions and 1 deletions

View File

@@ -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")]

View File

@@ -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()));

View File

@@ -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; }
}