feat(server): settings sent alone move the hero frame with the project's hero
The sync of a local copy sends only the project; the server now maps its hero index to the frame the Library shows, through the same helper the archive engine's project writes use. Edits that name the hero are audited as such. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+76
-10
No files matched your search
@@ -3,7 +3,9 @@ using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Repositories;
|
||||
using Titano.Protocol;
|
||||
using Titano.Server.Configuration;
|
||||
@@ -131,7 +133,9 @@ public static class SequenceEndpoints
|
||||
Rating = request.Rating,
|
||||
Notes = request.Notes,
|
||||
SettingsJson = request.SettingsJson,
|
||||
HeroFrameId = request.HeroFrameId,
|
||||
// A client that sends only the settings (the sync of a local copy) moves the hero frame with the project's hero.
|
||||
HeroFrameId = request.HeroFrameId
|
||||
?? (request.SettingsJson is { } settings ? await SettingsHeroAsync(db, id, settings, context.RequestAborted) : null),
|
||||
};
|
||||
var result = await db.Sequences.EditAsync(id, edit, expected, context.RequestAborted);
|
||||
switch (result.Outcome)
|
||||
@@ -293,6 +297,22 @@ public static class SequenceEndpoints
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>The hero frame edit of new settings: the frame of their hero when it is not the stored settings' hero.</summary>
|
||||
private static async Task<Guid?> SettingsHeroAsync(TitanoDatabase db, Guid id, string settingsJson, CancellationToken ct)
|
||||
{
|
||||
if (await db.Sequences.GetAsync(id, ct) is not { } current) return null;
|
||||
try
|
||||
{
|
||||
var before = string.IsNullOrWhiteSpace(current.SettingsJson) ? null : ProjectSettings.FromJson(current.SettingsJson).HeroFrame;
|
||||
return await HeroFrame.EditAsync(db, id, before, ProjectSettings.FromJson(settingsJson).HeroFrame, ct);
|
||||
}
|
||||
catch (Exception ex) when (ex is JsonException or InvalidDataException)
|
||||
{
|
||||
// Not a project of this Titano (a newer one, or free JSON): its hero is unknown here, the stored one stays.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsJson(string text)
|
||||
{
|
||||
try
|
||||
@@ -314,6 +334,7 @@ public static class SequenceEndpoints
|
||||
if (r.Rating is not null) fields.Add("rating");
|
||||
if (r.Notes is not null) fields.Add("notes");
|
||||
if (r.SettingsJson is not null) fields.Add("settings");
|
||||
if (r.HeroFrameId is not null) fields.Add("hero");
|
||||
return string.Join(", ", fields);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user