Files
Chronos/src/Titano.Protocol/Sequences.cs
T
Claude ea6e1a69e0 fix(sync): keep project positions on their photos when settings cross copies
Settings synced between a PC and its server sequence were stored as they
came, in the other copy's frame order. When the inserted photos arrived
later (a download, an upload), the index moved those already-correct
positions a second time, so exclusions, the hero and camera keyframes
landed on other photos (V-21, CD-2).

- Settings are translated by photo (SHA-256, else size and capture time)
  to the frames of the copy they go to: the server's before they are
  compared or applied here, this PC's to the server's frames as its
  manifest lists them before a push (SyncPositions).
- A position on a photo the receiving copy lacks waits in project.json as
  a pending frame and takes its place when the photo arrives, on an
  insertion or an append in step with the index; the Library's hero
  frame follows. A hero chosen meanwhile wins, and advice does not fill
  a hero while one waits. Old projects without the member are unchanged.
- Pushes send expectedFramesVersion; PATCH /api/v1/sequences/{id} answers
  409 frames_conflict when the frames changed since, and the next
  comparison translates again.
- A pulled payload equal to the local copy is settled without the
  archive: an offline or read-only archive no longer fails the
  comparison (V-10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-12 16:20:11 +00:00

154 lines
5.8 KiB
C#

namespace Titano.Protocol;
/// <summary>Sequence summary for lists (BRIEF §12.2 card data).</summary>
/// <param name="PreviewOnlyCount">Frames that decode only through their embedded preview (BRIEF §8.2 tier 2).</param>
public sealed record SequenceDto(
Guid Id,
string? Title,
string DisplayTitle,
string Folder,
string? CameraMake,
string? CameraModel,
string? Lens,
DateTime? FirstCapture,
DateTime? LastCapture,
int FrameCount,
double? MedianInterval,
long TotalBytes,
long Status,
int RenderedCount,
Guid? HeroFrameId,
IReadOnlyList<string> Tags,
int Rating,
string? Notes,
int SettingsVersion,
int FramesVersion,
int WarningCount,
Guid? OwnerUserId,
DateTimeOffset UpdatedAt,
int PreviewOnlyCount = 0);
/// <summary>A page of results with an opaque keyset cursor; null cursor = last page.</summary>
public sealed record Page<T>(IReadOnlyList<T> Items, string? NextCursor, long? Total);
/// <summary><c>POST /api/v1/sequences</c>.</summary>
public sealed record CreateSequenceRequest(string? Title, string? CameraHint);
/// <summary>
/// <c>PATCH /api/v1/sequences/{id}</c>. <see cref="ExpectedSettingsVersion"/> enables conflict detection (409).
/// <see cref="HeroFrameId"/> names the frame the sequence shows (one of its own; <see cref="Guid.Empty"/> clears it).
/// <see cref="ExpectedFramesVersion"/> is the frames version the settings' frame positions were written against: the
/// edit is refused (409 <c>frames_conflict</c>) when frames were added or removed since.
/// </summary>
public sealed record UpdateSequenceRequest(
string? Title,
IReadOnlyList<string>? Tags,
int? Rating,
string? Notes,
string? SettingsJson,
int? ExpectedSettingsVersion,
Guid? HeroFrameId = null,
int? ExpectedFramesVersion = null);
/// <param name="PreviewWidth">Width of the largest embedded preview before orientation, like <paramref name="Width"/>; 0 when unknown.</param>
/// <param name="PreviewHeight">Height of that preview before orientation; 0 when unknown.</param>
public sealed record FrameDto(
Guid Id,
Guid SequenceId,
int Index,
string FileName,
long Size,
string? Sha256,
DateTime? CapturedAt,
int? UtcOffsetMinutes,
double? ExposureTime,
double? FNumber,
int? Iso,
double? FocalLength,
int Orientation,
int Width,
int Height,
string Format,
long Flags,
int PreviewWidth = 0,
int PreviewHeight = 0);
/// <summary><c>GET /api/v1/sequences/{id}/manifest</c>: what a client needs to diff a sequence (BRIEF §14.5).</summary>
/// <param name="Proxies">How to make the proxies the server asks for (<see cref="ManifestFrame.WantsProxy"/>); null when it makes none.</param>
public sealed record SequenceManifest(
Guid SequenceId,
int FramesVersion,
int SettingsVersion,
string? SettingsJson,
IReadOnlyList<string> Tags,
IReadOnlyList<ManifestFrame> Frames,
IReadOnlyList<RenderDto> Renders,
ProxySpec? Proxies = null);
/// <summary>One frame of a manifest: its content, whether the server has a proxy and thumbnail of it, and its flags.</summary>
/// <param name="Sha256">Lower-case hex SHA-256; empty while the server has not hashed it (a folder adopted and not verified yet).</param>
/// <param name="Flags">The frame's <c>FrameFlags</c> bits (missing, corrupt, excluded…).</param>
/// <param name="WantsProxy">
/// The server cannot decode this original and has no proxy of it (BRIEF §2.3, §8.1: HEIF): a client or render node that
/// decodes it sends one with <c>PUT /api/v1/frames/{id}/proxy</c>, made as <see cref="SequenceManifest.Proxies"/> says.
/// </param>
public sealed record ManifestFrame(Guid Id, int Index, string FileName, long Size, string Sha256, bool HasProxy, bool HasThumb, long Flags = 0,
bool WantsProxy = false);
/// <summary>How the server's proxies are made (BRIEF §8.5): long edge in pixels (0 = full size) and JPEG quality.</summary>
public sealed record ProxySpec(int LongEdge, int Quality);
public sealed record RenderDto(
Guid Id,
string PresetName,
string? Codec,
int Width,
int Height,
double Fps,
double DurationSeconds,
long Bytes,
DateTimeOffset Created,
string? ProducedBy);
/// <summary>Aggregates for the archive dashboard and the admin panel.</summary>
public sealed record ArchiveStatsDto(
long Sequences,
long Photos,
long Bytes,
long FreeBytes,
long CapacityBytes,
int Cameras,
int? FirstYear,
int? LastYear,
IReadOnlyList<KeyValueCount> ByYear,
IReadOnlyList<KeyValueCount> ByMonth,
IReadOnlyList<KeyValueCount> ByCamera,
IReadOnlyList<KeyValueCount> ByFormat,
int SequencesWithoutProxies,
int UnverifiedSequences);
public sealed record KeyValueCount(string Key, long Count, long Bytes);
/// <summary><c>GET /api/v1/sequences/{id}/stats</c>: frame totals by format and flagged frames.</summary>
public sealed record SequenceStatsDto(
Guid SequenceId,
int FrameCount,
long TotalBytes,
DateTime? FirstCapture,
DateTime? LastCapture,
double? MedianInterval,
IReadOnlyList<KeyValueCount> ByFormat,
long MissingFrames,
long CorruptFrames,
long DuplicateFrames,
long ExcludedFrames);
/// <summary>
/// <c>DELETE /api/v1/sequences/{id}</c>: what the delete does (with <c>?dryRun=true</c>) or did. The folder is moved
/// to <see cref="TrashFolder"/> inside the archive, never erased.
/// </summary>
public sealed record SequenceDeletePlan(Guid SequenceId, string? Folder, string? TrashFolder, int FrameCount, long TotalBytes, int RenderCount, bool DryRun);
/// <summary><c>GET/PUT /api/v1/archive/settings</c> (admin). The root path comes from the server configuration.</summary>
public sealed record ArchiveSettingsDto(Guid Id, string Name, string RootPath, string FolderTemplate, string FileTemplate, int ProxyLongEdge);