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:
Claude committed 2026-10-13 19:14:35 +00:00
1 parent 6ff11ac8e3
commit e33540246e
76 files changed
+12503 -17

No files matched your search

+112
View File
@@ -0,0 +1,112 @@
using System.Text;
using Febe.Core.Abstractions;
using Febe.Core.Domain;
using Febe.Core.Storage;
using Febe.Web.Demo;
using Febe.Web.Hosting;
using Febe.Web.Native;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
namespace Febe.Web.Api;
/// <summary>Capabilities of the shell, preferences of the interface, the icon sprite.</summary>
public static class SystemApi
{
/// <summary>Setting key of the theme: «chiaro», «scuro» or «sistema».</summary>
public const string ThemeKey = "interfaccia.tema";
public static readonly IReadOnlyList<string> Themes = ["chiaro", "scuro", "sistema"];
public static void Map(IEndpointRouteBuilder endpoints, EmbeddedWwwroot files)
{
endpoints.MapGet("/api/capabilities", (HttpContext context, FebeWebOptions options, INativeShell shell, IBrowserWindow browser, IClock clock) =>
ApiHttp.Json(Capabilities(context, options, shell, browser, clock), FebeJsonContext.Default.CapabilitiesDto));
endpoints.MapGet("/api/preferences", async (IFebeStorage storage, CancellationToken ct) =>
{
var theme = await storage.Settings.GetAsync(ThemeKey, ct).ConfigureAwait(false);
return ApiHttp.Json(new PreferencesDto(Themes.Contains(theme) ? theme! : "sistema"), FebeJsonContext.Default.PreferencesDto);
});
endpoints.MapPut("/api/preferences", async (HttpContext context, IFebeStorage storage, CancellationToken ct) =>
{
var body = await ApiHttp.BodyAsync(context, FebeJsonContext.Default.PreferencesDto).ConfigureAwait(false);
if (!Themes.Contains(body.Theme))
{
throw new BadRequestException("Tema sconosciuto: si sceglie fra chiaro, scuro e come il sistema.");
}
await storage.Settings.SetAsync(ThemeKey, body.Theme, ct).ConfigureAwait(false);
return ApiHttp.Json(body, FebeJsonContext.Default.PreferencesDto);
});
// Every icon of wwwroot/icone as one sprite of <symbol id="i-name">, inlined once by the page.
var cached = new Lazy<string>(() => BuildSprite(files));
string Sprite() => files.FromDisk ? BuildSprite(files) : cached.Value;
endpoints.MapGet("/icone/tutte.svg", (HttpContext context) =>
{
context.Response.Headers.CacheControl = "no-cache";
return Results.Text(Sprite(), "image/svg+xml; charset=utf-8");
});
}
public static CapabilitiesDto Capabilities(HttpContext context, FebeWebOptions options, INativeShell shell, IBrowserWindow browser, IClock clock)
{
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(options);
ArgumentNullException.ThrowIfNull(shell);
ArgumentNullException.ThrowIfNull(browser);
ArgumentNullException.ThrowIfNull(clock);
var edition = options.Demo ? DemoRequest.Edition(context) ?? FebeEdition.Desktop : options.Edition;
var desktop = edition == FebeEdition.Desktop;
var demoDesktop = options.Demo && desktop;
return new CapabilitiesDto(
desktop ? "desktop" : "docker",
options.Demo,
options.Access switch { AccessMode.Password => "password", AccessMode.Token => "token", _ => "none" },
ShowInFolder: demoDesktop || (desktop && shell.CanShowInFolder),
PickFolder: demoDesktop || (desktop && shell.CanPickFolder),
OpenUrlNative: !options.Demo && shell.CanOpenUrl,
FoldersReadOnly: !desktop,
Autostart: demoDesktop || (desktop && shell.SupportsAutostart),
BrowserWindow: demoDesktop || (desktop && browser.IsSeparateWindow),
Notifications: demoDesktop || shell.CanNotify,
options.Version,
options.Demo ? DemoRequest.SceneName(DemoRequest.Scene(context)) : null,
options.Demo ? DemoRequest.SceneNames : [],
clock.Now.ToUnixTimeMilliseconds(),
ApiMapping.Day(LocalCalendar.Today(clock.Now, clock.LocalZone)));
}
/// <summary>The sprite: each Lucide file's drawing inside a symbol; stroke and fill come from the CSS of <c>svg.ic</c>.</summary>
public static string BuildSprite(EmbeddedWwwroot files)
{
ArgumentNullException.ThrowIfNull(files);
var builder = new StringBuilder("<svg xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\" style=\"display:none\">");
foreach (var path in files.Files.Where(f => f.StartsWith("icone/", StringComparison.Ordinal) && f.EndsWith(".svg", StringComparison.Ordinal)).Order(StringComparer.Ordinal))
{
var text = files.ReadText(path);
if (text is null)
{
continue;
}
var open = text.IndexOf("<svg", StringComparison.Ordinal);
var openEnd = open < 0 ? -1 : text.IndexOf('>', open);
var close = text.LastIndexOf("</svg>", StringComparison.Ordinal);
if (openEnd < 0 || close <= openEnd)
{
continue;
}
var name = path["icone/".Length..^".svg".Length];
builder.Append("<symbol id=\"i-").Append(name).Append("\" viewBox=\"0 0 24 24\">")
.Append(text[(openEnd + 1)..close].Trim())
.Append("</symbol>");
}
return builder.Append("</svg>").ToString();
}
}