feat(server): the server keeps its sequences' projects, pushed and pulled like a PC's archive
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>
This commit is contained in:
1 parent
917cddde41
commit
e2ecc409a3
30 files changed
+2261
-35
No files matched your search
@@ -472,6 +472,98 @@ public sealed class ChronosClient : IDisposable
|
||||
public Task ReportNodeFailureAsync(Guid nodeId, Guid jobId, string error, CancellationToken ct = default) =>
|
||||
SendAsync(HttpMethod.Post, $"api/v1/nodes/{nodeId}/jobs/{jobId}/failed", new NodeJobFailure(error), ProtocolJson.Default.NodeJobFailure, ct);
|
||||
|
||||
// ---------------- Projects (owner review 2, R8; servers with the "projects" capability) ----------------
|
||||
|
||||
/// <summary>The live projects of a server sequence, Main first (made from the sequence's settings the first time they are read).</summary>
|
||||
public Task<List<ProjectDto>> ListProjectsAsync(Guid sequenceId, CancellationToken ct = default) =>
|
||||
GetAsync($"api/v1/sequences/{sequenceId}/projects", ProtocolJson.Default.ListProjectDto, ct);
|
||||
|
||||
public Task<ProjectDto> GetProjectAsync(Guid sequenceId, Guid projectId, CancellationToken ct = default) =>
|
||||
GetAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}", ProtocolJson.Default.ProjectDto, ct);
|
||||
|
||||
/// <summary>
|
||||
/// A new project of the sequence, its first version copied from <see cref="CreateProjectRequest.FromVersionId"/> or from
|
||||
/// Main's head; a name refused is a 400 <c>invalid_name</c> or 409 <c>name_taken</c> <see cref="ChronosApiException"/>.
|
||||
/// </summary>
|
||||
public Task<ProjectDto> CreateProjectAsync(Guid sequenceId, CreateProjectRequest request, CancellationToken ct = default) =>
|
||||
SendAsync(HttpMethod.Post, $"api/v1/sequences/{sequenceId}/projects", request, ProtocolJson.Default.CreateProjectRequest, ProtocolJson.Default.ProjectDto, ct);
|
||||
|
||||
/// <summary>Gives a project another name; a name refused is a 400 <c>invalid_name</c> or 409 <c>name_taken</c> <see cref="ChronosApiException"/>.</summary>
|
||||
public Task<ProjectDto> RenameProjectAsync(Guid sequenceId, Guid projectId, string name, CancellationToken ct = default) =>
|
||||
SendAsync(HttpMethod.Patch, $"api/v1/sequences/{sequenceId}/projects/{projectId}", new RenameProjectRequest(name), ProtocolJson.Default.RenameProjectRequest,
|
||||
ProtocolJson.Default.ProjectDto, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a project and its versions into the sequence's projects' trash (never erased); Main is refused (409
|
||||
/// <c>main_cannot_be_deleted</c>).
|
||||
/// </summary>
|
||||
public Task DeleteProjectAsync(Guid sequenceId, Guid projectId, CancellationToken ct = default) =>
|
||||
SendNoContentAsync(HttpMethod.Delete, $"api/v1/sequences/{sequenceId}/projects/{projectId}", ct);
|
||||
|
||||
/// <summary>The project's newest version.</summary>
|
||||
public Task<ProjectVersionDto> GetProjectHeadAsync(Guid sequenceId, Guid projectId, CancellationToken ct = default) =>
|
||||
GetAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/head", ProtocolJson.Default.ProjectVersionDto, ct);
|
||||
|
||||
/// <summary>
|
||||
/// One page of a project's versions: newest first, numbered below <paramref name="before"/> (from the head when null),
|
||||
/// or, with <paramref name="after"/>, oldest first numbered above it (what a workspace pulls). <paramref name="limit"/>:
|
||||
/// 1–200 (the server's default, 50 newest first and 100 oldest first, when null).
|
||||
/// </summary>
|
||||
public Task<ProjectVersionPageDto> ListProjectVersionsAsync(Guid sequenceId, Guid projectId, int? before = null, int? after = null, int? limit = null,
|
||||
CancellationToken ct = default) =>
|
||||
GetAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions?{N("before", before)}{N("after", after)}{N("limit", limit)}".TrimEnd('&', '?'),
|
||||
ProtocolJson.Default.ProjectVersionPageDto, ct);
|
||||
|
||||
/// <summary>A version of the project by id; null when the server has no such version of it.</summary>
|
||||
public async Task<ProjectVersionDto?> GetProjectVersionAsync(Guid sequenceId, Guid projectId, Guid versionId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await GetAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}", ProtocolJson.Default.ProjectVersionDto, ct)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.NotFound && ex.Error.Details == "version")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes <paramref name="version"/>, made in a workspace from the project's head (<see cref="ProjectVersionDto.ParentId"/>):
|
||||
/// the server stores it as the new head, numbered head + 1 (201, <c>stored</c>), or answers it again for a repeated push
|
||||
/// (200, <c>already_stored</c>), or refuses it, storing nothing: 409 <c>diverged</c> with the head, 422
|
||||
/// <c>hash_mismatch</c>, <c>newer_format</c> or <c>invalid</c>. These come back as <see cref="ProjectPushResultDto"/>
|
||||
/// without throwing; any other failure (the sequence or project gone, no permission, the archive offline or the sequence
|
||||
/// busy: 503) throws <see cref="ChronosApiException"/>. Safe to repeat: the version's id makes a second push a no-op.
|
||||
/// </summary>
|
||||
public async Task<ProjectPushResultDto> PushProjectVersionAsync(Guid sequenceId, Guid projectId, ProjectVersionDto version, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(version);
|
||||
using var request = new HttpRequestMessage(HttpMethod.Post, $"api/v1/sequences/{sequenceId}/projects/{projectId}/versions")
|
||||
{
|
||||
Content = JsonContent.Create(version, ProtocolJson.Default.ProjectVersionDto),
|
||||
};
|
||||
using var response = await SendRawAsync(request, ct).ConfigureAwait(false);
|
||||
if (response.StatusCode is HttpStatusCode.OK or HttpStatusCode.Created or HttpStatusCode.Conflict or HttpStatusCode.UnprocessableEntity)
|
||||
{
|
||||
var body = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (JsonSerializer.Deserialize(body, ProtocolJson.Default.ProjectPushResultDto) is { Outcome.Length: > 0 } result) return result;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Not a push answer (a proxy's page): the status says what failed.
|
||||
}
|
||||
}
|
||||
await EnsureSuccessAsync(response, ct).ConfigureAwait(false);
|
||||
throw new ChronosApiException(response.StatusCode, new ApiError("http_" + (int)response.StatusCode, response.ReasonPhrase ?? "error"));
|
||||
}
|
||||
|
||||
/// <summary>The sequence's frames and photo aliases as of one frames version: what its projects' positions are placed on.</summary>
|
||||
public Task<ProjectFramesDto> GetProjectFramesAsync(Guid sequenceId, CancellationToken ct = default) =>
|
||||
GetAsync($"api/v1/sequences/{sequenceId}/projects/frames", ProtocolJson.Default.ProjectFramesDto, ct);
|
||||
|
||||
// ---------------- Events ----------------
|
||||
|
||||
/// <summary>Server events over WebSocket until cancelled; reconnect is the caller's policy.</summary>
|
||||
@@ -606,4 +698,8 @@ public sealed class ChronosClient : IDisposable
|
||||
};
|
||||
|
||||
private static string Q(string name, string? value) => string.IsNullOrEmpty(value) ? string.Empty : "&" + name + "=" + Uri.EscapeDataString(value);
|
||||
|
||||
/// <summary>A number of the query (<c>name=value&</c>); empty when null.</summary>
|
||||
private static string N(string name, int? value) =>
|
||||
value is { } n ? name + "=" + n.ToString(System.Globalization.CultureInfo.InvariantCulture) + "&" : string.Empty;
|
||||
}
|
||||
Reference in new issue
Block a user