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,107 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Febe.Web.Demo;
|
||||
|
||||
/// <summary>Scenes of the demo engine (spec §10.6), chosen by address: <c>?scena=…</c>.</summary>
|
||||
public enum DemoScene
|
||||
{
|
||||
/// <summary>«normale»: between two sessions, «In ascolto».</summary>
|
||||
Normal,
|
||||
|
||||
/// <summary>«sessione»: a session in progress.</summary>
|
||||
Session,
|
||||
|
||||
/// <summary>«fermo»: stopped for a verification, red strip on every page.</summary>
|
||||
Stopped,
|
||||
|
||||
/// <summary>«scollegato»: no Instagram session yet.</summary>
|
||||
Disconnected,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Per-request choices of the demo: the scene (<c>scena</c>) and the shell it imitates (<c>veste</c>: desktop or docker).
|
||||
/// The page carries them on every call as query parameters or headers (<c>X-Febe-Scena</c>, <c>X-Febe-Veste</c>), so
|
||||
/// every page stays in the chosen scene. Outside the demo they are ignored.
|
||||
/// </summary>
|
||||
public static class DemoRequest
|
||||
{
|
||||
public const string SceneQuery = "scena";
|
||||
public const string EditionQuery = "veste";
|
||||
public const string SceneHeader = "X-Febe-Scena";
|
||||
public const string EditionHeader = "X-Febe-Veste";
|
||||
|
||||
private const string SceneItem = "febe.demo.scena";
|
||||
private const string EditionItem = "febe.demo.veste";
|
||||
|
||||
public static IReadOnlyList<string> SceneNames { get; } = ["normale", "sessione", "fermo", "scollegato"];
|
||||
|
||||
public static DemoScene? ParseScene(string? text) => text?.Trim().ToLowerInvariant() switch
|
||||
{
|
||||
"normale" => DemoScene.Normal,
|
||||
"sessione" => DemoScene.Session,
|
||||
"fermo" => DemoScene.Stopped,
|
||||
"scollegato" => DemoScene.Disconnected,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
public static string SceneName(DemoScene scene) => scene switch
|
||||
{
|
||||
DemoScene.Session => "sessione",
|
||||
DemoScene.Stopped => "fermo",
|
||||
DemoScene.Disconnected => "scollegato",
|
||||
_ => "normale",
|
||||
};
|
||||
|
||||
public static FebeEdition? ParseEdition(string? text) => text?.Trim().ToLowerInvariant() switch
|
||||
{
|
||||
"desktop" or "windows" => FebeEdition.Desktop,
|
||||
"docker" => FebeEdition.Docker,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>The scene of this request (normal when not given).</summary>
|
||||
public static DemoScene Scene(HttpContext? context) =>
|
||||
context?.Items.TryGetValue(SceneItem, out var value) == true && value is DemoScene scene ? scene : DemoScene.Normal;
|
||||
|
||||
/// <summary>The shell this request imitates, or null when not given.</summary>
|
||||
public static FebeEdition? Edition(HttpContext? context) =>
|
||||
context?.Items.TryGetValue(EditionItem, out var value) == true && value is FebeEdition edition ? edition : null;
|
||||
|
||||
internal static void Capture(HttpContext context)
|
||||
{
|
||||
var scene = ParseScene(First(context, SceneQuery, SceneHeader));
|
||||
if (scene is not null)
|
||||
{
|
||||
context.Items[SceneItem] = scene.Value;
|
||||
}
|
||||
|
||||
var edition = ParseEdition(First(context, EditionQuery, EditionHeader));
|
||||
if (edition is not null)
|
||||
{
|
||||
context.Items[EditionItem] = edition.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private static string? First(HttpContext context, string query, string header)
|
||||
{
|
||||
var fromQuery = context.Request.Query[query].ToString();
|
||||
if (fromQuery.Length > 0)
|
||||
{
|
||||
return fromQuery;
|
||||
}
|
||||
|
||||
var fromHeader = context.Request.Headers[header].ToString();
|
||||
return fromHeader.Length > 0 ? fromHeader : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Reads the demo choices of each request (registered only in demo mode).</summary>
|
||||
public sealed class DemoRequestMiddleware(RequestDelegate next)
|
||||
{
|
||||
public Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
DemoRequest.Capture(context);
|
||||
return next(context);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user