Vorarbeit: WebUntis-API

This commit is contained in:
2026-08-24 12:14:36 +02:00
parent a30aab0fa5
commit 5841d96c5b
10 changed files with 1377 additions and 0 deletions
+23
View File
@@ -97,6 +97,28 @@ builder.Services.AddHttpClient("dwd", client =>
});
builder.Services.AddSingleton(sp => new DwdWeatherService(
sp.GetRequiredService<IHttpClientFactory>().CreateClient("dwd")));
builder.Services.Configure<WebUntisOptions>(options =>
{
builder.Configuration.GetSection("WebUntis").Bind(options);
options.School = builder.Configuration["WEBUNTIS_SCHOOL"] ?? options.School;
options.Host = builder.Configuration["WEBUNTIS_HOST"] ?? options.Host;
options.Username = builder.Configuration["WEBUNTIS_USER"] ?? options.Username;
options.Password = builder.Configuration["WEBUNTIS_PASSWORD"] ?? options.Password;
options.Client = builder.Configuration["WEBUNTIS_CLIENT"] ?? options.Client;
if (int.TryParse(builder.Configuration["WEBUNTIS_SESSION_IDLE_MINUTES"], out var idleMinutes))
options.SessionIdleTimeoutMinutes = idleMinutes;
});
builder.Services.AddHttpClient("webuntis", client =>
{
// Die einzelnen WebUntis-Schritte besitzen eigene Timeouts; insbesondere ein asynchron
// erzeugter Schülerreport darf länger als der HttpClient-Standardtimeout pollen.
client.Timeout = Timeout.InfiniteTimeSpan;
});
// Der Client hält eine WebUntis-Session über mehrere API-Aufrufe hinweg. Deshalb muss seine
// Lebensdauer der Serveranwendung entsprechen und darf nicht pro HTTP-Anfrage neu beginnen.
builder.Services.AddSingleton(sp => new WebUntisClient(
sp.GetRequiredService<IHttpClientFactory>().CreateClient("webuntis"),
sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<WebUntisOptions>>()));
var app = builder.Build();
app.UseForwardedHeaders();
@@ -112,5 +134,6 @@ app.MapSnapshotEndpoints();
app.MapReadableSnapshotEndpoints();
app.MapPlainSyncEndpoints();
app.MapSchoolWeatherEndpoints();
app.MapWebUntisEndpoints();
app.Run();
return 0;