feat: found copies foundation (contracts, migration 0012, store, wire, trash and job hooks, keys)
Owner review 6 asks Chronos to recognise the same time-lapse held under different ids on the server and on this PC, compare the copies, and keep them apart or integrate and sync them. This lays the shared foundation the later parcels build on, without any UI or detection yet. - Migration 0012 adds found_copies (local-server and local-local pairs with evidence, scores, answer, policy and the 404 record) and copy_probes; every existing link with a local sequence becomes a Linked pair, so a server deletion and the per-link policy have a place. - FoundCopyStore keeps the pairs: upserts that never touch the answer, a compare-and-set of the state with an Integrating backstop (a failed or cancelled job reads as the previous state), link promotion and demotion, the once-per-refresh 404 count, the merge's links stage (session keys, links reset, pairs moved, refused when both are linked on one server), the local overlap queries and the probes. SyncLinkStore.RekeyAsync moves pairs and probes with the links in the same transaction. - Contracts for detection, review, plans, the Integrate and MergeSequences jobs (kinds 25/26, High level, new detail steps) and the Upload all rule that keeps suspected, kept-apart, deleted, busy and server-born sequences here. - Wire: POST photos/lookup, uploads into a target (IntoTarget/Copied, trailing and optional), frames/delete on the client, capabilities photo-lookup and upload-into, cached per remote. - The trash plans and deletes accept the job that holds the sequence (its own hold is not Busy) and a frames version checked under the lease; a Background job never interrupts a running one. - Settings for linking, the photo policy and projects; the en and it keys of design section 9. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43719bb5c5
commit
283d04d9cd
57 files changed
+3302
-26
No files matched your search
@@ -278,6 +278,25 @@ public sealed class ChronosClient : IDisposable
|
||||
}, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asks which server sequences hold sampled photos of local sequences (<c>POST /api/v1/photos/lookup</c>, owner review 6,
|
||||
/// #73; servers announcing <see cref="ServerCapabilities.PhotoLookup"/>). At most
|
||||
/// <see cref="PhotoLookupRequest.MaxProbes"/> probes and <see cref="PhotoLookupRequest.MaxItems"/> items; 413
|
||||
/// <c>too_many</c> beyond.
|
||||
/// </summary>
|
||||
public Task<PhotoLookupResponse> LookupPhotosAsync(PhotoLookupRequest request, CancellationToken ct = default) =>
|
||||
RetryAsync(() => SendAsync(HttpMethod.Post, "api/v1/photos/lookup", request, ProtocolJson.Default.PhotoLookupRequest,
|
||||
ProtocolJson.Default.PhotoLookupResponse, ct), ct);
|
||||
|
||||
/// <summary>
|
||||
/// Moves frames of a server sequence into the server's trash (<c>POST /api/v1/sequences/{id}/frames/delete</c>, the Delete
|
||||
/// right, owner or admin), each leaving a tombstone; <see cref="FrameDeleteRequest.DryRun"/> answers the plan only. A
|
||||
/// moved <see cref="FrameDeleteRequest.ExpectedFramesVersion"/> is refused (409).
|
||||
/// </summary>
|
||||
public Task<FrameDeleteResultDto> DeleteFramesAsync(Guid sequenceId, FrameDeleteRequest request, CancellationToken ct = default) =>
|
||||
SendAsync(HttpMethod.Post, $"api/v1/sequences/{sequenceId}/frames/delete", request, ProtocolJson.Default.FrameDeleteRequest,
|
||||
ProtocolJson.Default.FrameDeleteResultDto, ct);
|
||||
|
||||
// ---------------- Uploads ----------------
|
||||
|
||||
/// <summary>
|
||||
@@ -286,19 +305,38 @@ public sealed class ChronosClient : IDisposable
|
||||
/// deleted from the target sequence, before the upload or while it was on its way (owner review 2, R6). Transient
|
||||
/// failures retry with exponential backoff.
|
||||
/// </summary>
|
||||
public async Task<CompleteUploadResponse?> UploadFileAsync(
|
||||
public Task<CompleteUploadResponse?> UploadFileAsync(
|
||||
string path,
|
||||
Guid? sequenceId,
|
||||
DateTime? capturedAt,
|
||||
string? sessionKey = null,
|
||||
string? knownSha256 = null,
|
||||
IProgress<UploadProgress>? progress = null,
|
||||
CancellationToken ct = default)
|
||||
CancellationToken ct = default) =>
|
||||
UploadAsync(path, sequenceId, capturedAt, sessionKey, knownSha256, intoTarget: false, progress, ct);
|
||||
|
||||
/// <summary>
|
||||
/// Uploads one file into <paramref name="sequenceId"/> with <see cref="StartUploadRequest.IntoTarget"/> (owner review 6,
|
||||
/// #73; servers announcing <see cref="ServerCapabilities.UploadInto"/>): a photo another sequence of the server holds is
|
||||
/// copied into the target by the server, no bytes on the wire. Returns the target's frame; null when the target deleted
|
||||
/// the photo (deleted photos stay deleted).
|
||||
/// </summary>
|
||||
public Task<CompleteUploadResponse?> UploadFileIntoAsync(
|
||||
string path,
|
||||
Guid sequenceId,
|
||||
DateTime? capturedAt,
|
||||
string? knownSha256 = null,
|
||||
IProgress<UploadProgress>? progress = null,
|
||||
CancellationToken ct = default) =>
|
||||
UploadAsync(path, sequenceId, capturedAt, null, knownSha256, intoTarget: true, progress, ct);
|
||||
|
||||
private async Task<CompleteUploadResponse?> UploadAsync(string path, Guid? sequenceId, DateTime? capturedAt, string? sessionKey,
|
||||
string? knownSha256, bool intoTarget, IProgress<UploadProgress>? progress, CancellationToken ct)
|
||||
{
|
||||
var info = new FileInfo(path);
|
||||
var sha = knownSha256 ?? await HashFileAsync(path, ct).ConfigureAwait(false);
|
||||
var start = await RetryAsync(() => SendAsync(HttpMethod.Post, "api/v1/uploads",
|
||||
new StartUploadRequest(sequenceId, info.Name, info.Length, sha, capturedAt, sessionKey),
|
||||
new StartUploadRequest(sequenceId, info.Name, info.Length, sha, capturedAt, sessionKey, IntoTarget: intoTarget),
|
||||
ProtocolJson.Default.StartUploadRequest, ProtocolJson.Default.StartUploadResponse, ct), ct).ConfigureAwait(false);
|
||||
if (start.AlreadyExists)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Chronos.Protocol;
|
||||
|
||||
/// <summary>
|
||||
/// One local sequence's sample for <c>POST /api/v1/photos/lookup</c> (owner review 6, #73): up to 64 SHA-256 (lower-case
|
||||
/// hex), up to 64 unhashed photos, and its back-reference key.
|
||||
/// </summary>
|
||||
public sealed record PhotoProbe(string Key, IReadOnlyList<string> Sha256, IReadOnlyList<PhotoKeyDto>? Unhashed = null, string? SessionKey = null);
|
||||
|
||||
/// <summary>An unhashed photo, told apart by size and capture time to the millisecond.</summary>
|
||||
public sealed record PhotoKeyDto(long Size, DateTime CapturedAt);
|
||||
|
||||
/// <summary>At most 200 probes and 20,000 items (hashes + unhashed keys + session keys) in all; 413 <c>too_many</c> beyond.</summary>
|
||||
public sealed record PhotoLookupRequest(IReadOnlyList<PhotoProbe> Probes)
|
||||
{
|
||||
/// <summary>The most probes one request may carry.</summary>
|
||||
public const int MaxProbes = 200;
|
||||
|
||||
/// <summary>The most items (hashes, unhashed keys and session keys) one request may carry.</summary>
|
||||
public const int MaxItems = 20_000;
|
||||
|
||||
/// <summary>The items the request carries, as the limit counts them.</summary>
|
||||
public int CountItems() => Probes.Sum(p => (p.Sha256?.Count ?? 0) + (p.Unhashed?.Count ?? 0) + (p.SessionKey is null ? 0 : 1));
|
||||
}
|
||||
|
||||
/// <summary>The answer of a lookup: one result per probe, in the request's order.</summary>
|
||||
public sealed record PhotoLookupResponse(IReadOnlyList<ProbeResult> Results);
|
||||
|
||||
/// <summary>The server sequences a probe hit.</summary>
|
||||
public sealed record ProbeResult(string Key, IReadOnlyList<PhotoLookupHit> Hits);
|
||||
|
||||
/// <summary>
|
||||
/// Hashes: distinct probe hashes the sequence holds in a frame; Removed: distinct probe hashes it tombstoned (deleted, or
|
||||
/// replaced by a conversion); Unhashed: probe keys a frame of it matches by size and capture time to the millisecond;
|
||||
/// SessionKey: the sequence is filed under the probe's session key.
|
||||
/// </summary>
|
||||
public sealed record PhotoLookupHit(Guid SequenceId, int Hashes, int Removed, int Unhashed, bool SessionKey);
|
||||
@@ -48,6 +48,18 @@ public static class ServerCapabilities
|
||||
/// its renders into its videos folder. Without it a client lists only its own videos.
|
||||
/// </summary>
|
||||
public const string Videos = "videos";
|
||||
|
||||
/// <summary>
|
||||
/// The server answers <c>POST /api/v1/photos/lookup</c> (owner review 6, #73): which of its sequences hold sampled photos
|
||||
/// of a client's sequences, by SHA-256, tombstone, size and capture time, or session key.
|
||||
/// </summary>
|
||||
public const string PhotoLookup = "photo-lookup";
|
||||
|
||||
/// <summary>
|
||||
/// The server files an upload into its target even when another sequence holds the photo
|
||||
/// (<see cref="StartUploadRequest.IntoTarget"/>, owner review 6, #73).
|
||||
/// </summary>
|
||||
public const string UploadInto = "upload-into";
|
||||
}
|
||||
|
||||
/// <summary><c>GET /health</c>.</summary>
|
||||
|
||||
@@ -77,6 +77,12 @@ namespace Chronos.Protocol;
|
||||
[JsonSerializable(typeof(RemovedPhotoDto))]
|
||||
[JsonSerializable(typeof(FrameDeleteRequest))]
|
||||
[JsonSerializable(typeof(FrameDeleteResultDto))]
|
||||
[JsonSerializable(typeof(PhotoProbe))]
|
||||
[JsonSerializable(typeof(PhotoKeyDto))]
|
||||
[JsonSerializable(typeof(PhotoLookupRequest))]
|
||||
[JsonSerializable(typeof(PhotoLookupResponse))]
|
||||
[JsonSerializable(typeof(ProbeResult))]
|
||||
[JsonSerializable(typeof(PhotoLookupHit))]
|
||||
[JsonSerializable(typeof(TrashEntryDto))]
|
||||
[JsonSerializable(typeof(TrashListDto))]
|
||||
[JsonSerializable(typeof(TrashRestoreDto))]
|
||||
|
||||
@@ -6,11 +6,22 @@ namespace Chronos.Protocol;
|
||||
/// from the target sequence is answered the same way, without a frame (owner review 2, R6), unless <see cref="Restore"/>
|
||||
/// asks to file it there again: only an explicit user action sends it (the admin panel's "Upload again"), never sync or a
|
||||
/// watch folder, and the completion repeats it (<c>complete?restore=true</c>). Filing it drops the photo's tombstone.
|
||||
/// <para>
|
||||
/// <see cref="IntoTarget"/> (owner review 6, #73; capability <see cref="ServerCapabilities.UploadInto"/>) files the photo into
|
||||
/// <see cref="SequenceId"/> even when another sequence of the served archive holds it: the server copies its own file into
|
||||
/// the target, no bytes on the wire, and answers <see cref="StartUploadResponse.Copied"/>. The caller must own the target,
|
||||
/// be an admin or hold the Edit right; never with <see cref="Restore"/>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed record StartUploadRequest(Guid? SequenceId, string FileName, long Size, string Sha256, DateTime? CapturedAt, string? SessionKey,
|
||||
bool Restore = false);
|
||||
bool Restore = false, bool IntoTarget = false);
|
||||
|
||||
public sealed record StartUploadResponse(Guid? UploadId, int ChunkSize, IReadOnlyList<int> Received, bool AlreadyExists, Guid? FrameId);
|
||||
/// <summary>
|
||||
/// The answer to <c>POST /api/v1/uploads</c>. <see cref="Copied"/>: the server filed the photo into the target from a file it
|
||||
/// held in another sequence (<see cref="StartUploadRequest.IntoTarget"/>); <see cref="FrameId"/> is the new frame.
|
||||
/// </summary>
|
||||
public sealed record StartUploadResponse(Guid? UploadId, int ChunkSize, IReadOnlyList<int> Received, bool AlreadyExists, Guid? FrameId,
|
||||
bool Copied = false);
|
||||
|
||||
/// <summary>Error codes of the frame upload calls that clients act on.</summary>
|
||||
public static class UploadErrors
|
||||
|
||||
Reference in new issue
Block a user