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

+199
View File
@@ -0,0 +1,199 @@
using System.Globalization;
using Febe.Core.Domain;
using Febe.Core.Engine;
using Febe.Core.Library;
namespace Febe.Web.Api;
/// <summary>The settings of an account (spec §4.4, mockup 05) between the domain and the form of the page.</summary>
public static class AccountSettingsMapper
{
public const double MinCustomPostHours = 1;
public const double MaxCustomPostHours = 48;
public const double MinCustomStoryHours = 1;
public const double MaxCustomStoryHours = 24;
/// <summary>Largest «Storico, massimo al giorno» the form accepts: twice the «Rapido» value (spec §7.5).</summary>
public static int MaxBackfillPerDay => CautionProfile.Fast.BackfillPostsPerAccountPerDay * 2;
public static AccountSettingsDto ToDto(Account account)
{
ArgumentNullException.ThrowIfNull(account);
var reference = account with { IsFollowed = false, Frequency = account.Frequency == Frequency.Custom ? Frequency.Custom : account.Frequency };
return new AccountSettingsDto(
account.KeepUpdated,
ApiMapping.Frequency(account.Frequency),
Math.Round((account.CustomPostInterval ?? CheckPolicy.ProfileCheckInterval(reference)).TotalHours, 2),
Math.Round((account.CustomStoryInterval ?? CheckPolicy.StoryMaxInterval(reference)).TotalHours, 2),
ApiMapping.Types(account.ContentTypes),
ApiMapping.Depth(account.Limits.Depth),
account.Limits.LastPosts,
account.Limits.FromDate is { } from ? from.UtcDateTime.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) : null,
account.Limits.BackfillPostsPerDay,
account.Limits.MaxVideoBytes is { } bytes ? Math.Round(bytes / 1024d / 1024d, 1) : null,
account.Limits.StoryVideos,
account.Folder);
}
/// <summary>
/// Applies the form to an account, with Italian errors for values out of range. «Tieni aggiornato» moves the state:
/// off on an up-to-date account pauses it (the single download is done), on reactivates a paused one.
/// </summary>
/// <param name="account">The stored account.</param>
/// <param name="dto">The form.</param>
/// <param name="zone">Alberto's zone (dates of «Da una data»).</param>
/// <param name="now">Now (state change time).</param>
/// <param name="folder">The folder value already resolved by the caller (null: default).</param>
public static Account Apply(Account account, AccountSettingsDto dto, TimeZoneInfo zone, DateTimeOffset now, string? folder)
{
ArgumentNullException.ThrowIfNull(account);
ArgumentNullException.ThrowIfNull(dto);
ArgumentNullException.ThrowIfNull(zone);
var frequency = ApiMapping.ParseFrequency(dto.Frequency) ?? throw new BadRequestException("Frequenza sconosciuta.");
TimeSpan? customPost = account.CustomPostInterval;
TimeSpan? customStory = account.CustomStoryInterval;
if (frequency == Frequency.Custom)
{
if (dto.CustomPostHours is not { } postHours || double.IsNaN(postHours) || postHours < MinCustomPostHours || postHours > MaxCustomPostHours)
{
throw new BadRequestException($"Su misura: i post si controllano fra ogni {Number(MinCustomPostHours)} e ogni {Number(MaxCustomPostHours)} ore.");
}
if (dto.CustomStoryHours is not { } storyHours || double.IsNaN(storyHours) || storyHours < MinCustomStoryHours || storyHours > MaxCustomStoryHours)
{
throw new BadRequestException($"Su misura: fra due controlli delle storie passano da {Number(MinCustomStoryHours)} a {Number(MaxCustomStoryHours)} ore.");
}
customPost = TimeSpan.FromMinutes(Math.Round(postHours * 60));
customStory = TimeSpan.FromMinutes(Math.Round(storyHours * 60));
}
var types = ApiMapping.Types(dto.Types ?? throw new BadRequestException("Manca «Cosa scaricare»."));
var depth = ApiMapping.ParseDepth(dto.Depth) ?? throw new BadRequestException("«Quanto indietro nel tempo» non valido.");
int? lastPosts = null;
DateTimeOffset? fromDate = null;
if (depth == HistoryDepth.LastPosts)
{
if (dto.LastPosts is not { } n || n < 1 || n > 1_000_000)
{
throw new BadRequestException("Indica quanti post tenere: almeno 1.");
}
lastPosts = n;
}
else if (depth == HistoryDepth.FromDate)
{
var day = ApiMapping.ParseDay(dto.FromDate) ?? throw new BadRequestException("Indica la data da cui partire.");
if (day > LocalCalendar.Today(now, zone))
{
throw new BadRequestException("La data da cui partire non può essere nel futuro.");
}
fromDate = LocalCalendar.StartOfDay(day, zone);
}
if (dto.BackfillPerDay < 1 || dto.BackfillPerDay > MaxBackfillPerDay)
{
throw new BadRequestException($"Storico, massimo al giorno: fra 1 e {ItalianText.Number(MaxBackfillPerDay)} post.");
}
long? maxVideo = null;
if (dto.MaxVideoMb is { } mb)
{
if (double.IsNaN(mb) || mb < 1 || mb > 100_000)
{
throw new BadRequestException("Salta i video oltre: un numero di MB da 1 in su, oppure vuoto per nessun limite.");
}
maxVideo = (long)Math.Round(mb * 1024 * 1024);
}
var state = account.State;
var changedAt = account.StateChangedAt;
if (account.KeepUpdated && !dto.KeepUpdated && state == AccountState.UpToDate)
{
state = AccountState.Paused;
changedAt = now;
}
else if (!account.KeepUpdated && dto.KeepUpdated && state == AccountState.Paused)
{
state = ReactivatedState(account, depth);
changedAt = now;
}
return account with
{
KeepUpdated = dto.KeepUpdated,
Frequency = frequency,
CustomPostInterval = customPost,
CustomStoryInterval = customStory,
ContentTypes = types,
Limits = account.Limits with
{
Depth = depth,
LastPosts = lastPosts,
FromDate = fromDate,
BackfillPostsPerDay = dto.BackfillPerDay,
MaxVideoBytes = maxVideo,
StoryVideos = dto.StoryVideos,
},
Folder = folder,
State = state,
StateChangedAt = changedAt,
};
}
/// <summary>State of a paused account that comes back: backfilling while its history is not complete.</summary>
public static AccountState ReactivatedState(Account account, HistoryDepth? depth = null)
{
ArgumentNullException.ThrowIfNull(account);
var d = depth ?? account.Limits.Depth;
return account.BackfillCompletedAt is null && d != HistoryDepth.FromDate && CheckPolicy.WantsProfileChecks(account)
? AccountState.Backfilling
: AccountState.UpToDate;
}
/// <summary>«Nuovi post ogni 3 ore circa, storie almeno ogni 6 ore» beside the frequency buttons.</summary>
public static string FrequencyHint(Account account)
{
ArgumentNullException.ThrowIfNull(account);
var parts = new List<string>();
if (CheckPolicy.WantsProfileChecks(account))
{
parts.Add(account.IsFollowed
? "nuovi post dal giro dei profili che segui, profilo riaperto " + ItalianText.Every(CheckPolicy.ProfileCheckInterval(account))
: "nuovi post " + ItalianText.Every(CheckPolicy.ProfileCheckInterval(account)) + " circa");
}
if (CheckPolicy.WantsStories(account))
{
parts.Add("storie almeno " + ItalianText.Every(CheckPolicy.StoryMaxInterval(account)));
}
return parts.Count == 0 ? "Niente da controllare con queste scelte." : ItalianText.Capitalize(string.Join(", ", parts));
}
/// <summary>The note under the panel: what being followed or not means for this account.</summary>
public static string? Note(Account account)
{
ArgumentNullException.ThrowIfNull(account);
if (account.State == AccountState.ArchiveOnly || account.IsMine)
{
return null;
}
if (!account.IsFollowed && !account.IsPrivate)
{
return "È un profilo pubblico che non segui: per vedere le novità Febe deve aprire la sua pagina. Se diventa privato, Febe si ferma e ti avvisa.";
}
if (account.IsFollowed)
{
return "Lo segui: le novità arrivano dal giro dei profili che segui, senza aprire ogni volta la sua pagina.";
}
return null;
}
private static string Number(double value) => ItalianText.Decimal(value, 1);
}