fix(sync): resolve conflicts against the versions shown, isolate failures, renders on request
- Conflicts are settled against the versions the user was shown; a later change on
either side refuses the choice and compares again. Title, tags, rating and notes
changed differently on both sides are a conflict too (no silent tag union).
- Links are written under the engine's gate and forgotten only after a 404; linked
local copies are read by id; unlinked copies with the same originals are linked
by content.
- A failure on one sequence is recorded on its link; the others are still compared.
- Downloads hash unverified local copies first and restore originals missing here.
- Background proxy downloads give way to the user's requests; "Keep proxies offline"
refreshes the caches of sequences opened with proxies, checks free space and backs
off after a failure.
- Renders travel on request: Send exports (chunked, hash-verified upload keeping the
render id; new POST /sequences/{id}/renders endpoints) and Get exports.
- Server screen: stable row buttons, mockup column grid, Tab through rows, conflict
rows first on the card colour, localised conflict detail, Save both confirmation,
Pause metered uploads, culture switch, Library one-word sync glyphs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
48 files changed
+2498
-465
No files matched your search
@@ -29,6 +29,15 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
/// <summary>The next original download of this frame returns damaged bytes.</summary>
|
||||
public Guid? CorruptOnce { get; set; }
|
||||
|
||||
/// <summary>Sequences the listing skips (a page boundary moved while it was read); they are still there.</summary>
|
||||
public HashSet<Guid> Unlisted { get; } = [];
|
||||
|
||||
/// <summary>Sequences whose manifest the server refuses (403), as for an account that lost a right.</summary>
|
||||
public HashSet<Guid> Refused { get; } = [];
|
||||
|
||||
/// <summary>Proxy and thumbnail downloads fail with a server error.</summary>
|
||||
public bool FailAssets { get; set; }
|
||||
|
||||
public FakeSequence Add(string? title, IEnumerable<byte[]> originals, string? settingsJson = null,
|
||||
SequenceStatus status = SequenceStatus.ProxiesBuilt | SequenceStatus.ThumbsBuilt)
|
||||
{
|
||||
@@ -61,13 +70,24 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
FailingListings--;
|
||||
throw new HttpRequestException("connection refused");
|
||||
}
|
||||
return Task.FromResult<IReadOnlyList<SequenceDto>>([.. Sequences.Values.Select(s => s.Dto())]);
|
||||
return Task.FromResult<IReadOnlyList<SequenceDto>>([.. Sequences.Values.Where(s => !Unlisted.Contains(s.Id)).Select(s => s.Dto())]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The next request for this sequence times out (HttpClient reports a timeout as a cancellation).</summary>
|
||||
public Guid? TimeoutOnce { get; set; }
|
||||
|
||||
public Task<SequenceDto> GetSequenceAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
lock (_gate) return Task.FromResult(Find(id).Dto());
|
||||
lock (_gate)
|
||||
{
|
||||
if (TimeoutOnce == id)
|
||||
{
|
||||
TimeoutOnce = null;
|
||||
throw new TaskCanceledException("The request timed out.");
|
||||
}
|
||||
return Task.FromResult(Find(id).Dto());
|
||||
}
|
||||
}
|
||||
|
||||
public Task<SequenceManifest> GetManifestAsync(Guid id, CancellationToken cancellationToken)
|
||||
@@ -75,6 +95,7 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
lock (_gate)
|
||||
{
|
||||
ManifestCalls++;
|
||||
if (Refused.Contains(id)) throw new TitanoApiException(HttpStatusCode.Forbidden, new ApiError("forbidden", "refused"));
|
||||
return Task.FromResult(Find(id).Manifest());
|
||||
}
|
||||
}
|
||||
@@ -137,6 +158,7 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
{
|
||||
"original" when CorruptOnce == frameId => [.. frame.Bytes.Select(b => (byte)~b)],
|
||||
"original" => frame.Bytes,
|
||||
"proxy" or "thumb" when FailAssets => throw new TitanoApiException(HttpStatusCode.InternalServerError, new ApiError("internal", "failed")),
|
||||
"proxy" when (sequence.Status & SequenceStatus.ProxiesBuilt) != 0 => frame.Proxy,
|
||||
"thumb" when (sequence.Status & SequenceStatus.ThumbsBuilt) != 0 => frame.Proxy[..Math.Min(frame.Proxy.Length, 64)],
|
||||
_ => throw NotFound(),
|
||||
@@ -149,6 +171,32 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
await destination.WriteAsync(bytes.AsMemory(offset), cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<string?> DownloadRenderAsync(Guid renderId, Stream destination, CancellationToken cancellationToken)
|
||||
{
|
||||
FakeRender render;
|
||||
lock (_gate) render = Sequences.Values.SelectMany(s => s.Renders).FirstOrDefault(r => r.Id == renderId) ?? throw NotFound();
|
||||
var offset = destination.CanSeek ? (int)Math.Min(destination.Length, render.Bytes.Length) : 0;
|
||||
if (destination.CanSeek) destination.Seek(0, SeekOrigin.End);
|
||||
await destination.WriteAsync(render.Bytes.AsMemory(offset), cancellationToken);
|
||||
return render.FileName;
|
||||
}
|
||||
|
||||
/// <summary>Like the server: the SHA-256 is checked and a render keeps its id; one it already has is not sent again.</summary>
|
||||
public async Task<RenderDto?> UploadRenderAsync(Guid sequenceId, string path, RenderUploadRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var bytes = await File.ReadAllBytesAsync(path, cancellationToken);
|
||||
if (Convert.ToHexStringLower(SHA256.HashData(bytes)) != request.Sha256 || bytes.Length != request.Size)
|
||||
throw new TitanoApiException(HttpStatusCode.UnprocessableEntity, new ApiError("hash_mismatch", "hash"));
|
||||
lock (_gate)
|
||||
{
|
||||
var sequence = Find(sequenceId);
|
||||
if (sequence.Renders.Any(r => r.Id == request.RenderId)) return null;
|
||||
var render = new FakeRender(request.RenderId, request.FileName, request.PresetName, bytes);
|
||||
sequence.Renders.Add(render);
|
||||
return render.Dto();
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
||||
{
|
||||
while (await _events.Reader.WaitToReadAsync(cancellationToken))
|
||||
@@ -178,7 +226,10 @@ internal sealed class FakeSequence
|
||||
public int FramesVersion { get; set; }
|
||||
public SequenceStatus Status { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTime? FirstCapture { get; set; }
|
||||
public string? CameraModel { get; set; } = "Canon EOS R5";
|
||||
public List<FakeFrame> Frames { get; } = [];
|
||||
public List<FakeRender> Renders { get; } = [];
|
||||
|
||||
public FakeFrame AddFrame(byte[] bytes, string? name = null, DateTime? capturedAt = null)
|
||||
{
|
||||
@@ -189,12 +240,17 @@ internal sealed class FakeSequence
|
||||
return frame;
|
||||
}
|
||||
|
||||
public SequenceDto Dto() => new(Id, Title, Title ?? "Untitled", "2026/" + Id.ToString("N"), "Canon", "Canon EOS R5", null, null, null, Frames.Count, 10,
|
||||
Frames.Sum(f => (long)f.Bytes.Length), (long)Status, 0, null, Tags, Rating, Notes, SettingsVersion, FramesVersion, 0, null, UpdatedAt);
|
||||
public SequenceDto Dto() => new(Id, Title, Title ?? "Untitled", "2026/" + Id.ToString("N"), "Canon", CameraModel, null, FirstCapture, null, Frames.Count, 10,
|
||||
Frames.Sum(f => (long)f.Bytes.Length), (long)Status, Renders.Count, null, Tags, Rating, Notes, SettingsVersion, FramesVersion, 0, null, UpdatedAt);
|
||||
|
||||
public SequenceManifest Manifest() => new(Id, FramesVersion, SettingsVersion, SettingsJson, Tags,
|
||||
[.. Frames.Select((f, i) => new ManifestFrame(f.Id, i, f.FileName, f.Bytes.Length, f.Sha256, (Status & SequenceStatus.ProxiesBuilt) != 0,
|
||||
(Status & SequenceStatus.ThumbsBuilt) != 0))], []);
|
||||
(Status & SequenceStatus.ThumbsBuilt) != 0))], [.. Renders.Select(r => r.Dto())]);
|
||||
}
|
||||
|
||||
internal sealed record FakeRender(Guid Id, string FileName, string PresetName, byte[] Bytes)
|
||||
{
|
||||
public RenderDto Dto() => new(Id, PresetName, "hevc", 3840, 2160, 30, 12, Bytes.Length, new DateTimeOffset(2026, 9, 20, 21, 0, 0, TimeSpan.Zero), "Studio NAS");
|
||||
}
|
||||
|
||||
internal sealed record FakeFrame(Guid Id, string FileName, byte[] Bytes, DateTime? CapturedAt)
|
||||
|
||||
Reference in new issue
Block a user