Untis-API von Server zu Client

This commit is contained in:
2026-08-24 22:00:26 +02:00
parent 0f10f754d0
commit 34a9fdf73b
21 changed files with 243 additions and 445 deletions
-24
View File
@@ -97,29 +97,6 @@ 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>>()));
builder.Services.AddSingleton<WebUntisConnectionStore>();
var app = builder.Build();
app.UseForwardedHeaders();
@@ -135,6 +112,5 @@ app.MapSnapshotEndpoints();
app.MapReadableSnapshotEndpoints();
app.MapPlainSyncEndpoints();
app.MapSchoolWeatherEndpoints();
app.MapWebUntisEndpoints();
app.Run();
return 0;