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:
Claude committed 2026-10-03 10:26:56 +00:00
1 parent 3601e0a47f
commit 2d40a613b9
48 files changed
+2498 -465

No files matched your search

+30 -12
View File
@@ -1,5 +1,7 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Protocol;
@@ -15,8 +17,8 @@ public sealed record SyncPayload(string? Title, IReadOnlyList<string> Tags, int
/// <summary>Title, tags, rating and notes match (blank equals absent, tags ignore case and order).</summary>
public bool SameMetadata(SyncPayload other) =>
Blank(Title) == Blank(other.Title)
&& Blank(Notes) == Blank(other.Notes)
SyncRules.Blank(Title) == SyncRules.Blank(other.Title)
&& SyncRules.Blank(Notes) == SyncRules.Blank(other.Notes)
&& Rating == other.Rating
&& Tags.ToHashSet(StringComparer.OrdinalIgnoreCase).SetEquals(other.Tags);
@@ -25,20 +27,27 @@ public sealed record SyncPayload(string? Title, IReadOnlyList<string> Tags, int
/// <summary>The PATCH that makes the server's copy equal to this one; settings are sent in their normalised form.</summary>
public UpdateSequenceRequest ToRequest(int? expectedSettingsVersion) =>
new(Title ?? string.Empty, Tags, Rating, Notes ?? string.Empty, SyncRules.NormalizeSettings(SettingsJson), expectedSettingsVersion);
private static string Blank(string? text) => text?.Trim() ?? string.Empty;
}
/// <summary>One setting that differs: its dotted path ("exposure.deflicker.window") and the JSON value on each side (null when absent).</summary>
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(SyncPayload))]
internal sealed partial class SyncPayloadJson : JsonSerializerContext;
/// <summary>
/// One field that differs: its dotted path ("exposure.deflickerWindow.manual", or "sequence.tags" for the metadata)
/// and the value on each side (JSON for settings, plain text for metadata; null when absent).
/// </summary>
public sealed record SettingsDifference(string Path, string? Mine, string? Theirs);
/// <summary>Decisions of the sync engine that need no I/O: the status of a row, settings equality and differences, merges.</summary>
public static class SyncRules
{
/// <summary>Path prefix of the title, tags, rating and notes in <see cref="Differences(SyncPayload, SyncPayload, int)"/>.</summary>
public const string MetadataPath = "sequence.";
/// <summary>
/// Where a linked pair stands. Settings changed on both sides since they last agreed are a conflict (the engine
/// settles equal content and metadata-only differences before a row is shown); missing originals count before
/// settings changed on one side only.
/// settles equal content before a row is shown); missing originals count before settings changed on one side only.
/// </summary>
public static SyncStatus Status(Sequence? local, SyncLink? link)
{
@@ -91,13 +100,20 @@ public static class SyncRules
}
/// <summary>
/// Metadata-only divergence (settings equal): tags are united, title, rating and notes come from the side edited last.
/// Up to <paramref name="max"/> differences between two payloads: title, tags, rating and notes first (paths
/// <c>sequence.title</c>, <c>sequence.tags</c>, …, tags as one comma-separated value), then the settings.
/// </summary>
public static SyncPayload Merge(SyncPayload local, SyncPayload remote, bool localIsNewer)
public static IReadOnlyList<SettingsDifference> Differences(SyncPayload mine, SyncPayload theirs, int max = 3)
{
var newer = localIsNewer ? local : remote;
var tags = local.Tags.Concat(remote.Tags).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
return newer with { Tags = tags, SettingsJson = local.SettingsJson };
var differences = new List<SettingsDifference>();
if (Blank(mine.Title) != Blank(theirs.Title)) differences.Add(new(MetadataPath + "title", Blank(mine.Title), Blank(theirs.Title)));
if (!mine.Tags.ToHashSet(StringComparer.OrdinalIgnoreCase).SetEquals(theirs.Tags))
differences.Add(new(MetadataPath + "tags", string.Join(", ", mine.Tags), string.Join(", ", theirs.Tags)));
if (mine.Rating != theirs.Rating)
differences.Add(new(MetadataPath + "rating", mine.Rating.ToString(CultureInfo.InvariantCulture), theirs.Rating.ToString(CultureInfo.InvariantCulture)));
if (Blank(mine.Notes) != Blank(theirs.Notes)) differences.Add(new(MetadataPath + "notes", Blank(mine.Notes), Blank(theirs.Notes)));
if (differences.Count < max) differences.AddRange(Differences(mine.SettingsJson, theirs.SettingsJson, max - differences.Count));
return differences.Count > max ? differences.GetRange(0, max) : differences;
}
/// <summary>
@@ -114,6 +130,8 @@ public static class SyncRules
return (hashed.Count - matched + Math.Max(0, unhashed - unmatchedRemote), Math.Max(0, unmatchedRemote - unhashed));
}
internal static string Blank(string? text) => text?.Trim() ?? string.Empty;
private static JsonNode? Parse(string json)
{
try