Files
Chronos/src/Chronos.Protocol/Library.cs
T
Alby96andClaude Opus 5.5 efa87f68ce
CI / Build and test (push) Failing after 3m1s
CI / PostgreSQL 16 integration (push) Skipped
CI / PostgreSQL 17 integration (push) Skipped
CI / Docker image (push) Skipped
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
Release / Build, test and publish (push) Successful in 15m31s
Release / Server image (push) Successful in 1m13s
feat: owner review 2 phase 4b: mass conversion after import (#13)
Convert photos already in the archive to JPEG, TIFF-16 or Linear DNG, from the panel's Library and the desktop's Archive and Library. Each run asks Replace (same frames, originals to the trash, recoverable) or New sequence. A dry run lists what converts, what is skipped and why, size before and after, and free space; the job converts exactly the confirmed photos, resumes, and commits all or nothing per sequence. A conversion never changes what Chronos reads from a photo. Replaced originals are erased only on the archive's own word that their conversion is gone. Desktop TIFFs that WIC showed black or as noise now go to the managed reader; the Edit picker no longer spins a core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-03 10:41:50 +01:00

184 lines
14 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Chronos.Protocol;
/// <summary>
/// <c>POST /api/v1/sequences/{id}/frames/delete</c> (owner review 2, R6): the photos to move into the archive's trash.
/// <see cref="ExpectedFramesVersion"/> is the frames version the ids were read at: a sequence whose frames changed since
/// answers 409 <c>frames_conflict</c>. <see cref="DryRun"/> only reports what would happen.
/// </summary>
public sealed record FrameDeleteRequest(IReadOnlyList<Guid> FrameIds, int? ExpectedFramesVersion, bool DryRun);
/// <summary>
/// What a photo deletion does (dry run) or did: the photos and bytes that go, the sequence's frames version (as it is on a
/// dry run, after the deletion otherwise) and the trash entry made (null on a dry run).
/// </summary>
public sealed record FrameDeleteResultDto(Guid SequenceId, int Photos, long Bytes, int FramesVersion, int FrameCount, string? TrashEntry, bool DryRun);
/// <summary>
/// An entry of the archive's trash (<c>GET /api/v1/archive/trash</c>): a deleted sequence (<see cref="Kind"/> <c>sequence</c>)
/// or photos deleted from one (<c>photos</c>; <c>replaced</c> for originals a conversion replaced). <see cref="Name"/>
/// identifies it in restore and empty requests. In the dry run of an emptying, <see cref="ConversionDeleted"/> marks
/// replaced originals whose conversion was deleted since, which may be the last copy of their photos.
/// </summary>
public sealed record TrashEntryDto(string Name, string Kind, Guid SequenceId, string Title, string Folder, int Photos, int Files, long Bytes,
string? DeletedBy, DateTimeOffset DeletedAt, bool ConversionDeleted = false);
/// <summary><c>GET /api/v1/archive/trash</c>: the entries, newest first, and their total size.</summary>
public sealed record TrashListDto(IReadOnlyList<TrashEntryDto> Entries, long Bytes);
/// <summary>
/// <c>POST /api/v1/archive/trash/{name}/restore</c>: the sequence the entry went back into (a new one when the photos'
/// sequence is gone: <see cref="NewSequence"/>), how many photos came back, and the photos kept in the trash: their names
/// (<see cref="Kept"/>), why each stayed (<see cref="KeptReasons"/>, in the same order: <c>mismatch</c>, its files no
/// longer match their record; <c>not_moved</c>, they could not be moved back; <c>in_sequence</c>, the sequence holds it
/// already; <c>no_file</c>, its original was missing when it was deleted) and one sentence per reason in the request's
/// language (<see cref="Message"/>; null when none stayed).
/// </summary>
public sealed record TrashRestoreDto(string Name, string Kind, Guid SequenceId, int Photos, IReadOnlyList<string> Kept, bool NewSequence,
IReadOnlyList<string>? KeptReasons = null, string? Message = null);
/// <summary>
/// <c>POST /api/v1/archive/trash/empty</c>: erase the entries <see cref="Names"/> (null: every entry). A dry run answers the
/// plan with its <see cref="TrashEmptyPlanDto.Fingerprint"/>; the erase itself must send that fingerprint back (409
/// <c>trash_changed</c> when the trash changed since) and runs as an <c>empty-trash</c> job (202).
/// </summary>
public sealed record TrashEmptyRequest(IReadOnlyList<string>? Names, bool DryRun, string? Fingerprint);
/// <summary>The dry run of emptying the trash: the entries measured on disk, their totals, the fingerprint, and names not in the trash.</summary>
public sealed record TrashEmptyPlanDto(IReadOnlyList<TrashEntryDto> Entries, int Photos, int Files, long Bytes, string Fingerprint, IReadOnlyList<string> Unknown);
/// <summary><c>POST /api/v1/sequences/bulk/delete</c>: move these sequences into the trash (or, with <see cref="DryRun"/>, say what would).</summary>
public sealed record BulkDeleteRequest(IReadOnlyList<Guid> Ids, bool DryRun);
/// <summary><c>POST /api/v1/sequences/bulk/retag</c>: add and remove tags on these sequences (the same edit as a PATCH of their tags).</summary>
public sealed record BulkRetagRequest(IReadOnlyList<Guid> Ids, IReadOnlyList<string>? Add, IReadOnlyList<string>? Remove);
/// <summary>
/// <c>POST /api/v1/sequences/bulk/jobs</c>: queue one job of <see cref="Kind"/> (<c>analyse</c>, <c>deep</c>, <c>proxies</c>,
/// <c>thumbnails</c>, <c>verify</c>) over these sequences.
/// </summary>
public sealed record BulkJobsRequest(IReadOnlyList<Guid> Ids, string Kind);
/// <summary>
/// One sequence of a bulk operation: <see cref="Outcome"/> <c>ok</c>, or <c>skipped</c> with the error code that says why
/// (<see cref="Reason"/>, e.g. <c>not_found</c>, <c>forbidden</c>, <c>sequence_busy</c>) and its localised sentence.
/// </summary>
/// <param name="TrashFolder">For a delete: where the folder goes (or went) in the trash; null when it has no folder.</param>
public sealed record BulkItemResult(Guid Id, string Outcome, string? Reason = null, string? Message = null, string? TrashFolder = null);
/// <summary>
/// The result of a bulk operation: one item per id asked for, the counts, the photos and bytes a delete moves (or moved),
/// and the job a bulk job request queued (null when nothing was queued).
/// </summary>
public sealed record BulkResultDto(IReadOnlyList<BulkItemResult> Items, int Ok, int Skipped, bool DryRun, int Photos = 0, long Bytes = 0, JobDto? Job = null);
/// <summary>
/// A value a Library filter offers: <see cref="Value"/> as <c>GET /api/v1/sequences</c> takes it (<c>year</c>, <c>camera</c>,
/// <c>tag</c>), the sequences that have it, and the label a menu shows when it differs (a camera model with its make).
/// </summary>
public sealed record FacetDto(string Value, int Sequences, string? Label = null);
/// <summary>
/// <c>GET /api/v1/sequences/facets</c> (owner review 2, R6): the years of first capture (newest first), camera models (most
/// 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 server
/// keeps it a few minutes, a refusal too, so the same dry run again (also after one cut off) is answered from it; 503
/// <c>plan_dropped</c> when the server stopped making it (it took too long, or too many were asked at once). The change
/// itself sends that plan's <see cref="Fingerprint"/> back and runs as a <c>move</c> job (202): 409 <c>plan_changed</c>
/// when the index changed since in what the plan reads (the sequences' rows, and which of their photos are hashed, as a
/// verify does); a change made on disk alone, which the index does not have yet, is found by the job, which then fails and
/// changes nothing.
/// </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>
/// Why part of a sequence stays as it is in a Reorganize, as one localised sentence: photos that keep their names,
/// <see cref="Reason"/> <c>in_place</c> (kept in place outside <c>originals/</c>), <c>unhashed</c> (never verified) or
/// <c>missing</c>, with how many; or <c>unreadable</c> (0 photos): the sequence's sidecar cannot be read, so the sequence
/// keeps its folder, title and names, and so does every folder it is inside.
/// </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 what stays
/// as it is (<see cref="Blocked"/>). A step that changes nothing lists only that.
/// </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 (those that change nothing list only what stays as it is), the sequences that
/// change (carried ones included), the photos renamed, the photos that keep their names (a sequence that stays as it is
/// whole, <c>unreadable</c>, counts none), and the fingerprint the change sends back.
/// </summary>
public sealed record ReorganizePlanDto(IReadOnlyList<ReorganizeStepDto> Steps, int Sequences, int Files, int Kept, string Fingerprint);
/// <summary>
/// <c>POST /api/v1/archive/convert</c> (owner review 2, R7; administrators of the archive): the photos of
/// <see cref="SequenceIds"/>, or of every sequence with <see cref="All"/> (exactly one of the two), converted to
/// <see cref="Target"/> (<c>jpeg</c>, <c>tiff16</c> or <c>linear-dng</c>, the archival choice) with <see cref="Quality"/> 1–100
/// for a JPEG (default 95, ignored otherwise). <see cref="Mode"/>, chosen at every run: <c>replace</c> (the converted files
/// become the frames, the originals go to the archive's trash) or <c>new-sequence</c> (copies in a new sequence, the source
/// untouched, the photos it leaves as they are not copied into it). <see cref="DryRun"/> answers the plan
/// (<see cref="ConvertPlanDto"/>) and changes nothing; the server keeps it a few minutes, a refusal too, so the same dry run
/// again (also after one cut off, in either mode, at any quality of a lossless target) is answered from it with the busy
/// sequences and the free space as they are then; 503 <c>plan_dropped</c> when the server stopped making it (it took too
/// long, or too many were asked at once). The change itself sends that plan's <see cref="Fingerprint"/> back and takes the
/// plan kept (503 <c>plan_dropped</c> when none is kept for the index as it is now, let go since or the index changed in
/// what the plan reads, the sequences' rows and the formats, sizes, hashes and flags of their photos: ask the dry run
/// again, then confirm that one; 409 <c>plan_changed</c> when the plan kept is not the one confirmed: a job made one of its
/// sequences busy or free since, or a conversion of them was queued) and runs as a <c>convert</c> job (202), which
/// converts the photos of that plan alone and leaves as it is a sequence where one of them no longer fits.
/// </summary>
public sealed record ConvertRequest(IReadOnlyList<Guid>? SequenceIds, bool All, string? Target, int? Quality, string? Mode, bool DryRun,
string? Fingerprint = null);
/// <summary>
/// Photos of a sequence a conversion leaves as they are: <see cref="Reason"/> <c>same_format</c>, <c>convert_on_pc</c> (the
/// server cannot read them at full resolution: a CR3, a HEIC, a body its RAW decoder does not support), <c>undecodable</c>,
/// <c>missing</c>, <c>unhashed</c> (never verified), <c>eight_bit</c> (a RAW the host develops at 8 bits only, for a 16-bit
/// target), <c>color_profile</c> (a colour profile the target can neither keep nor convert to), <c>too_large</c> or
/// <c>inaccessible</c> (another program held the file open, or it could not be opened, when the plan was made), how many,
/// and the reason as one localised sentence: of a sequence <c>new-sequence</c> copies, that the new sequence lacks them (it
/// holds the converted copies alone).
/// </summary>
public sealed record ConvertSkippedDto(string Reason, int Photos, string Message);
/// <summary>Why a whole sequence is not converted now: <see cref="Reason"/> <c>busy</c>, <c>offline</c>, <c>unreadable</c> or <c>frames_changed</c>, as one localised sentence too.</summary>
public sealed record ConvertBlockedDto(string Reason, string Message);
/// <summary>
/// One sequence of a conversion plan: its title, folder and the frames version it was planned at, the photos converted
/// with their size now and the estimated size after, the photos left as they are and why, and what blocks the sequence
/// (it is then not converted).
/// </summary>
public sealed record ConvertSequenceDto(Guid SequenceId, string Title, string Folder, int FramesVersion, int Photos, long BytesBefore, long BytesAfter,
IReadOnlyList<ConvertSkippedDto> Skipped, IReadOnlyList<ConvertBlockedDto> Blocked);
/// <summary>
/// The space a conversion needs on the archive's volume (the estimate × 1.15 plus a 512 MiB reserve; with <c>replace</c> the
/// originals stay in the trash, so it adds up), what is free there (null when it cannot be measured), whether it is
/// enough, and the line the dialog shows.
/// </summary>
public sealed record ConvertSpaceDto(long Required, long? Free, bool Enough, string Message);
/// <summary>
/// The dry run of a conversion: the target, quality and mode, each sequence asked for in order (<see cref="Steps"/>), the
/// sequences and photos converted, the photos skipped, the bytes before and the estimate after, the space, and the
/// fingerprint the change sends back.
/// </summary>
public sealed record ConvertPlanDto(string Target, int Quality, string Mode, IReadOnlyList<ConvertSequenceDto> Steps, int Sequences, int Photos, int Skipped,
long BytesBefore, long BytesAfter, ConvertSpaceDto Space, string Fingerprint);