-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicroservice.cs
40 lines (38 loc) · 1.63 KB
/
Microservice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Microsoft.AspNetCore.Mvc;
using CommandLine;
static class Microservice
{
public static void Run(IConfiguration configuration, Database database, TranskribusClient transkribusClient, MsvcOptions options)
{
Console.WriteLine("Setting up microservice...");
var builder = WebApplication.CreateBuilder(options.AspNetArgs.SplitArgs());
builder.Services.AddSingleton(configuration);
builder.Services.AddSingleton(database);
builder.Services.AddSingleton(transkribusClient);
builder.Services.AddScoped<Processor>();
var app = builder.Build();
app.MapGet("/", (
[FromHeader(Name = "X-Islandora-Args")] string args,
[FromHeader(Name = "Apix-Ldp-Resource")] string fileUri,
Processor processor
) =>
{
var parseResult = Parser.Default.ParseArguments<MicroservicePageOptions, MicroserviceOcrOptions>(args.SplitArgs());
return parseResult.MapResult(
async (MicroservicePageOptions options) =>
{
var file = await processor.ProcessSinglePage(new Uri(fileUri), options);
return Results.File(file, "application/xml");
},
async (MicroserviceOcrOptions options) =>
{
var file = await processor.CreateSinglePageOcr(new Uri(fileUri), options);
return Results.File(file, "text/plain");
},
error => Task.FromResult(Results.BadRequest())
);
});
Console.WriteLine("Running microservice");
app.Run();
}
}