Owner review 2, phase 5b (R8): a server is a project home. A workspace can
list a sequence's projects, make, rename and delete them, read their
versions and push new ones through /api/v1/sequences/{sid}/projects. The
endpoints run on the archive's ProjectService exactly as a desktop's archive
does (sidecars first, then the index, under the sequence's lease), so no
version is stored apart and a desktop sharing the archive sees the same
projects.
- Protocol: project, version, create, rename, version page, push answer
(outcome, stored version, head, plus code and message on 409/422) and
home frames DTOs, the projectChanged event, the "projects" capability and
the ChronosClient calls; a push returns its outcome without throwing on
409 or 422. ProjectWire maps them to and from the model for both sides.
- Server: Read lists and reads, Edit makes, renames and pushes, Delete (the
sequence's owner, the project's maker or an admin) deletes; refusals with
stable codes, 503 while the sequence is busy, offline or moved; the
pushing account becomes the version's author; creations, renames and
deletions audited, pushes logged.
- ProjectService tells the host what each call changed, compared under the
lease, so projectChanged also follows Main's external versions; a Main
version mirrored into the settings sends sequenceChanged too, for older
clients. ProjectCatchUp takes settings a PATCH, an analysis or a
conversion wrote into Main at once, for sequences that have a Main.
- Renders of a project version: POST /jobs checks the project and version
against the sequence and pins a project alone to its head; render nodes
get the version's settings placed on the frames they claim; the render
records the project and version.
- Admin panel: the sequence page lists its projects (Main marked, head,
last change, versions on demand) with Rename and Delete for the others,
live on projectChanged. It edits no settings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
4.9 KiB
C#
112 lines
4.9 KiB
C#
using System.Globalization;
|
|
using System.Reflection;
|
|
using Chronos.Core.Imaging;
|
|
using Chronos.Core.Localization;
|
|
using Chronos.Data;
|
|
using Chronos.Protocol;
|
|
using Chronos.Server.Configuration;
|
|
using Chronos.Server.Security;
|
|
|
|
namespace Chronos.Server.Api;
|
|
|
|
/// <summary><c>/health</c>, <c>/api/v1/server/info</c> and <c>/api/v1/i18n/{culture}</c> (all anonymous).</summary>
|
|
public static class SystemEndpoints
|
|
{
|
|
private static readonly string[] AdminAreas = ["Common", "Admin"];
|
|
|
|
/// <summary>Languages with translated resources (English plus every satellite of the catalog), for the admin language menu.</summary>
|
|
private static readonly Lazy<string> AdminLanguages = new(() => string.Join(',', Languages.Shipped.Where(code =>
|
|
{
|
|
if (code == "en") return true;
|
|
try
|
|
{
|
|
typeof(Loc).Assembly.GetSatelliteAssembly(CultureInfo.GetCultureInfo(code));
|
|
return true;
|
|
}
|
|
catch (FileNotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
})));
|
|
|
|
/// <summary>The extensions the archive scanner files as photos (BRIEF §8.1), which the admin panel's uploads keep to.</summary>
|
|
private static readonly string[] PhotoExtensions = [.. ImageFormatInfo.Known.SelectMany(f => f.Extensions)];
|
|
|
|
public static string Version { get; } =
|
|
typeof(SystemEndpoints).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "0.0.0";
|
|
|
|
public static void Map(WebApplication app, RouteGroupBuilder api)
|
|
{
|
|
app.MapGet("/health", HealthAsync);
|
|
|
|
api.MapGet("/server/info", (ServerOptions options, ServerState state) => Results.Json(new ServerInfo(
|
|
options.ServerName,
|
|
Version,
|
|
ApiVersion.Current,
|
|
state.Capabilities,
|
|
state.TlsFingerprint,
|
|
["jpeg", "png", "tiff", "dng", "cr2", "cr3", "nef", "arw", "raf", "orf", "rw2", "pef", "heic", "webp"],
|
|
new ServerLimits(options.MaxUploadBytes, options.ChunkSizeBytes, PasswordHasher.MinimumLength),
|
|
PhotoExtensions), ProtocolJson.Default.ServerInfo)).AllowAnonymousCaller();
|
|
|
|
api.MapGet("/i18n/{culture}", (string culture) =>
|
|
{
|
|
CultureInfo ci;
|
|
try
|
|
{
|
|
ci = Languages.BestMatch(CultureInfo.GetCultureInfo(culture));
|
|
}
|
|
catch (CultureNotFoundException)
|
|
{
|
|
ci = CultureInfo.GetCultureInfo("en");
|
|
}
|
|
var strings = new Dictionary<string, string>(StringComparer.Ordinal);
|
|
foreach (var area in AdminAreas)
|
|
foreach (var (k, v) in Loc.GetArea(area, ci)) strings[k] = v;
|
|
strings["$culture"] = ci.Name;
|
|
strings["$rtl"] = ci.TextInfo.IsRightToLeft ? "true" : "false";
|
|
strings["$languages"] = AdminLanguages.Value;
|
|
return Results.Json(strings, ProtocolJson.Default.DictionaryStringString);
|
|
}).AllowAnonymousCaller();
|
|
}
|
|
|
|
/// <summary>Liveness for the container health check: 503 while the database cannot be reached.</summary>
|
|
private static async Task<IResult> HealthAsync(HttpContext context, ServerOptions options, ChronosDatabase db)
|
|
{
|
|
var checks = new Dictionary<string, string>(StringComparer.Ordinal)
|
|
{
|
|
["archive"] = Directory.Exists(options.ArchivePath) ? "ok" : "missing",
|
|
["data"] = Directory.Exists(options.DataPath) ? "ok" : "missing",
|
|
};
|
|
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(context.RequestAborted);
|
|
timeout.CancelAfter(TimeSpan.FromSeconds(3));
|
|
try
|
|
{
|
|
await using var session = await db.Database.OpenAsync(timeout.Token);
|
|
await session.ExecuteAsync("SELECT 1", [], timeout.Token);
|
|
checks["database"] = "ok";
|
|
}
|
|
catch (Exception ex) when (ex is DatabaseException or OperationCanceledException or IOException)
|
|
{
|
|
checks["database"] = "unavailable";
|
|
}
|
|
var healthy = checks["database"] == "ok";
|
|
return Results.Json(new HealthStatus(healthy ? "ok" : "unavailable", Version, checks), ProtocolJson.Default.HealthStatus,
|
|
statusCode: healthy ? StatusCodes.Status200OK : StatusCodes.Status503ServiceUnavailable);
|
|
}
|
|
}
|
|
|
|
/// <summary>Process-wide facts computed at startup.</summary>
|
|
public sealed class ServerState
|
|
{
|
|
public string? TlsFingerprint { get; init; }
|
|
|
|
/// <summary>Engine and version of the database ("PostgreSQL 17.2", "SQLite 3.45.1").</summary>
|
|
public string Database { get; init; } = string.Empty;
|
|
|
|
/// <summary>What this server offers clients (<see cref="ServerInfo.Capabilities"/>; <see cref="ServerCapabilities"/> names those clients act on).</summary>
|
|
public List<string> Capabilities { get; } = ["uploads", "sync", "jobs", "render-nodes", "events", ServerCapabilities.Projects];
|
|
|
|
public DateTimeOffset StartedAt { get; } = DateTimeOffset.UtcNow;
|
|
}
|