First Commit 2nd run

This commit is contained in:
2025-11-03 16:25:07 +10:30
parent d1d2c9f41e
commit fa9d535a34
26 changed files with 691 additions and 821 deletions
+48 -37
View File
@@ -1,42 +1,53 @@
using TinfoilVibeServer.Middleware;
// File: TinfoilVibeServer/Program.cs
using LibHac.Common.Keys;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using TinfoilVibeServer.Config;
using TinfoilVibeServer.Models;
using TinfoilVibeServer.Services;
using TinfoilVibeServer.Persistence;
var builder = WebApplication.CreateBuilder(args);
namespace TinfoilVibeServer;
// -----------------------------------------------------
// 1. Register AuthStore as a singleton
// -----------------------------------------------------
builder.Services.AddSingleton<AuthStore>();
// -----------------------------------------------------
// 2. Snapshot + other services (unchanged)
// -----------------------------------------------------
builder.Services.AddSingleton<SnapshotService>();
// … any other services you already have
var app = builder.Build();
// -----------------------------------------------------
// 3. Apply authentication middleware *before* the
// snapshot endpoints. This guarantees all routes
// are protected.
// -----------------------------------------------------
app.UseMiddleware<BasicAuthMiddleware>();
// -----------------------------------------------------
// 4. Existing endpoints unchanged
// -----------------------------------------------------
app.MapGet("/", () => Results.Redirect("/index.tfl"));
app.MapGet("/index.tfl", async context =>
internal static class Program
{
var jsonPath = Path.Combine(AppContext.BaseDirectory, "index.tfl");
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(await File.ReadAllTextAsync(jsonPath));
});
app.MapGet("/debug", () => new SnapshotService(builder.Configuration).GetSnapshot());
app.MapGet("/stream/{*relativePath}", async context =>
{
// … (unchanged streaming logic same as before)
});
public static void Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, cfg) =>
{
cfg.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
cfg.AddEnvironmentVariables();
cfg.AddCommandLine(args);
})
.ConfigureServices((ctx, services) =>
{
// Configuration POCO
services.Configure<GameDirectoriesOptions>(ctx.Configuration.GetSection("GameDirectories"));
app.Run();
// Snapshot persistence
services.AddSingleton<ISnapshotRepository, SnapshotRepository>();
// LibHac parser
services.AddSingleton<ILibHacParser, LibHacParser>();
// Main service
services.AddHostedService<GameDirectoryWatcherService>();
KeySetHolder.KeySet = ExternalKeyReader.ReadKeyFile(ctx.Configuration.GetSection("KeySet").Get<string>());
})
.ConfigureLogging((ctx, logging) =>
{
logging.ClearProviders();
logging.AddConsole(options =>
{
options.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
});
})
.Build();
host.Run();
}
}