feat(archive): reorganize existing sequences with folder, file and title templates

Owner review 2, R7 asks for renaming and moving after import, on the web panel and the
desktop. This is the engine and the server API both UIs build on.

- FrameNaming (Core/Naming) is the one naming context and unique-name rule of a frame:
  imports, uploads and Reorganize now produce identical names (behaviour of the ingest and
  the import planner unchanged).
- RenamePlanner takes a file template: each step counts its renamed frames, shows the first
  three and the frames version they were planned at, and lists what keeps its name (photos
  in place outside originals/, never hashed, missing, unreadable sidecar). Names are given
  in index order with _2, _3 as filing does; XMP companions follow their photo.
- MassRenamer renames a step's files under the same leases after its folder moved, checks
  the frames version, journals .chronos/rename-files.json and moves files in two phases
  through temporary names so chains and swaps never meet; then sidecar, index
  (FrameRepository.RenameFilesAsync, both dialects) and journal. A failure puts every file
  back; a crash is completed by the next writer or the plan's resume, the index following.
  Plans a paused or cancelled job holds are left to that job.
- JobKind.Move gets MoveJobHandler: it plans again and applies only the confirmed plan
  (fingerprint and frames versions), with progress and checkpoints per sequence.
- POST /api/v1/archive/reorganize: dry run with the plan and its fingerprint, otherwise a
  202 move job; validated templates, audited, sequenceChanged reorganized events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit aae1c3eb18ea932b4a6251c5e2a282b9295a5785)
This commit is contained in:
Alby96 committed 2026-10-27 14:03:36 +01:00
1 parent 81cf58227d
commit eb2395d9b0
36 files changed
+2238 -164

No files matched your search

+36
View File
@@ -81,3 +81,39 @@ public sealed record FacetDto(string Value, int Sequences, string? Label = null)
/// sequences first) and tags in use (by name) of the archive's sequences, for the admin panel's Library filters.
/// </summary>
public sealed record LibraryFacetsDto(IReadOnlyList<FacetDto> Years, IReadOnlyList<FacetDto> Cameras, IReadOnlyList<FacetDto> Tags);
/// <summary>
/// <c>POST /api/v1/archive/reorganize</c> (owner review 2, R7; administrators of the archive): new folder, file and title
/// templates applied to sequences already in the archive, <see cref="SequenceIds"/> or every one with <see cref="All"/>
/// (exactly one of the two). A null template keeps that part; at least one is given, each valid as the archive settings'
/// templates are. <see cref="DryRun"/> answers the plan (<see cref="ReorganizePlanDto"/>) and changes nothing; the change
/// itself sends that plan's <see cref="Fingerprint"/> back (409 <c>plan_changed</c> when the archive changed since) and runs
/// as a <c>move</c> job (202).
/// </summary>
public sealed record ReorganizeRequest(IReadOnlyList<Guid>? SequenceIds, bool All, string? FolderTemplate, string? FileTemplate, string? TitleTemplate,
bool DryRun, string? Fingerprint = null);
/// <summary>A file a Reorganize renames: its name before and after, relative to the sequence folder (<c>originals/…</c>).</summary>
public sealed record ReorganizeFileDto(string From, string To);
/// <summary>
/// Photos of a sequence that keep their names in a Reorganize: <see cref="Reason"/> <c>in_place</c> (kept in place outside
/// <c>originals/</c>), <c>unhashed</c> (never verified), <c>missing</c> or <c>unreadable</c> (the sequence's sidecar), how many
/// (0 for <c>unreadable</c>), and the reason as one localised sentence.
/// </summary>
public sealed record ReorganizeBlockedDto(string Reason, int Photos, string Message);
/// <summary>
/// One sequence of a Reorganize plan, in the order the steps apply: its folder and title before and after,
/// <see cref="Carried"/> when it only moves with a folder it is inside, the frames version its file names were planned at
/// (0 when none changes), how many photos get a new name with the first of them (<see cref="FileSamples"/>), and the photos
/// that keep their names. A step that changes nothing lists only those.
/// </summary>
public sealed record ReorganizeStepDto(Guid SequenceId, string FromFolder, string ToFolder, string? FromTitle, string? ToTitle, bool Carried,
int FramesVersion, int FileChanges, IReadOnlyList<ReorganizeFileDto> FileSamples, IReadOnlyList<ReorganizeBlockedDto> Blocked);
/// <summary>
/// The dry run of a Reorganize: its steps, the sequences that change (carried ones included), the photos renamed, the photos
/// that keep their names, and the fingerprint the change sends back.
/// </summary>
public sealed record ReorganizePlanDto(IReadOnlyList<ReorganizeStepDto> Steps, int Sequences, int Files, int Kept, string Fingerprint);
+2
View File
@@ -87,4 +87,6 @@ namespace Chronos.Protocol;
[JsonSerializable(typeof(BulkItemResult))]
[JsonSerializable(typeof(BulkResultDto))]
[JsonSerializable(typeof(LibraryFacetsDto))]
[JsonSerializable(typeof(ReorganizeRequest))]
[JsonSerializable(typeof(ReorganizePlanDto))]
public sealed partial class ProtocolJson : JsonSerializerContext;