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
@@ -1,3 +1,6 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
@@ -25,23 +28,68 @@ public enum SyncAction
|
||||
KeepMine,
|
||||
TakeServer,
|
||||
SaveBoth,
|
||||
GetExports,
|
||||
SendExports,
|
||||
Pause,
|
||||
Resume,
|
||||
}
|
||||
|
||||
/// <summary>What the signed-in account may do (server permission bits).</summary>
|
||||
/// <param name="CanUpload">Send originals and settings.</param>
|
||||
/// <param name="CanUpload">Send originals, settings and renders (upload and edit rights).</param>
|
||||
/// <param name="CanFetchOriginals">Download originals (editors and render nodes).</param>
|
||||
public readonly record struct SyncRights(bool CanUpload, bool CanFetchOriginals)
|
||||
/// <param name="CanEdit">Change the server's copy of a sequence's settings, title, tags, rating and notes.</param>
|
||||
public readonly record struct SyncRights(bool CanUpload, bool CanFetchOriginals, bool CanEdit)
|
||||
{
|
||||
public static SyncRights Of(long permissions) => new(
|
||||
(permissions & (long)Permissions.Upload) != 0 && (permissions & (long)Permissions.Edit) != 0,
|
||||
(permissions & (long)(Permissions.Edit | Permissions.RenderNode)) != 0);
|
||||
(permissions & (long)(Permissions.Edit | Permissions.RenderNode)) != 0,
|
||||
(permissions & (long)Permissions.Edit) != 0);
|
||||
}
|
||||
|
||||
/// <summary>The words, glyphs and actions of the sync table (BRIEF §12.7): plain functions of a <see cref="SyncEntry"/>.</summary>
|
||||
public static class SyncText
|
||||
{
|
||||
/// <summary>Resource keys of the settings and sequence fields a conflict can show, by JSON path (sections, then members).</summary>
|
||||
private static readonly Dictionary<string, string> SettingKeys = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["sequence.title"] = "Server.Setting.Title",
|
||||
["sequence.tags"] = "Server.Setting.Tags",
|
||||
["sequence.rating"] = "Server.Setting.Rating",
|
||||
["sequence.notes"] = "Server.Setting.Notes",
|
||||
["timing.mode"] = "Server.Setting.TimingMode",
|
||||
["timing.frameRate"] = "Server.Setting.FrameRate",
|
||||
["timing.fitToSeconds"] = "Server.Setting.FitToDuration",
|
||||
["timing.remapCurve"] = "Server.Setting.TimeRemap",
|
||||
["exposure.deflicker"] = "Server.Setting.Deflicker",
|
||||
["exposure.deflickerWindow"] = "Server.Setting.DeflickerWindow",
|
||||
["exposure.deflickerStrength"] = "Server.Setting.DeflickerStrength",
|
||||
["exposure.regions"] = "Server.Setting.Regions",
|
||||
["exposure.holyGrail"] = "Server.Setting.HolyGrail",
|
||||
["exposure.transitionLength"] = "Server.Setting.Transitions",
|
||||
["exposure.whiteBalanceSmoothing"] = "Server.Setting.WhiteBalance",
|
||||
["exposure.exposureOffsetEv"] = "Server.Setting.ExposureOffset",
|
||||
["exposure.highlightKnee"] = "Server.Setting.HighlightKnee",
|
||||
["motion.motionBlur"] = "Server.Setting.MotionBlur",
|
||||
["motion.targetShutterAngle"] = "Server.Setting.ShutterAngle",
|
||||
["motion.flowQuality"] = "Server.Setting.FlowQuality",
|
||||
["motion.stabilize"] = "Server.Setting.Stabilize",
|
||||
["motion.stabilizeSmoothing"] = "Server.Setting.StabilizeSmoothing",
|
||||
["camera.crop"] = "Server.Setting.Crop",
|
||||
["camera.aspect"] = "Server.Setting.Aspect",
|
||||
["camera.offsetX"] = "Server.Setting.CameraOffset",
|
||||
["camera.offsetY"] = "Server.Setting.CameraOffset",
|
||||
["camera.keyframes"] = "Server.Setting.Keyframes",
|
||||
["stack.mode"] = "Server.Setting.Stacking",
|
||||
["stack.length"] = "Server.Setting.TrailLength",
|
||||
["export.preset"] = "Server.Setting.ExportPreset",
|
||||
["export.overrides"] = "Server.Setting.ExportValues",
|
||||
["export.nameTemplate"] = "Server.Setting.OutputName",
|
||||
["export.folder"] = "Server.Setting.ExportFolder",
|
||||
["export.batch"] = "Server.Setting.Batch",
|
||||
["excludedFrames"] = "Server.Setting.ExcludedFrames",
|
||||
["heroFrame"] = "Server.Setting.HeroFrame",
|
||||
};
|
||||
|
||||
/// <summary>"originals · proxies", "proxies" (cached server proxies) or "—".</summary>
|
||||
public static string Local(SyncEntry entry)
|
||||
{
|
||||
@@ -76,6 +124,7 @@ public static class SyncText
|
||||
Loc.L(upload ? "Tooltips.Server.Sync.State.Uploading" : "Tooltips.Server.Sync.State.Downloading")),
|
||||
};
|
||||
}
|
||||
if (entry.Link?.Error is { } error) return (StatusKind.Warning, Loc.L("Server.Sync.State.Failed"), Loc.L("Tooltips.Server.Sync.State.Failed", error));
|
||||
return entry.Status switch
|
||||
{
|
||||
SyncStatus.InSync => (StatusKind.Done, Loc.L("Server.Sync.State.InSync"), Loc.L("Tooltips.Server.Sync.State.InSync")),
|
||||
@@ -84,16 +133,44 @@ public static class SyncText
|
||||
SyncStatus.ProxiesOnly => (StatusKind.Remote, Loc.L("Server.Sync.State.ProxiesOnly"), Loc.L("Tooltips.Server.Sync.State.ProxiesOnly")),
|
||||
SyncStatus.LocalAhead => (StatusKind.Synced, Loc.L("Server.Sync.State.LocalAhead"), Loc.L("Tooltips.Server.Sync.State.LocalAhead")),
|
||||
SyncStatus.ServerAhead => (StatusKind.Remote, Loc.L("Server.Sync.State.ServerAhead"), Loc.L("Tooltips.Server.Sync.State.ServerAhead")),
|
||||
_ => (StatusKind.Warning, Loc.L("Server.Sync.State.Conflict"), Conflict(entry)),
|
||||
_ => (StatusKind.Warning, Loc.L("Server.Sync.State.Conflict"), ConflictSummary(entry)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>"exposure.deflickerWindow.manual: 41 here, 33 on the server" for each setting that differs (at most three).</summary>
|
||||
public static string Conflict(SyncEntry entry)
|
||||
/// <summary>One line for the State tooltip: "Deflicker window 41 here, 33 on the server · +2".</summary>
|
||||
public static string ConflictSummary(SyncEntry entry)
|
||||
{
|
||||
var differences = entry.Link?.ConflictSettingsJson is { } theirs ? SyncRules.Differences(entry.Local?.SettingsJson, theirs) : [];
|
||||
if (differences.Count == 0) return Loc.L("Tooltips.Server.Sync.State.Conflict");
|
||||
return string.Join("\n", differences.Select(d => Loc.L("Server.Conflict.Difference", d.Path, d.Mine ?? Loc.L("Server.Sync.None"), d.Theirs ?? Loc.L("Server.Sync.None"))));
|
||||
var lines = Conflict(entry, int.MaxValue);
|
||||
return lines.Count switch
|
||||
{
|
||||
0 => Loc.L("Tooltips.Server.Sync.State.Conflict"),
|
||||
1 => lines[0],
|
||||
_ => Loc.L("Server.Conflict.More", lines[0], Formatting.Count(lines.Count - 1)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What differs, one line per setting or sequence field in project order ("Deflicker window 41 here, 33 on the
|
||||
/// server", "Tags differ"), at most <paramref name="max"/>.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<string> Conflict(SyncEntry entry, int max)
|
||||
{
|
||||
if (entry is not { Local: { } local, Link.ConflictRemote: { } theirs }) return [];
|
||||
var lines = new List<string>();
|
||||
var shown = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var difference in SyncRules.Differences(SyncPayload.Of(local), theirs, 64))
|
||||
{
|
||||
var (key, field) = Setting(difference.Path);
|
||||
if (!shown.Add(key)) continue;
|
||||
var label = Loc.L(key);
|
||||
var metadata = difference.Path.StartsWith(SyncRules.MetadataPath, StringComparison.Ordinal);
|
||||
lines.Add((metadata ? Text(difference.Mine) : Value(difference.Mine, field)) is { } mine
|
||||
&& (metadata ? Text(difference.Theirs) : Value(difference.Theirs, field)) is { } server
|
||||
? Loc.L("Server.Conflict.Difference", label, mine, server)
|
||||
: Loc.L("Server.Conflict.Changed", label));
|
||||
if (lines.Count == max) break;
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
/// <summary>The row's buttons, in the order the mockup shows them.</summary>
|
||||
@@ -116,24 +193,42 @@ public static class SyncText
|
||||
case SyncStatus.ServerAhead when entry.Link is { MissingLocal: > 0 }:
|
||||
if (rights.CanFetchOriginals) actions.Add(SyncAction.DownloadOriginals);
|
||||
break;
|
||||
case SyncStatus.LocalAhead or SyncStatus.ServerAhead:
|
||||
case SyncStatus.LocalAhead when rights.CanEdit:
|
||||
case SyncStatus.ServerAhead:
|
||||
actions.Add(SyncAction.SyncSettings);
|
||||
break;
|
||||
case SyncStatus.Conflict:
|
||||
actions.AddRange([SyncAction.KeepMine, SyncAction.TakeServer, SyncAction.SaveBoth]);
|
||||
break;
|
||||
if (rights.CanEdit) actions.Add(SyncAction.KeepMine);
|
||||
actions.AddRange([SyncAction.TakeServer, SyncAction.SaveBoth]);
|
||||
return actions;
|
||||
}
|
||||
if (entry is { Local: not null, Link: { } link })
|
||||
{
|
||||
if (link.ExportsToGet > 0) actions.Add(SyncAction.GetExports);
|
||||
if (link.ExportsToSend > 0 && rights.CanUpload) actions.Add(SyncAction.SendExports);
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
/// <summary>The bytes an upload or download of the row moves (for the tooltips).</summary>
|
||||
/// <summary>The bytes an action moves (for the tooltips).</summary>
|
||||
public static long Size(SyncEntry entry, SyncAction action) => action switch
|
||||
{
|
||||
SyncAction.Upload => entry.Local?.TotalBytes ?? 0,
|
||||
SyncAction.DownloadOriginals => entry.Link?.TotalBytes ?? 0,
|
||||
SyncAction.GetExports => entry.Link?.ExportsToGetBytes ?? 0,
|
||||
SyncAction.SendExports => entry.Link?.ExportsToSendBytes ?? 0,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
/// <summary>The tooltip of a row button: what it does and, for transfers, what it moves.</summary>
|
||||
public static string ToolTip(SyncEntry entry, SyncAction action) => action switch
|
||||
{
|
||||
SyncAction.Upload or SyncAction.DownloadOriginals => Loc.L("Tooltips.Server.Sync." + action, Formatting.Bytes(Size(entry, action))),
|
||||
SyncAction.GetExports => Loc.Plural("Tooltips.Server.Sync.GetExports", entry.Link!.ExportsToGet, Formatting.Bytes(Size(entry, action))),
|
||||
SyncAction.SendExports => Loc.Plural("Tooltips.Server.Sync.SendExports", entry.Link!.ExportsToSend, Formatting.Bytes(Size(entry, action))),
|
||||
_ => Loc.L("Tooltips.Server.Sync." + action),
|
||||
};
|
||||
|
||||
public static bool Matches(SyncEntry entry, SyncFilter filter, string search) =>
|
||||
(filter switch
|
||||
{
|
||||
@@ -143,5 +238,49 @@ public static class SyncText
|
||||
_ => true,
|
||||
}) && (search.Length == 0 || entry.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
/// <summary>
|
||||
/// The label key of a difference path and the member below the setting it reaches ("isAuto", "manual", … of an
|
||||
/// Auto parameter; null for the setting itself): "exposure.deflickerWindow.manual" is the deflicker window's manual value.
|
||||
/// </summary>
|
||||
private static (string Key, string? Field) Setting(string path)
|
||||
{
|
||||
var segments = path.Split('.');
|
||||
for (var length = segments.Length; length > 0; length--)
|
||||
{
|
||||
if (SettingKeys.TryGetValue(string.Join('.', segments[..length]), out var key)) return (key, length < segments.Length ? segments[length] : null);
|
||||
}
|
||||
return ("Server.Setting.Other", segments[^1]);
|
||||
}
|
||||
|
||||
/// <summary>A title, tags, rating or notes value as shown ("—" when empty).</summary>
|
||||
private static string Text(string? value) => string.IsNullOrWhiteSpace(value) ? Loc.L("Server.Sync.None") : Shorten(value);
|
||||
|
||||
/// <summary>A side's value as shown ("41", "on", "auto"); null when it is not a single value worth printing.</summary>
|
||||
private static string? Value(string? json, string? field)
|
||||
{
|
||||
if (json is null) return field is null or "manual" ? Loc.L("Server.Sync.None") : null;
|
||||
if (field is not (null or "manual" or "autoValue" or "isAuto")) return null;
|
||||
JsonNode? node;
|
||||
try
|
||||
{
|
||||
node = JsonNode.Parse(json);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (field == "isAuto") return node is JsonValue v && v.TryGetValue<bool>(out var auto) ? Loc.L(auto ? "Server.Setting.Auto" : "Server.Setting.Manual") : null;
|
||||
return node switch
|
||||
{
|
||||
null => Loc.L("Server.Sync.None"),
|
||||
JsonValue value when value.TryGetValue<bool>(out var flag) => Loc.L(flag ? "Server.Setting.On" : "Server.Setting.Off"),
|
||||
JsonValue value when value.TryGetValue<double>(out var number) => number.ToString("0.###", Loc.Culture),
|
||||
JsonValue value when value.TryGetValue<string>(out var text) => Shorten(text),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
private static string Shorten(string text) => text.Length <= 40 ? text : string.Concat(text.AsSpan(0, 39), "…");
|
||||
|
||||
private static string Join(params string[] parts) => string.Join(" · ", parts);
|
||||
}
|
||||
Reference in new issue
Block a user