feat(server): publish card imports as cardEvent

BRIEF §14.3 lists cardEvent among the WebSocket events, but the server had
none. A client importing a card into the server now reports its start,
progress (at most once a second, a report still waiting replaced by the
next) and end to the new POST /api/v1/uploads/cards (Upload permission;
import id, card name, state, done, total, failed), and the server publishes
a CardEvent naming the account and client to every connected client; the
protocol client parses it and offers ReportCardAsync. A report that fails is
logged and never stops the import; a server without the endpoint gets no
more reports (SRS-10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 09:40:53 +00:00
1 parent 01e17c9961
commit bb55e47b47
9 files changed
+376 -6

No files matched your search

@@ -173,6 +173,13 @@ public sealed class TitanoClient : IDisposable
return await RetryAsync(() => SendAsync<CompleteUploadResponse>(HttpMethod.Post, $"api/v1/uploads/{uploadId}/complete", ProtocolJson.Default.CompleteUploadResponse, ct), ct).ConfigureAwait(false);
}
/// <summary>
/// Reports a card import this client streams into the server (started, progress, finished); the server tells every
/// connected client with a <see cref="CardEvent"/> (BRIEF §14.3).
/// </summary>
public Task ReportCardAsync(CardImportReport report, CancellationToken ct = default) =>
SendAsync(HttpMethod.Post, "api/v1/uploads/cards", report, ProtocolJson.Default.CardImportReport, ct);
/// <summary>
/// Render node: uploads the output of a claimed job in resumable chunks, then completes the job; the server verifies
/// the SHA-256 in <paramref name="result"/> and files the render under the sequence's exports (BRIEF §14.7).
+21
View File
@@ -10,6 +10,7 @@ namespace Titano.Protocol;
[JsonDerivedType(typeof(JobProgressEvent), "jobProgress")]
[JsonDerivedType(typeof(JobStateEvent), "jobState")]
[JsonDerivedType(typeof(SequenceChangedEvent), "sequenceChanged")]
[JsonDerivedType(typeof(CardEvent), "cardEvent")]
[JsonDerivedType(typeof(NodeStateEvent), "nodeState")]
public abstract record ServerEvent;
@@ -19,4 +20,24 @@ public sealed record JobStateEvent(Guid JobId, string State, string? Error) : Se
public sealed record SequenceChangedEvent(Guid SequenceId, string Change, int FramesVersion, int SettingsVersion) : ServerEvent;
/// <summary>
/// A card import that a connected client streams into the server (BRIEF §14.4), as that client reported it
/// (<see cref="CardImportReport"/>): <see cref="State"/> is one of <see cref="CardImportStates"/>, <see cref="Done"/>
/// counts the photos of its plan handled so far (failures included), <see cref="User"/> and <see cref="ClientName"/>
/// say who imports it.
/// </summary>
public sealed record CardEvent(Guid ImportId, string Card, string State, int Done, int Total, int Failed, string User, string? ClientName) : ServerEvent;
/// <summary>States of a card import report and of its <see cref="CardEvent"/>.</summary>
public static class CardImportStates
{
public const string Started = "started";
public const string Progress = "progress";
/// <summary>The import ended: every photo handled, or fewer when it stopped early.</summary>
public const string Finished = "finished";
public static bool IsKnown(string? state) => state is Started or Progress or Finished;
}
public sealed record NodeStateEvent(Guid NodeId, string ClientName, string State) : ServerEvent;
+1
View File
@@ -35,6 +35,7 @@ namespace Titano.Protocol;
[JsonSerializable(typeof(ChunkReceived))]
[JsonSerializable(typeof(CompleteUploadResponse))]
[JsonSerializable(typeof(UploadState))]
[JsonSerializable(typeof(CardImportReport))]
[JsonSerializable(typeof(JobDto))]
[JsonSerializable(typeof(Page<JobDto>))]
[JsonSerializable(typeof(CreateJobRequest))]
+7
View File
@@ -17,6 +17,13 @@ public sealed record CompleteUploadResponse(Guid FrameId, Guid SequenceId, int I
/// <summary><c>GET /api/v1/uploads/{id}</c>: resume state.</summary>
public sealed record UploadState(Guid UploadId, string FileName, long Size, string Sha256, int ChunkSize, IReadOnlyList<int> Received, string State);
/// <summary>
/// <c>POST /api/v1/uploads/cards</c>: a client importing a card into the server through these uploads reports its start,
/// progress and end (BRIEF §14.4); the server tells every connected client with a <see cref="CardEvent"/> (BRIEF §14.3).
/// <see cref="ImportId"/> is the client's import plan, <see cref="Card"/> the card's name as the client shows it.
/// </summary>
public sealed record CardImportReport(Guid ImportId, string Card, string State, int Done, int Total, int Failed);
/// <summary>
/// <c>POST /api/v1/sequences/{id}/renders</c>: a client offers one of its renders of the sequence (BRIEF §14.5,
/// renders are uploaded on request). The render keeps its id on the server, so both sides recognise it; when the