Interfaccia web, parte 1: ospite, sicurezza, API, modalità dimostrativa, libreria, visualizzatore e account
Febe.Web: AddFebeWeb/UseFebe/FebeWebHost per le due vesti, interfaccia incorporata con IFileProvider proprio, indirizzi italiani, API JSON con contesto generato, eventi SSE, controlli di Host/Origin, gettone del desktop e password con blocco (§13.1), INativeShell e capacità per veste. Modalità --demo con 38 account e circa 18.000 elementi finti e scene del motore. Pagine Libreria, Visualizzatore, Account, Aggiungi account e Scheda account (contenuti, impostazioni con piano, cronologia); schermate in docs/schermate con le differenze dai mockup; prove delle API, della sicurezza, dell'esportazione CSV e dei dati dimostrativi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
76 files changed
+12503
-17
No files matched your search
@@ -0,0 +1,134 @@
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Core.Engine;
|
||||
using Febe.Core.Library;
|
||||
using Febe.Core.Storage;
|
||||
using Febe.Data;
|
||||
using Febe.Web.Engine;
|
||||
using Febe.Web.Library;
|
||||
using Febe.Web.Native;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Febe.Web.Demo;
|
||||
|
||||
/// <summary>Options of <c>--demo</c>.</summary>
|
||||
/// <param name="Port">Port on 127.0.0.1 (8480 by default; 0 picks a free one).</param>
|
||||
/// <param name="Zone">Alberto's time zone for the demo (the system zone by default).</param>
|
||||
/// <param name="Root">Parent of the temporary folder (the system temporary folder by default).</param>
|
||||
/// <param name="InterfaceFolder">Development: serve the interface from this folder (see <see cref="FebeWebOptions.InterfaceFolder"/>).</param>
|
||||
public sealed record DemoOptions(int Port = FebeListen.DefaultPort, TimeZoneInfo? Zone = null, string? Root = null, string? InterfaceFolder = null);
|
||||
|
||||
/// <summary>
|
||||
/// Demo mode (spec §10.6): starts without browser and network, listening only on 127.0.0.1 and without password, with
|
||||
/// a temporary Data folder and a temporary library seeded with coherent demo data. It cannot write to the real
|
||||
/// library: every path lives under a new temporary folder, removed when the demo ends.
|
||||
/// </summary>
|
||||
public sealed class DemoHost : IAsyncDisposable
|
||||
{
|
||||
private readonly FebeDatabase _database;
|
||||
|
||||
private DemoHost(string root, FebeDatabase database, WebApplication app, DemoWorld world, Uri address)
|
||||
{
|
||||
Root = root;
|
||||
_database = database;
|
||||
App = app;
|
||||
World = world;
|
||||
Address = address;
|
||||
}
|
||||
|
||||
/// <summary>The temporary folder of this demo (Data and library inside).</summary>
|
||||
public string Root { get; }
|
||||
|
||||
public WebApplication App { get; }
|
||||
|
||||
public DemoWorld World { get; }
|
||||
|
||||
/// <summary>Where the interface answers, e.g. http://127.0.0.1:8480/.</summary>
|
||||
public Uri Address { get; }
|
||||
|
||||
public IFebeStorage Storage => _database;
|
||||
|
||||
public static async Task<DemoHost> StartAsync(DemoOptions options, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
var root = Path.Combine(options.Root ?? Path.GetTempPath(), "febe-dimostrazione-" + Guid.NewGuid().ToString("N")[..10]);
|
||||
Directory.CreateDirectory(root);
|
||||
FebeDatabase? database = null;
|
||||
try
|
||||
{
|
||||
var clock = new SystemClock(options.Zone ?? TimeZoneInfo.Local);
|
||||
var data = new DataFolderLayout(Path.Combine(root, "dati"));
|
||||
var layout = new LibraryLayout(Path.Combine(root, "libreria"));
|
||||
Directory.CreateDirectory(data.Root);
|
||||
Directory.CreateDirectory(layout.Root);
|
||||
database = await FebeDatabase.OpenAsync(data.Root, ct).ConfigureAwait(false);
|
||||
await database.Settings.SetAsync(SettingKeys.LibraryRoot, layout.Root, ct).ConfigureAwait(false);
|
||||
var world = await DemoSeeder.SeedAsync(database, data, layout, clock, ct).ConfigureAwait(false);
|
||||
var library = new FebeLibrary(database, data, layout, clock);
|
||||
var web = new FebeWebOptions
|
||||
{
|
||||
Edition = FebeEdition.Desktop,
|
||||
Access = AccessMode.None,
|
||||
AllowedHosts = FebeWebOptions.LoopbackHosts(options.Port),
|
||||
Demo = true,
|
||||
InterfaceFolder = options.InterfaceFolder,
|
||||
};
|
||||
var db = database;
|
||||
var app = FebeWebHost.Build(web, FebeListen.Loopback(options.Port), services =>
|
||||
{
|
||||
services.AddSingleton<IFebeStorage>(db);
|
||||
services.AddSingleton(library);
|
||||
services.AddSingleton<IClock>(clock);
|
||||
services.AddSingleton(world);
|
||||
services.AddSingleton<DemoEngine>();
|
||||
services.AddSingleton<IEngineMonitor>(sp => sp.GetRequiredService<DemoEngine>());
|
||||
services.AddSingleton<IEngineControl>(sp => sp.GetRequiredService<DemoEngine>());
|
||||
services.AddSingleton(sp => new DemoShell(sp.GetRequiredService<IHttpContextAccessor>(), root));
|
||||
services.AddSingleton<INativeShell>(sp => sp.GetRequiredService<DemoShell>());
|
||||
services.AddSingleton<IBrowserWindow>(sp => sp.GetRequiredService<DemoShell>());
|
||||
services.AddSingleton<IMediaFileResolver, DemoFileResolver>();
|
||||
});
|
||||
await app.StartAsync(ct).ConfigureAwait(false);
|
||||
return new DemoHost(root, database, app, world, FebeWebHost.BoundAddress(app));
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (database is not null)
|
||||
{
|
||||
await database.DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
TryDelete(root);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await App.StopAsync().ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await App.DisposeAsync().ConfigureAwait(false);
|
||||
await _database.DisposeAsync().ConfigureAwait(false);
|
||||
TryDelete(Root);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryDelete(string root)
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(root, recursive: true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user