merge: integration branch claude/keen-knuth-uhxv8w (remote editor after review) into the Library workstream

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-06 20:38:30 +00:00
commit a4ceb89247
81 files changed
+3827 -263

No files matched your search

+106 -13
View File
@@ -46,22 +46,27 @@ 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;
/// <summary>The server-only sequence whose proxies <see cref="CacheProxiesAsync"/> keeps on this PC (Sunrise over Superga).</summary>
public Guid ProxiedSequenceId => _sunrise;
/// <summary>Points the services at fakes (server, encoders, update check) for an empty first-run state.</summary>
public static SampleData Configure(AppServices services)
{
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;
}
@@ -170,6 +175,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
@@ -600,15 +643,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;
@@ -639,13 +682,15 @@ public sealed class SampleData
}
/// <summary>
/// The sample server's sequences for the sync table: listings, manifests (frames hashed from their index, so
/// unhashed sample frames match them by count; renders as many as the listing says), settings edits and proxies
/// (generated JPEGs); uploads and originals are not part of the screenshots.
/// 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 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
private sealed class SampleSyncRemote : ISyncRemote, IRemoteSequenceApi
{
private readonly Dictionary<Guid, (SequenceDto Dto, string? Settings, Guid[] Frames)> _sequences = [];
private readonly Dictionary<Guid, JobDto> _jobs = [];
public string Server => ServerAddress;
@@ -698,9 +743,9 @@ public sealed class SampleData
{
lock (_sequences)
{
var (dto, _, frames) = _sequences[id];
var (dto, settings, frames) = _sequences[id];
var updated = dto with { SettingsVersion = dto.SettingsVersion + 1, UpdatedAt = DateTimeOffset.UtcNow };
_sequences[id] = (updated, request.SettingsJson, frames);
_sequences[id] = (updated, request.SettingsJson ?? settings, frames);
return Task.FromResult(updated);
}
}
@@ -729,6 +774,54 @@ public sealed class SampleData
yield break;
}
public Task<string?> GetAnalysisReportAsync(Guid id, CancellationToken cancellationToken) => Task.FromResult<string?>(null);
public Task<JobDto> CreateJobAsync(CreateJobRequest request, CancellationToken cancellationToken)
{
var job = new JobDto(Guid.CreateVersion7(), request.Kind, request.Target, null, "queued", "user", 0, 0, null, null, null, null, 0, null,
DateTimeOffset.UtcNow, null, null);
lock (_jobs) _jobs[job.Id] = job;
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]);
}
public Task<IReadOnlyList<JobDto>> ListActiveJobsAsync(CancellationToken cancellationToken)
{
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()
{
}