- Updated `IMediaSourceCatalog` to support user-added media sources, allowing dynamic editing and management of sources. - Removed the `UrlListSource` class as its functionality is now integrated into the new catalog structure. - Enhanced `CollectOptions` to default `RequireProxy` to true, ensuring stricter handling of proxy requirements. - Improved error handling in `ParseError` to include a `Subject` field for better context on failures. - Adjusted dependency injection to reflect changes in media source management, removing old source registrations. - Introduced background proxy checks to ensure a more robust proxy pool management during collection processes. These changes streamline the media collection process and improve the overall user experience by providing clearer error reporting and more flexible source management.
58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using System.Text;
|
|
using AvParser.ImgTestService;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var options = builder.Configuration.GetSection("ImgTest").Get<ImgTestOptions>() ?? new ImgTestOptions();
|
|
var endpoints = options.BuildLookup();
|
|
|
|
var app = builder.Build();
|
|
|
|
// A plain index so opening the host in a browser explains what is here.
|
|
app.MapGet(
|
|
"/",
|
|
() =>
|
|
{
|
|
var text = new StringBuilder();
|
|
text.AppendLine("AvParser image test service");
|
|
text.AppendLine();
|
|
text.AppendLine($"miss rate: {options.MissRate:0.###}");
|
|
text.AppendLine("endpoints:");
|
|
foreach (var endpoint in endpoints.Values)
|
|
{
|
|
var ext = endpoint.Extensions.Length == 0 ? "(none)" : string.Join(" ", endpoint.Extensions);
|
|
text.AppendLine(
|
|
$" /{endpoint.Path}/{{id}} length {endpoint.MinLength}-{endpoint.MaxLength}, "
|
|
+ $"{endpoint.Allowed.Count} chars, ext {ext}"
|
|
);
|
|
}
|
|
|
|
return Results.Text(text.ToString(), "text/plain; charset=utf-8");
|
|
}
|
|
);
|
|
|
|
app.MapGet("/healthz", () => Results.Text("ok", "text/plain"));
|
|
|
|
// One handler for every configured endpoint: the first segment selects the config, the second is
|
|
// the id (optionally with an extension). A miss and an unknown endpoint are both a plain 404.
|
|
app.MapGet(
|
|
"/{endpoint}/{id}",
|
|
(string endpoint, string id) =>
|
|
{
|
|
if (!endpoints.TryGetValue(endpoint, out var config))
|
|
{
|
|
return Results.NotFound();
|
|
}
|
|
|
|
var core = config.StripExtension(id);
|
|
if (!config.Matches(core) || ImgTestOptions.IsMiss(core, options.MissRate))
|
|
{
|
|
return Results.NotFound();
|
|
}
|
|
|
|
return Results.Bytes(Identicon.Render(core), "image/png");
|
|
}
|
|
);
|
|
|
|
app.Run();
|