Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
72 lines
3.2 KiB
C#
72 lines
3.2 KiB
C#
using Febe.Core.Library;
|
|
using Febe.Web.Connection;
|
|
|
|
namespace Febe.Server;
|
|
|
|
/// <summary>
|
|
/// The checks made before anything starts (spec §8.2, §11): the interface password and the Data folder. With a problem
|
|
/// the engine and the browser do not start, and the interface shows only the page that explains it.
|
|
/// </summary>
|
|
internal static class StartupChecks
|
|
{
|
|
public const string PasswordMissing = "password-mancante";
|
|
|
|
public const string DataNotWritable = "dati-non-scrivibili";
|
|
|
|
public const string DataOnNetwork = "dati-in-rete";
|
|
|
|
/// <summary>Every problem found, in the order the error page shows them.</summary>
|
|
public static IReadOnlyList<ConfigurationProblem> Run(ServerOptions options, DataFolderCheck? check = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
var problems = new List<ConfigurationProblem>();
|
|
if (string.IsNullOrEmpty(options.Password))
|
|
{
|
|
problems.Add(new ConfigurationProblem(
|
|
PasswordMissing,
|
|
"Manca la password dell'interfaccia",
|
|
"Il contenitore è partito senza la variabile FEBE_PASSWORD. Senza password l'interfaccia, e con lei la vista "
|
|
+ "remota del browser, sarebbe aperta a chiunque raggiunga il server: per questo Febe non ha avviato né il motore né il browser.",
|
|
"Imposta FEBE_PASSWORD (nel modello di Unraid o in compose.yml) con una frase lunga che usi solo qui, poi riavvia il contenitore."));
|
|
}
|
|
|
|
if ((check ?? new DataFolderCheck()).Check(options.DataFolder) is { } data)
|
|
{
|
|
problems.Add(new ConfigurationProblem(
|
|
data.Kind == DataFolderProblemKind.NetworkPath ? DataOnNetwork : DataNotWritable,
|
|
data.Title,
|
|
data.Explanation,
|
|
data.Remedy));
|
|
}
|
|
|
|
return problems;
|
|
}
|
|
}
|
|
|
|
/// <summary>The problems found at start-up; fixed for the life of the process (fixing one needs a restart).</summary>
|
|
internal sealed class StartupProblems(IReadOnlyList<ConfigurationProblem> problems) : IConfigurationProblems
|
|
{
|
|
public IReadOnlyList<ConfigurationProblem> Current { get; } = problems;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The link to Instagram while a configuration problem keeps the browser from starting: always «browser non
|
|
/// disponibile», and every command refused with the problem (the configuration gate refuses them earlier anyway).
|
|
/// </summary>
|
|
internal sealed class UnavailableConnectionService(IReadOnlyList<ConfigurationProblem> problems) : IConnectionService
|
|
{
|
|
public Task<ConnectionStatus> GetStatusAsync(CancellationToken ct) =>
|
|
Task.FromResult(new ConnectionStatus(ConnectionState.BrowserUnavailable, null, null, false, null));
|
|
|
|
public Task BeginUserDrivingAsync(bool openLogin, CancellationToken ct) => throw Refused();
|
|
|
|
public Task<FinishResult> FinishAsync(CancellationToken ct) => throw Refused();
|
|
|
|
public Task CancelAsync(CancellationToken ct) => Task.CompletedTask;
|
|
|
|
public Task DisconnectAsync(CancellationToken ct) => throw Refused();
|
|
|
|
private Febe.Web.Api.BadRequestException Refused() =>
|
|
new($"{(problems.Count > 0 ? problems[0].Title : "Configurazione da sistemare")}: il browser di Febe non è partito.");
|
|
}
|