feat: Phase 0 shells, design system, server skeleton, Docker and CI
- Titano.Ui: DESIGN.md tokens (dark/light), generated 16-px icon set, styles for all standard controls, custom chrome window with snap layouts, rail, job bar, Auto/manual slider, chips, toasts. - Titano desktop shell with sections, Settings (language, theme), About and a --capture screenshot mode. - Titano Server skeleton: env/server.json configuration, self-signed TLS with fingerprint, /health, /server/info, i18n endpoint and the embedded admin panel; in-process server tests. - Docker image (multi-arch, PUID/PGID, health check), compose file, Unraid template; CI, release and nightly workflows; changelog tool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
122 files changed
+6838
-22
No files matched your search
@@ -0,0 +1,130 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Titano.Server.Configuration;
|
||||
|
||||
public enum TlsMode
|
||||
{
|
||||
/// <summary>Self-signed certificate generated at first start (stored under /data/tls).</summary>
|
||||
Auto,
|
||||
|
||||
/// <summary>Certificate and key from PEM files.</summary>
|
||||
Pem,
|
||||
|
||||
/// <summary>Plain HTTP behind a TLS-terminating reverse proxy.</summary>
|
||||
Proxy,
|
||||
}
|
||||
|
||||
public enum DatabaseKind
|
||||
{
|
||||
Postgres,
|
||||
Sqlite,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Server configuration (BRIEF §14.9): environment variables override <c>/data/server.json</c>, which overrides defaults.
|
||||
/// </summary>
|
||||
public sealed class ServerOptions
|
||||
{
|
||||
public string ServerName { get; set; } = "Titano Server";
|
||||
public string ArchivePath { get; set; } = OperatingSystem.IsWindows() ? @"C:\TitanoArchive" : "/archive";
|
||||
public string DataPath { get; set; } = OperatingSystem.IsWindows() ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Titano Server") : "/data";
|
||||
public string? AdminUser { get; set; }
|
||||
public string? AdminPassword { get; set; }
|
||||
public DatabaseKind Database { get; set; } = OperatingSystem.IsWindows() ? DatabaseKind.Sqlite : DatabaseKind.Postgres;
|
||||
public string DbHost { get; set; } = "postgres";
|
||||
public int DbPort { get; set; } = 5432;
|
||||
public string DbName { get; set; } = "titano";
|
||||
public string DbUser { get; set; } = "titano";
|
||||
public string? DbPassword { get; set; }
|
||||
public string DbSslMode { get; set; } = "prefer";
|
||||
public int HttpPort { get; set; } = 8080;
|
||||
public int HttpsPort { get; set; } = 8443;
|
||||
public TlsMode TlsMode { get; set; } = TlsMode.Auto;
|
||||
public string? TlsCert { get; set; }
|
||||
public string? TlsKey { get; set; }
|
||||
public string Language { get; set; } = "en";
|
||||
public int Workers { get; set; } = Math.Max(1, Environment.ProcessorCount / 2);
|
||||
public bool Discovery { get; set; } = true;
|
||||
public long MaxUploadBytes { get; set; } = 2L * 1024 * 1024 * 1024;
|
||||
public int ChunkSizeBytes { get; set; } = 8 * 1024 * 1024;
|
||||
public int JobHistoryDays { get; set; } = 90;
|
||||
public int TokenLifetimeDays { get; set; } = 30;
|
||||
|
||||
[JsonIgnore]
|
||||
public string LogPath => Path.Combine(DataPath, "logs");
|
||||
|
||||
[JsonIgnore]
|
||||
public string TlsPath => Path.Combine(DataPath, "tls");
|
||||
|
||||
[JsonIgnore]
|
||||
public string UploadsPath => Path.Combine(DataPath, "uploads");
|
||||
|
||||
/// <summary>Loads <c>{DataPath}/server.json</c> (if present) then applies <c>TITANO_*</c> environment variables.</summary>
|
||||
public static ServerOptions Load(IReadOnlyDictionary<string, string?>? environment = null)
|
||||
{
|
||||
var env = environment ?? ReadEnvironment();
|
||||
string? Env(string name) => env.TryGetValue(name, out var v) && !string.IsNullOrWhiteSpace(v) ? v : null;
|
||||
|
||||
var dataPath = Env("TITANO_DATA_PATH") ?? new ServerOptions().DataPath;
|
||||
var options = new ServerOptions();
|
||||
var file = Path.Combine(dataPath, "server.json");
|
||||
if (File.Exists(file))
|
||||
{
|
||||
try
|
||||
{
|
||||
options = JsonSerializer.Deserialize(File.ReadAllText(file), ServerOptionsJson.Default.ServerOptions) ?? options;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
throw new InvalidOperationException($"{file} is not valid JSON: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
options.DataPath = dataPath;
|
||||
|
||||
options.ServerName = Env("TITANO_SERVER_NAME") ?? options.ServerName;
|
||||
options.ArchivePath = Env("TITANO_ARCHIVE_PATH") ?? options.ArchivePath;
|
||||
options.AdminUser = Env("TITANO_ADMIN_USER") ?? options.AdminUser;
|
||||
options.AdminPassword = Env("TITANO_ADMIN_PASSWORD") ?? options.AdminPassword;
|
||||
if (Env("TITANO_DB") is { } db) options.Database = Enum.Parse<DatabaseKind>(db, ignoreCase: true);
|
||||
options.DbHost = Env("TITANO_DB_HOST") ?? options.DbHost;
|
||||
if (Env("TITANO_DB_PORT") is { } port) options.DbPort = int.Parse(port, System.Globalization.CultureInfo.InvariantCulture);
|
||||
options.DbName = Env("TITANO_DB_NAME") ?? options.DbName;
|
||||
options.DbUser = Env("TITANO_DB_USER") ?? options.DbUser;
|
||||
options.DbPassword = Env("TITANO_DB_PASSWORD") ?? options.DbPassword;
|
||||
options.DbSslMode = Env("TITANO_DB_SSLMODE") ?? options.DbSslMode;
|
||||
if (Env("TITANO_HTTP_PORT") is { } http) options.HttpPort = int.Parse(http, System.Globalization.CultureInfo.InvariantCulture);
|
||||
if (Env("TITANO_HTTPS_PORT") is { } https) options.HttpsPort = int.Parse(https, System.Globalization.CultureInfo.InvariantCulture);
|
||||
if (Env("TITANO_TLS_MODE") is { } tls) options.TlsMode = Enum.Parse<TlsMode>(tls, ignoreCase: true);
|
||||
options.TlsCert = Env("TITANO_TLS_CERT") ?? options.TlsCert;
|
||||
options.TlsKey = Env("TITANO_TLS_KEY") ?? options.TlsKey;
|
||||
options.Language = Env("TITANO_LANG") ?? options.Language;
|
||||
if (Env("TITANO_WORKERS") is { } workers) options.Workers = Math.Max(1, int.Parse(workers, System.Globalization.CultureInfo.InvariantCulture));
|
||||
if (Env("TITANO_DISCOVERY") is { } discovery) options.Discovery = bool.Parse(discovery);
|
||||
options.Validate();
|
||||
return options;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string?> ReadEnvironment()
|
||||
{
|
||||
// Variables may differ only by case on Linux (no_proxy/NO_PROXY); the last one wins.
|
||||
var result = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (System.Collections.DictionaryEntry e in Environment.GetEnvironmentVariables()) result[(string)e.Key] = (string?)e.Value;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!OperatingSystem.IsWindows() && Database == DatabaseKind.Sqlite)
|
||||
throw new InvalidOperationException("TITANO_DB=sqlite is supported on Windows only; use postgres (BRIEF §14.9).");
|
||||
if (TlsMode == TlsMode.Pem && (string.IsNullOrEmpty(TlsCert) || string.IsNullOrEmpty(TlsKey)))
|
||||
throw new InvalidOperationException("TITANO_TLS_MODE=pem requires TITANO_TLS_CERT and TITANO_TLS_KEY.");
|
||||
// Port 0 asks the OS for a free port (used by the in-process test host).
|
||||
if (HttpPort is < 0 or > 65535 || HttpsPort is < 0 or > 65535)
|
||||
throw new InvalidOperationException("Ports must be between 0 and 65535.");
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, UseStringEnumConverter = true, PropertyNameCaseInsensitive = true)]
|
||||
[JsonSerializable(typeof(ServerOptions))]
|
||||
internal sealed partial class ServerOptionsJson : JsonSerializerContext;
|
||||
Reference in new issue
Block a user