merge: desktop settings fixes (V-4, V-6, V-7, V-30, V-31, V-32, V-34, ENG-08)
Merge branch fix2/desktop-settings into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
34 files changed
+1132
-171
No files matched your search
@@ -19,7 +19,9 @@ public static class ArchiveEndpoints
|
||||
public static void Map(RouteGroupBuilder api)
|
||||
{
|
||||
var archive = api.MapGroup("/archive").Requires(Permissions.ManageArchive);
|
||||
archive.MapGet("/settings", (ServerArchive a) => Results.Json(Settings(a.Current), ProtocolJson.Default.ArchiveSettingsDto));
|
||||
// The form saves every field: it starts from what archive.json holds now, also a desktop's change since the last poll.
|
||||
archive.MapGet("/settings", async (HttpContext c, ServerArchive a, TitanoDatabase db, [FromServices] ArchiveService? archives) =>
|
||||
Results.Json(Settings(archives is null ? a.Current : await a.RefreshAsync(archives, db, c.RequestAborted)), ProtocolJson.Default.ArchiveSettingsDto));
|
||||
archive.MapPut("/settings", UpdateAsync);
|
||||
archive.MapGet("/stats", async (HttpContext c, TitanoDatabase db, ServerArchive a) =>
|
||||
Results.Json(await StatsAsync(db, a, c.RequestAborted), ProtocolJson.Default.ArchiveStatsDto));
|
||||
|
||||
@@ -10,9 +10,11 @@ namespace Titano.Server.Storage;
|
||||
/// Polls the archive (BRIEF §7: by modification time and size, no file-system watchers): an incremental scan at start
|
||||
/// and every <see cref="Interval"/> while the archive is online, so photos already in an adopted folder and sequences
|
||||
/// another writer adds (a desktop sharing the archive, files copied in by hand) are indexed without an administrator's
|
||||
/// rescan. A scan or rebuild of the archive that is waiting, running or paused is not queued again.
|
||||
/// rescan. Settings such a writer changed in archive.json reach the index first, so uploads and the admin panel follow
|
||||
/// them. A scan or rebuild of the archive that is waiting, running or paused is not queued again.
|
||||
/// </summary>
|
||||
public sealed class ArchivePolling(TitanoDatabase db, ServerArchive archive, JobEngineHost jobs, TimeProvider time, ILogger<ArchivePolling> logger)
|
||||
public sealed class ArchivePolling(TitanoDatabase db, ServerArchive archive, ArchiveService archives, JobEngineHost jobs, TimeProvider time,
|
||||
ILogger<ArchivePolling> logger)
|
||||
: BackgroundService
|
||||
{
|
||||
/// <summary>The desktop's rhythm (it polls its archive the same way).</summary>
|
||||
@@ -26,6 +28,7 @@ public sealed class ArchivePolling(TitanoDatabase db, ServerArchive archive, Job
|
||||
if (!jobs.CanRun(JobKind.Scan)) return null;
|
||||
var current = archive.Current;
|
||||
if (ArchiveService.GetAvailability(current) != ArchiveAvailability.Online) return null;
|
||||
current = await archive.RefreshAsync(archives, db, cancellationToken);
|
||||
foreach (var kind in new[] { JobKind.Scan, JobKind.Rebuild })
|
||||
{
|
||||
foreach (var state in Pending)
|
||||
|
||||
@@ -19,6 +19,29 @@ public sealed class ServerArchive(Archive archive)
|
||||
set => _current = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serves <paramref name="value"/> unless <see cref="Current"/> is no longer <paramref name="expected"/>, the archive
|
||||
/// it was read from: an edit an administrator saved meanwhile is never undone. False when it was not replaced.
|
||||
/// </summary>
|
||||
public bool TryReplace(Archive expected, Archive value) => ReferenceEquals(Interlocked.CompareExchange(ref _current, value, expected), expected);
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Current"/> once it and the index row hold the settings another writer sharing the archive (a desktop)
|
||||
/// put into its archive.json (<see cref="ArchiveService.RefreshSettingsAsync"/>): uploads, the polling and the admin
|
||||
/// panel, whose form saves every field, never work from older ones. Unchanged while the file cannot be read.
|
||||
/// </summary>
|
||||
public async Task<Archive> RefreshAsync(ArchiveService archives, TitanoDatabase db, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(archives);
|
||||
ArgumentNullException.ThrowIfNull(db);
|
||||
var current = Current;
|
||||
// Only a change the refresh registered is served, and never over an edit an administrator saved since the read above.
|
||||
if (await archives.RefreshSettingsAsync(current.Id, cancellationToken).ConfigureAwait(false) is { } settings && !settings.IsRegisteredIn(current)
|
||||
&& await db.Archives.GetAsync(current.Id, cancellationToken).ConfigureAwait(false) is { } row)
|
||||
TryReplace(current, row);
|
||||
return Current;
|
||||
}
|
||||
|
||||
public Guid Id => _current.Id;
|
||||
|
||||
public string Root => _current.RootPath;
|
||||
|
||||
Reference in new issue
Block a user