fix(editor): server jobs, stale proxies and read-only accounts in the remote editor

- A server sequence whose cached frames are no longer the server's (a load, a 409
  merge or a frames change event finds other frame ids) turns read-only and says
  why; opening it, or a sequence without cached proxies, queues the proxy
  download and opens it when done. Signed out reads "Connect to the server".
- Server jobs show queued, running (with a bar), paused and analysing glyphs in
  the header with Cancel; a failed or cancelled one raises a toast with Retry.
  Progress alone no longer refreshes the whole editor.
- The server job list is read by state and kind to its last page; "Add to queue"
  sets the job's priority; the event listener survives any failure and always
  releases its frames and connection.
- An account that may render but not edit picks the preset to render without
  changing the project; preset cards and their batch boxes say why they wait.
- Export tab of a server sequence: no local encoder, notices or folder; no Jobs
  history link. Sync at 12 px beside a folder that keeps 96 px and trims.
- Restore's Undo puts back the project from before the restore, only while that
  restore is the editor's last change.
- Export "Sync" of a render that ends while the session is down is queued for the
  saved session's server; skips are logged; sync follows the engine before it
  starts.
- Capture: sequence-remote-export, -running and -readonly, and
  sequence-export-copies.

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-05 22:15:34 +00:00
1 parent 2813184b85
commit 757695f037
27 files changed
+932 -173

No files matched your search

+77 -10
View File
@@ -45,6 +45,7 @@ public sealed class SampleData
private TitanoDatabase? _db;
private Guid _sunrise;
private Guid _lakeComo;
private Permissions _permissions = RolePermissions.Default(UserRole.Editor);
private SampleData(AppServices services) => _services = services;
@@ -56,13 +57,13 @@ public sealed class SampleData
{
if (!services.Environment.IsCapture) throw new InvalidOperationException("Sample data only runs in a capture environment.");
var settings = services.Settings;
var sample = new SampleData(services);
services.Server.Dispose();
services.Server = new ServerSession(settings, services.SaveSettings, new SampleServerApiFactory(), new PlainTokenProtector());
services.Server = new ServerSession(settings, services.SaveSettings, new SampleServerApiFactory(sample), new PlainTokenProtector());
services.Encoders = new SampleEncoders();
services.CheckForUpdateAsync = _ => Task.FromResult<ReleaseInfo?>(null);
services.Devices.Dispose();
services.Devices = new SampleDeviceMonitor();
var sample = new SampleData(services);
services.Sync.RemoteFactory = (_, _, _) => sample._remote;
services.Sync.EditorFactory = (_, _, _) => sample._remote;
return sample;
@@ -163,6 +164,44 @@ public sealed class SampleData
for (var i = 0; i < 200 && await db.Jobs.GetAsync(job.Id) is { State: JobState.Queued or JobState.Running }; i++) await Task.Delay(50);
}
/// <summary>A render of Sunrise over Superga running on the sample server, 43 % done (the remote editor's server job).</summary>
public void RunServerRender() => _remote.Run(_sunrise, "render", 1_240, 2_880);
/// <summary>The sample server's jobs end (none waits or runs any more).</summary>
public void EndServerJobs() => _remote.EndJobs();
/// <summary>
/// The signed-in account keeps Read, Upload and Render but loses Edit (server sequences open read-only); the
/// session is read again so the client sees it.
/// </summary>
public async Task RestrictAccountAsync()
{
_permissions = Permissions.Read | Permissions.Upload | Permissions.Render;
await _services.Server.RestoreAsync();
}
/// <summary>
/// The editor's sample as a sequence the sample server also has (so its Export "Sync" applies), with two copies of
/// this PC's settings kept by "Save both" in its <c>.titano</c> folder.
/// </summary>
public async Task KeepEditorCopiesAsync(Guid sequenceId)
{
var db = _db ?? throw new InvalidOperationException("FillAsync first.");
var sequence = await db.Sequences.GetAsync(sequenceId) ?? throw new InvalidOperationException("FillEditorAsync first.");
var archive = await db.Archives.GetAsync(sequence.ArchiveId) ?? throw new InvalidOperationException("FillEditorAsync first.");
var meta = new ArchivePaths(archive.RootPath).Sequence(sequence.Folder).MetaDirectory;
Directory.CreateDirectory(meta);
var project = sequence.SettingsJson is { } json ? ProjectSettings.FromJson(json) : new ProjectSettings();
var copies = new (DateTime Saved, double OffsetEv)[] { (new DateTime(2026, 9, 30, 21, 14, 5), 0.3), (new DateTime(2026, 10, 2, 8, 41, 37), -0.2) };
foreach (var (saved, offset) in copies)
{
var copy = project with { Exposure = project.Exposure with { ExposureOffsetEv = offset } };
Titano.Core.IO.AtomicFile.WriteAllText(Path.Combine(meta, SyncService.SavedCopyName(saved)), copy.ToJson());
}
var remote = _remote.Add(SampleSyncRemote.Dto(sequence), sequence.SettingsJson, sequence.FrameCount);
await _services.Sync.Service!.LinkAsync(ServerAddress, remote, sequence.Id);
}
/// <summary>
/// The server's side: six sequences this PC also holds (two the same, one with settings changed on both sides, one
/// with more originals on the server, one with more here, one with renders this PC lacks) and two only on the server;
@@ -582,15 +621,15 @@ public sealed class SampleData
}
/// <summary>A server that always answers as "Studio NAS" with a self-signed certificate the sample trusts.</summary>
private sealed class SampleServerApiFactory : IServerApiFactory
private sealed class SampleServerApiFactory(SampleData sample) : IServerApiFactory
{
public IServerApi Create(Uri baseAddress, IReadOnlyCollection<string> trustedFingerprints) => new SampleServerApi(baseAddress, trustedFingerprints);
public IServerApi Create(Uri baseAddress, IReadOnlyCollection<string> trustedFingerprints) => new SampleServerApi(sample, baseAddress, trustedFingerprints);
}
private sealed class SampleServerApi(Uri baseAddress, IReadOnlyCollection<string> trusted) : IServerApi
/// <summary>The sample account, an editor unless <see cref="RestrictAccountAsync"/> took the Edit right away.</summary>
private sealed class SampleServerApi(SampleData sample, Uri baseAddress, IReadOnlyCollection<string> trusted) : IServerApi
{
private static readonly UserDto User = new(Guid.Empty, "alberto", "Alberto", "editor", (long)RolePermissions.Default(UserRole.Editor), 5_000_000_000_000,
2_100_000_000_000, false, false,
private UserDto User => new(Guid.Empty, "alberto", "Alberto", "editor", (long)sample._permissions, 5_000_000_000_000, 2_100_000_000_000, false, false,
new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero), DateTimeOffset.UtcNow);
public Uri BaseAddress { get; } = baseAddress;
@@ -623,8 +662,8 @@ public sealed class SampleData
/// <summary>
/// The sample server's sequences for the sync table and the editor of a server sequence: listings, manifests
/// (frames hashed from their index, so unhashed sample frames match them by count; renders as many as the listing
/// says), settings edits, proxies (generated JPEGs) and jobs the editor posts (kept queued); uploads, originals and
/// analysis reports are not part of the screenshots.
/// says), settings edits, proxies (generated JPEGs) and jobs the editor posts (kept queued until cancelled, or run by
/// <see cref="Run"/>); uploads, originals and analysis reports are not part of the screenshots.
/// </summary>
private sealed class SampleSyncRemote : ISyncRemote, IRemoteSequenceApi
{
@@ -723,6 +762,20 @@ public sealed class SampleData
return Task.FromResult(job);
}
/// <summary>A job of <paramref name="kind"/> running for <paramref name="sequenceId"/>, <paramref name="done"/> of <paramref name="total"/> frames.</summary>
public void Run(Guid sequenceId, string kind, long done, long total)
{
var now = DateTimeOffset.UtcNow;
var job = new JobDto(Guid.CreateVersion7(), kind, [sequenceId], null, "running", "user", done, total, 11.3, (total - done) / 11.3, null, "studio-pc", 1,
null, now.AddMinutes(-2), now.AddMinutes(-2), null);
lock (_jobs) _jobs[job.Id] = job;
}
public void EndJobs()
{
lock (_jobs) _jobs.Clear();
}
public Task<JobDto> GetJobAsync(Guid id, CancellationToken cancellationToken)
{
lock (_jobs) return Task.FromResult(_jobs[id]);
@@ -730,7 +783,21 @@ public sealed class SampleData
public Task<IReadOnlyList<JobDto>> ListActiveJobsAsync(CancellationToken cancellationToken)
{
lock (_jobs) return Task.FromResult<IReadOnlyList<JobDto>>([.. _jobs.Values]);
lock (_jobs) return Task.FromResult<IReadOnlyList<JobDto>>([.. _jobs.Values.Where(j => j.State is "queued" or "running" or "paused")]);
}
public Task<JobDto> CancelJobAsync(Guid id, CancellationToken cancellationToken) =>
Task.FromResult(Update(id, job => job with { State = "cancelled", Finished = DateTimeOffset.UtcNow }));
public Task<JobDto> RetryJobAsync(Guid id, CancellationToken cancellationToken) =>
Task.FromResult(Update(id, job => job with { State = "queued", Error = null, Finished = null }));
public Task<JobDto> SetJobPriorityAsync(Guid id, string priority, CancellationToken cancellationToken) =>
Task.FromResult(Update(id, job => job with { Priority = priority }));
private JobDto Update(Guid id, Func<JobDto, JobDto> change)
{
lock (_jobs) return _jobs[id] = change(_jobs[id]);
}
public void Dispose()