feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s

- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job.
- One naming rule (FrameNaming) for import, upload and Reorganize.
- Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder.
- Writers refuse a folder another program moved or gave to another sequence.
- Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules.
- Phase 3 docs and translations merged; strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #12.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-27 21:58:39 +01:00
1 parent 9aa818ed47
commit 7e4a3b481d
416 files changed
+15304 -1572

No files matched your search

+13 -2
View File
@@ -3,14 +3,17 @@ using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Housekeeping;
using Chronos.Data.Jobs;
using Chronos.Protocol;
using Chronos.Server.Configuration;
using Chronos.Server.Events;
namespace Chronos.Server.Storage;
/// <summary>
/// The archive engine behind the server (BRIEF §7, §14.4): ingest of verified uploads, lookup of proxies and
/// thumbnails, and its job handlers (scan, rebuild, verify, import, thumbnails, proxies, maintenance, the duplicates and
/// orphans reports, index backups and clean-ups with the server's own steps, the <see cref="ICleanupStep"/>s in DI); a scan
/// orphans reports, index backups and clean-ups with the server's own steps, the <see cref="ICleanupStep"/>s in DI, and Reorganize's
/// <c>move</c> jobs, which tell connected clients of the sequences they change); a scan
/// queues thumbnails and proxies of what it indexes, as an upload does. Decoding is managed only (BRIEF §4.2). Recurring
/// work (the periodic scan, the nightly backup of an SQLite index, clean-ups) is queued by the server's system schedules
/// (<see cref="Jobs.ServerScheduleHost"/>, owner review 2, R10).
@@ -25,9 +28,17 @@ public static class ArchiveModule
services.AddSingleton(sp =>
{
var options = sp.GetRequiredService<ServerOptions>();
var db = sp.GetRequiredService<ChronosDatabase>();
var events = sp.GetRequiredService<EventHub>();
// Photos the running job processes at once: the settings' value as it is when each sequence starts (owner review 1).
return new ArchiveService(sp.GetRequiredService<ChronosDatabase>(), new ArchiveServiceOptions
return new ArchiveService(db, new ArchiveServiceOptions
{
// A Reorganize tells connected clients of every sequence it changed (BRIEF §14.3).
SequenceChanged = async (id, change, ct) =>
{
if (await db.Sequences.GetAsync(id, ct) is { } sequence)
events.Publish(new SequenceChangedEvent(id, change, sequence.FramesVersion, sequence.SettingsVersion));
},
Decoder = DecoderFactory.CreateServer(),
Owner = Owner,
ImagesAfterScan = true,
+50 -27
View File
@@ -1,47 +1,64 @@
using Chronos.Core.Archiving;
using Chronos.Core.IO;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Protocol;
namespace Chronos.Server.Storage;
/// <summary>Files a verified render output under the sequence's <c>exports/</c> folder (BRIEF §7) and records it.</summary>
public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeProvider time)
/// <param name="archives">The archive engine whose sequence lease the filing takes; one of its own when none is registered.</param>
public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeProvider time, ArchiveService? archives = null)
{
private readonly ArchiveService _archives = archives ?? new ArchiveService(db, new ArchiveServiceOptions { Owner = ArchiveModule.Owner });
/// <summary>
/// Moves <paramref name="stagedFile"/> (on the archive volume) to <c>&lt;sequence folder&gt;/exports/</c>, never
/// replacing an existing export, and inserts the render row. Null when the sequence has no folder in the archive yet.
/// replacing an existing export, and inserts the render row, both under the sequence's lease with its folder as the
/// index has it then: a Reorganize may have moved it since <paramref name="sequence"/> was read, and moves the row's
/// path along when it moves it later. Null when the sequence left the index or has no folder in the archive yet; nothing
/// is moved then.
/// </summary>
/// <exception cref="FolderMovedException">The sequence is not in the folder the index has (another index moved it, and
/// maybe another sequence into that folder): nothing is moved, and the filing can be done again once this index's next
/// scan found the folder.</exception>
public Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, CancellationToken cancellationToken) =>
CommitAsync(sequence, stagedFile, output, producedBy, Guid.CreateVersion7(), cancellationToken);
/// <summary>As above, keeping <paramref name="id"/>: a render a client sends keeps the id it has on that client.</summary>
public async Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, Guid id,
CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(sequence.Folder) || ArchivePathGuard.Resolve(archive.Root, sequence.Folder.TrimEnd('/') + "/exports") is not { } exports)
return null;
Directory.CreateDirectory(exports);
var target = Unique(exports, output.FileName);
File.Move(stagedFile, target);
var render = new Render
/// <exception cref="FolderMovedException">The sequence is not in the folder the index has.</exception>
public Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, Guid id,
CancellationToken cancellationToken) =>
_archives.UnderLeaseAsync(sequence, async row =>
{
Id = id,
SequenceId = sequence.Id,
PresetName = output.PresetName,
OutputPath = LongPath.ToPortableRelative(archive.Root, target),
Codec = output.Codec,
Width = output.Width,
Height = output.Height,
Fps = output.Fps,
DurationSeconds = output.DurationSeconds,
Bytes = output.Size,
Created = time.GetUtcNow(),
ProducedBy = producedBy,
};
await db.Renders.InsertAsync(render, cancellationToken);
return render;
}
if (row is null || string.IsNullOrEmpty(row.Folder) || ArchivePathGuard.Resolve(archive.Root, row.Folder.TrimEnd('/') + "/exports") is not { } exports)
return null;
// A folder another index moved is found by this index's next scan; until then nothing is filed, so it is not created
// again, nor filed among the exports of another sequence that index moved into it since.
if (!SequenceFolders.Holds(new ArchivePaths(archive.Root).Sequence(row.Folder), row.Id)) throw new FolderMovedException();
Directory.CreateDirectory(exports);
var target = Unique(exports, output.FileName);
File.Move(stagedFile, target);
var render = new Render
{
Id = id,
SequenceId = row.Id,
PresetName = output.PresetName,
OutputPath = LongPath.ToPortableRelative(archive.Root, target),
Codec = output.Codec,
Width = output.Width,
Height = output.Height,
Fps = output.Fps,
DurationSeconds = output.DurationSeconds,
Bytes = output.Size,
Created = time.GetUtcNow(),
ProducedBy = producedBy,
};
await db.Renders.InsertAsync(render, cancellationToken);
return (Render?)render;
}, cancellationToken);
private static string Unique(string folder, string fileName)
{
@@ -52,3 +69,9 @@ public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeP
return candidate;
}
}
/// <summary>
/// A sequence is not in the folder the index has (another index of the archive moved it): nothing was filed into it, and
/// this index's next scan finds the folder, after which the filing can be done again.
/// </summary>
public sealed class FolderMovedException() : IOException(Loc.L("Errors.Archive.FolderMoved"));
+12 -2
View File
@@ -1,5 +1,7 @@
using System.Globalization;
using System.Text.Json;
using Chronos.Core.Archiving;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Repositories;
using Chronos.Protocol;
@@ -87,8 +89,16 @@ public sealed class RenderUploads(
var sequence = await db.Sequences.GetAsync(sequenceId, cancellationToken);
var result = new RenderResultRequest(output.FileName, output.Size, output.Sha256, output.PresetName, output.Codec, output.Width, output.Height, output.Fps,
output.DurationSeconds);
var render = sequence is null ? null : await renders.CommitAsync(sequence, staged, result, output.ProducedBy ?? caller.ClientName ?? caller.User.Username,
output.RenderId, cancellationToken);
Render? render;
try
{
render = sequence is null ? null : await renders.CommitAsync(sequence, staged, result, output.ProducedBy ?? caller.ClientName ?? caller.User.Username,
output.RenderId, cancellationToken);
}
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException or FolderMovedException)
{
return await uploads.ReceiveAgainAsync<RenderDto>(upload, staged, ex);
}
if (render is null)
{
UploadStore.TryDelete(staged);
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using System.Globalization;
using Microsoft.AspNetCore.Http.Features;
using Chronos.Core.Archiving;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Repositories;
@@ -303,6 +304,27 @@ public sealed class UploadService(
return null;
}
/// <summary>
/// A verified upload whose filing was refused before anything moved, for a reason that passes: its sequence held by
/// another writer past the lease wait (503 <c>sequence_busy</c>), the archive offline or read-only (503
/// <c>archive_offline</c>), or the sequence's folder not where the index has it until this index's next scan (503
/// <c>folder_moved</c>, <see cref="FolderMovedException"/>). The staged copy goes and the upload receives again with its
/// part file, so the client completes it again, as it does after any 503.
/// </summary>
public async Task<Outcome<T>> ReceiveAgainAsync<T>(Upload upload, string staged, Exception refusal)
{
ArgumentNullException.ThrowIfNull(upload);
logger.LogWarning("Upload {Upload} ({File}) not filed for now: {Reason}", upload.Id, upload.FileName, refusal.Message);
UploadStore.TryDelete(staged);
await db.Uploads.TryTransitionAsync(upload.Id, UploadState.Committing, UploadState.Receiving, cancellationToken: CancellationToken.None);
return Fail<T>(503, refusal switch
{
ArchiveOfflineException => "archive_offline",
FolderMovedException => "folder_moved",
_ => "sequence_busy",
});
}
private async Task FailAsync(Upload upload)
{
await db.Uploads.TryTransitionAsync(upload.Id, UploadState.Committing, UploadState.Failed, cancellationToken: CancellationToken.None);