Titano: time-lapse ecosystem (client, server, uploader) — in progress #1

Merged
Alby96 merged 204 commits from claude/keen-knuth-uhxv8w into main 2026-10-02 16:29:53 +02:00
Showing only changes of commit 145ecf33d2 - Show all commits
+14 -10
View File
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Titano.Core.Diagnostics;
using Titano.Data;
@@ -15,9 +16,11 @@ namespace Titano.Server.Hosting;
/// <summary>
/// Builds the Titano Server web application from <see cref="ServerOptions"/> (used by Program, the Windows service
/// host and tests). The archive module plugs in through <paramref name="configureServices"/> of <see cref="Build"/>:
/// it must register <see cref="IArchiveIngest"/> and <see cref="IFrameAssetLocator"/>, and may add
/// <see cref="Titano.Data.Jobs.IJobHandler"/>s; the server refuses to start without the first two.
/// host and tests). The archive module plugs in through the <c>configureServices</c> callback of <see cref="Build"/>,
/// which runs before the server's own registrations: it must register <see cref="IArchiveIngest"/> and
/// <see cref="IFrameAssetLocator"/> (the server refuses to start without them), may add
/// <see cref="Titano.Data.Jobs.IJobHandler"/>s, and may resolve <see cref="TitanoDatabase"/>, <see cref="ServerArchive"/>
/// and <see cref="ServerOptions"/> from DI in its factories.
/// </summary>
public static class ServerHost
{
@@ -38,6 +41,10 @@ public static class ServerHost
builder.Logging.AddFilter("Microsoft.AspNetCore", Microsoft.Extensions.Logging.LogLevel.Warning);
builder.Logging.AddFilter("Microsoft.Hosting.Lifetime", Microsoft.Extensions.Logging.LogLevel.Information);
// The archive module registers first, so a missing piece stops the server before it touches the database.
configureServices?.Invoke(builder.Services);
RequireArchiveModule(builder.Services);
using var bootLoggerFactory = LoggerFactory.Create(l => l.AddSimpleConsole(c => c.SingleLine = true));
var bootLogger = bootLoggerFactory.CreateLogger("Titano.Server");
var certificate = CertificateStore.Load(options, bootLogger);
@@ -66,10 +73,8 @@ public static class ServerHost
});
});
ConfigureServices(builder.Services, options, state, database, archive);
configureServices?.Invoke(builder.Services);
var app = builder.Build();
RequireArchiveModule(app.Services);
Log.SetSink(new LoggerSink(app.Services.GetRequiredService<ILoggerFactory>()));
ConfigurePipeline(app, options);
app.Logger.LogInformation("Titano Server {Version} · archive {Archive} · data {Data} · {Database} · TLS {Tls}{Fingerprint}",
@@ -93,7 +98,7 @@ public static class ServerHost
services.AddSingleton(state);
services.AddSingleton(database);
services.AddSingleton(archive);
services.AddSingleton(TimeProvider.System);
services.TryAddSingleton(TimeProvider.System);
services.ConfigureHttpJsonOptions(j => j.SerializerOptions.TypeInfoResolverChain.Insert(0, ProtocolJson.Default));
services.Configure<RouteHandlerOptions>(o => o.ThrowOnBadRequest = true);
services.Configure<HostOptions>(o => o.ShutdownTimeout = TimeSpan.FromSeconds(30));
@@ -152,12 +157,11 @@ public static class ServerHost
}
/// <summary>Fails fast when the archive module's services are missing (the server would accept uploads it cannot commit).</summary>
private static void RequireArchiveModule(IServiceProvider services)
private static void RequireArchiveModule(IServiceCollection services)
{
var registry = services.GetRequiredService<IServiceProviderIsService>();
var missing = new List<string>();
if (!registry.IsService(typeof(IArchiveIngest))) missing.Add($"{typeof(IArchiveIngest).FullName} (commits verified uploads into the archive layout)");
if (!registry.IsService(typeof(IFrameAssetLocator))) missing.Add($"{typeof(IFrameAssetLocator).FullName} (finds proxies and thumbnails)");
if (!services.Any(d => d.ServiceType == typeof(IArchiveIngest))) missing.Add($"{typeof(IArchiveIngest).FullName} (commits verified uploads into the archive layout)");
if (!services.Any(d => d.ServiceType == typeof(IFrameAssetLocator))) missing.Add($"{typeof(IFrameAssetLocator).FullName} (finds proxies and thumbnails)");
if (missing.Count > 0)
{
throw new InvalidOperationException(