fix(projects): empty sequences, push size, version paging, delete rights, settings PATCH, change events

- An unplaced sequence (no photos) lists no projects and refuses to create one
  with sequence_empty, instead of writing sidecars at the archive root.
- A push accepts a full-size version; a 413 is reported as too_large.
- Version pages are capped in bytes and say when more follow; the summary form
  leaves settings out; server homes page on.
- Deleting by its maker needs the same account, not just the same username.
- A settings PATCH writes project.json under the sequence lease, so Main's
  later birth no longer wipes it.
- Reconcile, read-only catch-up and a Main flip publish projectChanged.
- Server homes read the frames stamp and check a version is really stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 12:31:52 +01:00
1 parent ed7452e739
commit 4f652c4025
16 files changed
+356 -53

No files matched your search

+32 -7
View File
@@ -507,7 +507,9 @@ public sealed class ChronosClient : IDisposable
/// <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).
/// 1–200 (the server's default, 50 newest first and 100 oldest first, when null). A page may hold fewer versions than
/// asked for while more follow (<see cref="ProjectVersionPageDto.More"/>): the server also ends one before its settings
/// pass a few MiB (<c>?summary=true</c> leaves the settings out, for a list of the versions).
/// </summary>
public Task<ProjectVersionPageDto> ListProjectVersionsAsync(Guid sequenceId, Guid projectId, int? before = null, int? after = null, int? limit = null,
CancellationToken ct = default) =>
@@ -515,12 +517,22 @@ public sealed class ChronosClient : IDisposable
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)
public Task<ProjectVersionDto?> GetProjectVersionAsync(Guid sequenceId, Guid projectId, Guid versionId, CancellationToken ct = default) =>
VersionOrNullAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}", ct);
/// <summary>
/// A version of the project the server holds durably, read back from its file now with its content hash: what a workspace
/// asks before it drops its own copy. Null when the file is missing or damaged, or the server has no such version; a
/// deleted project is a 404 <c>project</c> <see cref="ChronosApiException"/>.
/// </summary>
public Task<ProjectVersionDto?> GetStoredProjectVersionAsync(Guid sequenceId, Guid projectId, Guid versionId, CancellationToken ct = default) =>
VersionOrNullAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}?stored=true", ct);
private async Task<ProjectVersionDto?> VersionOrNullAsync(string path, CancellationToken ct)
{
try
{
return await GetAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}", ProtocolJson.Default.ProjectVersionDto, ct)
.ConfigureAwait(false);
return await GetAsync(path, ProtocolJson.Default.ProjectVersionDto, ct).ConfigureAwait(false);
}
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.NotFound && ex.Error.Details == "version")
{
@@ -532,8 +544,8 @@ public sealed class ChronosClient : IDisposable
/// 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>, <c>too_large</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
/// <c>hash_mismatch</c>, <c>newer_format</c>, <c>too_large</c> or <c>invalid</c>; a body larger than the server (or a proxy before
/// it) takes, 413, is <c>too_large</c> too. 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)
@@ -556,6 +568,8 @@ public sealed class ChronosClient : IDisposable
// Not a push answer (a proxy's page): the status says what failed.
}
}
if (response.StatusCode == HttpStatusCode.RequestEntityTooLarge)
return new ProjectPushResultDto(ProjectPushOutcomes.TooLarge, null, null, ProjectErrors.TooLarge, response.ReasonPhrase);
await EnsureSuccessAsync(response, ct).ConfigureAwait(false);
throw new ChronosApiException(response.StatusCode, new ApiError("http_" + (int)response.StatusCode, response.ReasonPhrase ?? "error"));
}
@@ -564,16 +578,27 @@ public sealed class ChronosClient : IDisposable
public Task<ProjectFramesDto> GetProjectFramesAsync(Guid sequenceId, CancellationToken ct = default) =>
GetAsync($"api/v1/sequences/{sequenceId}/projects/frames", ProtocolJson.Default.ProjectFramesDto, ct);
/// <summary>A cheap stamp of what <see cref="GetProjectFramesAsync"/> answers: the frames are read again only when it moved.</summary>
public Task<ProjectFramesStampDto> GetProjectFramesStampAsync(Guid sequenceId, CancellationToken ct = default) =>
GetAsync($"api/v1/sequences/{sequenceId}/projects/frames/stamp", ProtocolJson.Default.ProjectFramesStampDto, ct);
// ---------------- Events ----------------
/// <summary>Server events over WebSocket until cancelled; reconnect is the caller's policy.</summary>
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken ct = default)
public IAsyncEnumerable<ServerEvent> EventsAsync(CancellationToken ct = default) => EventsAsync(null, ct);
/// <summary>
/// Server events over WebSocket until cancelled, calling <paramref name="connected"/> once the socket is open (before its
/// first event): from then on no event the server sends is missed.
/// </summary>
public async IAsyncEnumerable<ServerEvent> EventsAsync(Action? connected, [EnumeratorCancellation] CancellationToken ct = default)
{
using var socket = new ClientWebSocket();
socket.Options.RemoteCertificateValidationCallback = _pinning.Validate;
if (_token is not null) socket.Options.SetRequestHeader("Authorization", "Bearer " + _token);
var ws = new UriBuilder(new Uri(BaseAddress, "api/v1/events")) { Scheme = BaseAddress.Scheme == "https" ? "wss" : "ws" }.Uri;
await socket.ConnectAsync(ws, ct).ConfigureAwait(false);
connected?.Invoke();
var buffer = new byte[64 * 1024];
using var message = new MemoryStream();
while (socket.State == WebSocketState.Open && !ct.IsCancellationRequested)
+13
View File
@@ -87,6 +87,13 @@ public sealed record ProjectPushResultDto(string Outcome, ProjectVersionDto? Ver
/// </summary>
public sealed record ProjectFramesDto(Guid SequenceId, int FramesVersion, IReadOnlyList<FrameDto> Frames, IReadOnlyList<RemovedPhotoDto>? Aliases = null);
/// <summary>
/// <c>GET /api/v1/sequences/{sid}/projects/frames/stamp</c>: a cheap stamp of what <c>…/projects/frames</c> answers, another
/// value whenever the frames, how their photos are named (a hash learnt) or the encodings conversions joined may have
/// changed, so a workspace reads the frames again only then.
/// </summary>
public sealed record ProjectFramesStampDto(Guid SequenceId, string Stamp);
/// <summary>What became of a pushed version (<see cref="ProjectPushResultDto.Outcome"/>).</summary>
public static class ProjectPushOutcomes
{
@@ -154,4 +161,10 @@ public static class ProjectErrors
/// <summary>409: the Main project holds the sequence's own settings and is never deleted.</summary>
public const string MainCannotBeDeleted = "main_cannot_be_deleted";
/// <summary>409: the sequence has no photo yet (no folder in the archive), so it keeps no projects; its list is empty.</summary>
public const string SequenceEmpty = "sequence_empty";
/// <summary>413 from a push: the body is larger than the server takes; read as the outcome <see cref="ProjectPushOutcomes.TooLarge"/>.</summary>
public const string TooLarge = "too_large";
}
+1
View File
@@ -99,4 +99,5 @@ namespace Chronos.Protocol;
[JsonSerializable(typeof(ProjectVersionPageDto))]
[JsonSerializable(typeof(ProjectPushResultDto))]
[JsonSerializable(typeof(ProjectFramesDto))]
[JsonSerializable(typeof(ProjectFramesStampDto))]
public sealed partial class ProtocolJson : JsonSerializerContext;