Files
Febe/src/Febe.Core/Export/ExportModels.cs
T
Alby96andClaude Opus 5.5 b746aff45d E3: formati e fotogrammi nella copia verso le cartelle esterne
La richiesta di copia porta i formati («Copia in…» per foto e video, poi
la destinazione, poi le impostazioni), i fotogrammi dei video e la «Copia
di nuovo» di una sola copia. Il piano prevede convertiti, copiati com'è e
fotogrammi; il lavoro si ricorda di fotogrammi ed identità esatta per la
ripresa.

La copia converte prima dei controlli di spazio e di FAT32, adotta un file
già presente solo se lunghezza e SHA-256 della conversione coincidono, e
prende i fotogrammi di un video in un solo passaggio, ognuno con il suo
istante esatto come identità. Un file copiato in qualunque forma che non
sia un fotogramma è «già copiato»; un fotogramma non rende mai copiato il
file (nuovo segno FrameOnly). Le note sono un elenco di codici, con i testi
italiani nuovi e il rapporto che mostra i file copiati con una nota.

Le prove dell'archivio e dei piani delle query seguono le nuove ricerche;
due prove nuove coprono una foto convertita e un fotogramma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 23:08:38 +01:00

185 lines
8.2 KiB
C#

using Febe.Core.Domain;
using Febe.Core.Storage;
namespace Febe.Core.Export;
/// <summary>What a «Copia in…» is asked for (spec §4.10 «Manuale sempre»).</summary>
public abstract record ExportSelection
{
private ExportSelection()
{
}
/// <summary>Files by id: a selection of «Tutte le foto», a file of the viewer.</summary>
public sealed record Media(IReadOnlyList<long> MediaIds) : ExportSelection;
/// <summary>Entries by id: a grouped selection, an entry of the viewer.</summary>
public sealed record Entries(IReadOnlyList<long> EntryIds) : ExportSelection;
/// <summary>The current filter («Copia i file in…» of the CSV menu).</summary>
public sealed record Filter(LibraryFilter LibraryFilter, MosaicMode Mode) : ExportSelection;
/// <summary>Every file of an account (the account card).</summary>
public sealed record Account(long AccountId) : ExportSelection;
}
/// <summary>How the instants of «Fotogrammi» are chosen (spec §4.10 «Fotogrammi»).</summary>
public enum FrameMode
{
/// <summary>«Questo istante»: one frame at <see cref="ExportFramesRequest.At"/>.</summary>
At,
/// <summary>«Uno ogni k secondi»: at 0, k, 2k… before the end.</summary>
Every,
/// <summary>«N in tutto»: N frames spread over the video, each in the middle of its share.</summary>
Count,
}
/// <summary>A request of frames of videos, in a photo format (Jpg, Png or WebpLossless).</summary>
public sealed record ExportFramesRequest(FrameMode Mode, TimeSpan? At, TimeSpan? Every, int? Count, ExportFormat Format);
/// <summary>
/// The formats of «Copia in…» for this request only (tappa E3, D1): null keeps the destination's (or the general
/// settings'). A photo format or Original for photos; Mp4 or Original for videos.
/// </summary>
public sealed record ExportFormatChoice(ExportFormat? Photo, ExportFormat? Video);
/// <summary>«Copia di nuovo» of one copy row (tappa E3, D11): the form of that row, looked up only by its exact identity.</summary>
/// <param name="FrameAt">The instant of a frame row; null otherwise.</param>
public sealed record ExportCopyRequest(ExportVariant Variant, ExportFormat Format, TimeSpan? FrameAt);
/// <summary>A «Copia in…»: what to copy, whether «Tolti» and «Superati» are copied again (D9), who asked.</summary>
/// <param name="Formats">The formats of this request («Copia in…» → «Cambia»); null: those of the destination.</param>
/// <param name="Frames">Not null: a frames job («Fotogrammi…» → «Nella cartella delle copie»), videos only.</param>
/// <param name="Exact">«Copia di nuovo» of one copy row, only with a selection of one file.</param>
public sealed record ExportJobRequest(
ExportSelection Selection,
bool CopyAgain = false,
ExportRunOrigin Origin = ExportRunOrigin.Manual,
ExportFormatChoice? Formats = null,
ExportFramesRequest? Frames = null,
ExportCopyRequest? Exact = null);
/// <summary>
/// What a «Copia in…» would do (database only, decisions D3 and D9 of tappa E2). Each file goes to the effective
/// destination of its account (D5).
/// </summary>
/// <param name="Files">Files to write.</param>
/// <param name="Bytes">Their bytes.</param>
/// <param name="AlreadyCopied">Already in their destination (or, with «Una copia sola», copied for another account).</param>
/// <param name="RemovedOrSuperseded">
/// «Tolti o superati»: never copied again by themselves. With <see cref="ExportJobRequest.CopyAgain"/> they are also
/// counted in <paramref name="Files"/> and <paramref name="Bytes"/>, since they will be written.
/// </param>
/// <param name="NotExported">«Esporta questo account» off, no destination, or a content type the destination does not take.</param>
/// <param name="Missing">«File non presente in libreria».</param>
/// <param name="Destinations">Each destination that gets files, with whether it answers now.</param>
/// <param name="HasDestination">
/// A folder of the copies exists (the general one or one of an account, in use): when nothing is to copy, the dialog
/// says «no folder» only when this is false, not because no destination gets files.
/// </param>
public sealed record ExportPlan(
int Files,
long Bytes,
int AlreadyCopied,
int RemovedOrSuperseded,
int NotExported,
int Missing,
IReadOnlyList<ExportPlanDestination> Destinations,
bool HasDestination = true)
{
public static ExportPlan Empty { get; } = new(0, 0, 0, 0, 0, 0, []);
/// <summary>
/// Files predicted to be copied as they are, by kind («3 HEIC copiati come sono»): a prediction from the names
/// («circa»), the copy decides on the bytes (tappa E3).
/// </summary>
public IReadOnlyList<ExportPlanAsIs> AsIs { get; init; } = [];
/// <summary>Files predicted to be converted.</summary>
public int Converted { get; init; }
/// <summary>«Con perdita»: at least one file predicted converted to JPG, or JPG frames (D7 of tappa E3).</summary>
public bool Lossy { get; init; }
/// <summary>Frames job: the due videos.</summary>
public int Videos { get; init; }
/// <summary>Frames job: the photos of the selection, skipped («Le 4 foto si saltano»).</summary>
public int PhotosSkipped { get; init; }
/// <summary>Frames job: the frames to write (also in <see cref="Files"/>); «circa» for a video of unknown length.</summary>
public int Frames { get; init; }
/// <summary>Frames job: videos that would give more than <see cref="ExportFrames.MaxPerVideo"/> frames (the job is refused).</summary>
public int OverCap { get; init; }
}
/// <summary>Files of a plan copied as they are, of one kind («HEIC», «AVIF», «raw», «GIF», «WebM»).</summary>
public sealed record ExportPlanAsIs(string Label, int Files);
/// <summary>A destination of a plan.</summary>
/// <param name="Username">The account of an own folder; null for the general folder.</param>
/// <param name="Files">Files to write there.</param>
/// <param name="Paused">The destination is paused (its last check failed).</param>
/// <param name="Problem">Why it cannot be written now (not reachable, not mounted, paused), in Italian; null when fine.</param>
/// <param name="FreeBytes">Free space, when it can be measured.</param>
public sealed record ExportPlanDestination(
long DestinationId,
string Label,
string RootPath,
ExportScope Scope,
string? Username,
int Files,
long Bytes,
bool Paused,
string? Problem,
long? FreeBytes);
/// <summary>What the export job is doing.</summary>
public enum ExportPhase
{
Preparing,
/// <summary>«Controlla le copie».</summary>
Checking,
/// <summary>An engine session is running: copies wait for it to end (decision D11).</summary>
WaitingForSession,
Copying,
Finished,
}
/// <summary>Progress of the export job, for the progress card (polled, D20).</summary>
/// <param name="RunId">The job's run being worked on; null for «Controlla le copie» and when nothing ever ran.</param>
/// <param name="BytesTotal">Bytes of the files still pending when the run (re)started, plus those done since; 0 when unknown.</param>
public sealed record ExportProgress(
long? RunId,
ExportPhase Phase,
int FilesDone,
int FilesTotal,
long BytesDone,
long BytesTotal,
string? CurrentFile,
string? DestinationLabel,
IReadOnlyDictionary<ExportItemState, int> ByState,
DateTimeOffset UpdatedAt)
{
/// <summary>0..1: by bytes when known, otherwise by files.</summary>
public double Fraction => BytesTotal > 0
? Math.Clamp((double)BytesDone / BytesTotal, 0, 1)
: FilesTotal > 0 ? Math.Clamp((double)FilesDone / FilesTotal, 0, 1) : 0;
}
/// <summary>What <c>ExportService.StartAsync</c> did: one run per destination (D6), and the plan it followed.</summary>
public sealed record ExportStart(IReadOnlyList<ExportRun> Runs, ExportPlan Plan);
/// <summary>What «Riprova» of a paused destination did: the reason it is still paused (null: it answers), and the jobs resumed.</summary>
public sealed record ExportRetry(string? Problem, IReadOnlyList<ExportRun> Resumed);
/// <summary>The export job ended (however it ended): the runs it worked on, and whether copies may have changed.</summary>
public sealed record ExportJobFinished(IReadOnlyList<long> RunIds, bool CopiesChanged);