Files
Febe/src/Febe.Web/Api/ExportDtos.cs
T
Alby96andClaude Opus 5.5 958cb71cd6 E3: correzioni della revisione di formati e fotogrammi
Le 16 osservazioni confermate della revisione, ognuna con la sua prova:

- JPEG: il controllo stima la memoria di lavoro del decodificatore
  (progressivo), così un file che non si decodifica esce «troppo
  grande» e non «illeggibile».
- Un EXIF che non si tiene lascia un EXIF minimo con l'orientamento,
  perché la foto convertita non esca girata.
- Fotogrammi: istanti in millisecondi interi; la copia trova l'indice
  del nome dall'istante, non dall'ordine delle righe.
- Video di durata sconosciuta misurati prima di registrare: contano
  nei limiti di 500 per richiesta e 5000 per video.
- Rimuxaggio: la durata del segmento di elst passa nell'MP4, la fine
  tagliata resta nascosta (anche nei fotogrammi).
- H.264: il punto di recupero vale come IDR solo con exact_match_flag.
- MP3 in MP4: objectTypeIndication 0x69 fino a 24 kHz, 0x6B oltre.
- Conversione della libreria: il lavoro toglie le righe di un formato
  spento o cambiato; spegnere toglie anche i «Non riuscito»; «Riprova»
  solo i formati di adesso; pausa per spazio prima di rileggere
  l'originale.
- «Anche i N» conta e mette in coda solo il tipo che si cambia; le
  impostazioni dell'esportazione si salvano una per volta.
- Eliminazione e «Tieni il più grande» scelgono i convertiti nella
  stessa transazione: nessun convertito orfano.
- Un file arrivato tardi in un elemento vecchio mette in coda solo sé
  (file nuovo = salvato da quando il formato è scelto).
- Zip dei fotogrammi a pezzi di 64 KB: un browser lento che legge non
  si interrompe, uno fermo sì.

Decisioni in docs/decisioni.md (28/11), §4.10 della specifica precisato.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 13:30:33 +01:00

359 lines
18 KiB
C#

namespace Febe.Web.Api;
// JSON shapes of the copies to external folders (spec §4.10, tappa E2). Same conventions as Dtos.cs: English camelCase
// names, Italian texts, times as LocalTimeDto. Names of states and types on the wire:
// scope «general»|«account»; types «postFoto», «postVideo», «storie», «evidenza», «taggati», «profilo»;
// copy states «copied», «removed», «superseded», «failed»; job states «running», «interrupted», «paused», «completed»,
// «cancelled»; file states «pending», «copied», «adopted», «alreadyCopied», «skipped», «missing», «failed».
/// <summary>
/// Where copies can go. <paramref name="Docker"/>: destinations are subfolders of <paramref name="Root"/> (the page
/// lists them); otherwise any folder, with the native picker when <paramref name="PickFolder"/>.
/// <paramref name="Active"/> false: nothing can be written, <paramref name="Problem"/> says why.
/// </summary>
public sealed record ExportRootDto(bool Docker, bool Active, string? Root, string? Problem, bool PickFolder);
/// <summary>The library's naming schemes, to prefill «Uno schema suo», and the placeholders.</summary>
public sealed record ExportSchemesDto(string General, string Highlight, string Profile, IReadOnlyList<string> Placeholders);
/// <summary>
/// A destination. <paramref name="Display"/> is the folder as shown («/esporta/usb» in Docker). <paramref name="Types"/>
/// are the wire names of the content types; null schemes are «Come la libreria». <paramref name="Problem"/>: the reason
/// of its pause (or, with <c>/status</c>, why it does not answer now). <paramref name="Counts"/>: copies per state
/// (<c>copied</c>, <c>removed</c>, <c>superseded</c>, <c>failed</c>). <paramref name="Reachable"/> and
/// <paramref name="FreeBytes"/> only from <c>/status</c>. <paramref name="Orphan"/>: an own folder whose account was
/// removed («era di @<paramref name="FormerUsername"/>»).
/// </summary>
public sealed record ExportDestinationDto(
long Id,
string Scope,
long? AccountId,
string? Username,
string Label,
string RootPath,
string Display,
IReadOnlyList<string> Types,
string? NamingScheme,
string? HighlightNamingScheme,
string? ProfileNamingScheme,
bool Automatic,
LocalTimeDto? PausedAt,
string? Problem,
IReadOnlyDictionary<string, int> Counts,
bool? Reachable = null,
long? FreeBytes = null,
bool Orphan = false,
string? FormerUsername = null,
string? PhotoFormat = null,
string? VideoFormat = null);
/// <summary>
/// <c>GET /api/export</c>: Impostazioni → Esportazione and the notice of the Dashboard. <paramref name="SamePost"/>:
/// <c>onePerAccount</c> or <c>oneOnly</c>. <paramref name="UnfinishedRuns"/>: interrupted or paused jobs («Riprendi»).
/// Formats (tappa E3) on the wire: <c>original</c>, <c>jpg</c>, <c>png</c>, <c>webplossless</c>, <c>mp4</c>; the
/// library ones are <c>original</c> while the conversion of the library is off. <paramref name="LibraryConversion"/>:
/// the state of that conversion.
/// </summary>
public sealed record ExportOverviewDto(
ExportRootDto Root,
string SamePost,
ExportDestinationDto? General,
IReadOnlyList<ExportDestinationDto> Own,
IReadOnlyList<long> ActiveRunIds,
int UnfinishedRuns,
ExportSchemesDto Library,
string PhotoFormat = "original",
string VideoFormat = "original",
string LibraryPhotoFormat = "original",
string LibraryVideoFormat = "original",
LibraryConversionDto? LibraryConversion = null);
/// <summary>
/// The conversion of the library (tappa E3, spec §4.10): files in the queue, converted, failed («Riprova»), that never
/// convert (<paramref name="AsIs"/>: «non si convertono»), «In pausa», and why it waits (Italian, null when it does
/// not): an import, a copy or a rebuild at work, an engine session, low space. <paramref name="Text"/>: the status line
/// («In coda 12 · convertiti 340 · non riusciti 2 · non si convertono 3»). <paramref name="On"/>: a library format is
/// chosen.
/// </summary>
public sealed record LibraryConversionDto(int Pending, int Converted, int Failed, int AsIs, bool Paused, string? Waiting, string Text, bool On);
/// <summary>
/// <c>PUT /api/export/settings</c>, every field optional (null keeps it): «Lo stesso post in due account»
/// (<c>onePerAccount</c> or <c>oneOnly</c>), the formats of the copies and of the library (wire names).
/// <paramref name="ConvertExisting"/>: the answer «Anche i N già in libreria» when a library format is turned on or
/// changed; it queues the files of the kinds whose library format this request changes, never those of the other.
/// </summary>
public sealed record ExportSettingsRequest(
string? SamePost = null,
string? PhotoFormat = null,
string? VideoFormat = null,
string? LibraryPhotoFormat = null,
string? LibraryVideoFormat = null,
bool? ConvertExisting = null);
/// <summary>What <c>PUT /api/export/settings</c> did: a message, the overview after the change, the files queued.</summary>
public sealed record ExportSettingsSavedDto(string Message, ExportOverviewDto Overview, int Queued = 0);
/// <summary>
/// «Converti anche i N file già in libreria?»: <paramref name="Files"/> that would enter the queue, the bytes of their
/// originals («circa») and the line of the question («gli originali occupano circa 3,1 GB; i convertiti possono occupare
/// di più»).
/// </summary>
public sealed record LibraryConversionPreviewDto(int Files, long Bytes, string Text);
/// <summary>Docker: the subfolders of a folder of <c>/esporta</c>. <paramref name="Relative"/> is "" for the root.</summary>
public sealed record ExportFolderListDto(string Relative, string? Parent, string Display, IReadOnlyList<SourceFolderDto> Folders);
/// <summary><c>POST /api/export/pick-folder</c>: the destination being changed, to open the picker on its folder.</summary>
public sealed record ExportPickRequest(long? DestinationId);
/// <summary>The check of a candidate folder (before saving). <paramref name="Fat32"/>: files over 4 GB cannot go there.</summary>
public sealed record ExportFolderCheckDto(bool Accepted, string FullPath, string Display, string? Problem, long? FreeBytes, bool Fat32);
/// <summary>The «Risultato» of a destination's naming. <paramref name="Scope"/>: general or account; null schemes are the library's.</summary>
public sealed record ExportNamingPreviewRequest(string Scope, string? General, string? Highlight, string? Profile);
/// <summary>
/// A destination to add or change. <paramref name="Path"/>: in Docker the folder relative to <c>/esporta</c> (as listed),
/// elsewhere the full path. <paramref name="Types"/>: wire names, at least one. Null or empty schemes: «Come la
/// libreria». «Automatica» is stored only (tappa E5 acts on it).
/// </summary>
public sealed record ExportDestinationRequest(
string Scope,
long? AccountId,
string Path,
string? Label,
IReadOnlyList<string> Types,
string? NamingScheme,
string? HighlightNamingScheme,
string? ProfileNamingScheme,
bool Automatic = false,
bool OnlyNew = true,
string? PhotoFormat = null,
string? VideoFormat = null);
/// <summary>A saved destination (a change of folder gives a new id) and the warnings of its schemes.</summary>
public sealed record ExportDestinationSavedDto(ExportDestinationDto Destination, IReadOnlyList<string> Warnings);
/// <summary>
/// What a «Copia in…» copies: exactly one of <paramref name="MediaIds"/> (files of «Tutte le foto» or the viewer),
/// <paramref name="EntryIds"/> (a grouped selection), <paramref name="Query"/> (the filter of the Libreria, as its query
/// string, with <paramref name="Mode"/> <c>grouped</c> or <c>files</c>) or <paramref name="AccountId"/> (every file of
/// the account). <paramref name="CopyAgain"/>: «Copia di nuovo anche i tolti o superati». Tappa E3:
/// <paramref name="PhotoFormat"/>/<paramref name="VideoFormat"/> override the destination's for this request only
/// (null: as the destination); <paramref name="Frames"/> makes it a frames job («Fotogrammi…» → «Nella cartella delle
/// copie»), without formats.
/// </summary>
public sealed record CopyJobRequestDto(
IReadOnlyList<long>? MediaIds,
IReadOnlyList<long>? EntryIds,
string? Query,
string? Mode,
long? AccountId,
bool CopyAgain = false,
string? PhotoFormat = null,
string? VideoFormat = null,
FramesRequestDto? Frames = null);
/// <summary>
/// Which frames (spec §4.10 «Fotogrammi»): <paramref name="Mode"/> <c>istante</c> (at <paramref name="AtMs"/>),
/// <c>ogni</c> (every <paramref name="EveryMs"/>, at least 100) or <c>numero</c> (<paramref name="Count"/> in all, 1 to
/// 1.000); <paramref name="Format"/> <c>jpg</c>, <c>png</c> (the default) or <c>webplossless</c>.
/// </summary>
public sealed record FramesRequestDto(string? Mode, long? AtMs = null, long? EveryMs = null, int? Count = null, string? Format = null);
/// <summary>Files of a plan copied as they are, of one kind («3 HEIC copiati come sono»).</summary>
public sealed record ExportPlanAsIsDto(string Label, int Files);
/// <summary>A destination of a plan. <paramref name="Problem"/>: why it cannot be written now (paused, not reachable).</summary>
public sealed record ExportPlanDestinationDto(
long Id,
string Label,
string Display,
string Scope,
string? Username,
int Files,
long Bytes,
bool Paused,
string? Problem,
long? FreeBytes);
/// <summary>
/// The summary of «Copia in…» (spec §10.3). <paramref name="Files"/>/<paramref name="Bytes"/>: what will be written
/// (with «Copia di nuovo» the tolti/superati too). <paramref name="NotExported"/>: of accounts that are not exported
/// (switch off, no destination, type not taken). <paramref name="Missing"/>: not in the library. Tappa E3:
/// <paramref name="AsIs"/> files predicted copied as they are («circa»), <paramref name="Converted"/> predicted
/// converted, <paramref name="Lossy"/> «con perdita»; a frames job: <paramref name="Videos"/>,
/// <paramref name="PhotosSkipped"/>, <paramref name="Frames"/> and <paramref name="OverCap"/> (videos over 1.000
/// frames: the job is refused). <paramref name="Summary"/>: the line of the dialog («312 file · 41 già copiati, saltati ·
/// circa 3 HEIC copiati come sono · circa 4,2 GB · con perdita»).
/// </summary>
public sealed record ExportPlanDto(
int Files,
long Bytes,
int AlreadyCopied,
int RemovedOrSuperseded,
int NotExported,
int Missing,
IReadOnlyList<ExportPlanDestinationDto> Destinations,
bool HasDestination = true,
IReadOnlyList<ExportPlanAsIsDto>? AsIs = null,
int Converted = 0,
bool Lossy = false,
int Videos = 0,
int PhotosSkipped = 0,
int Frames = 0,
int OverCap = 0,
string? Summary = null);
/// <summary>The jobs a «Copia in…» started, one per destination (empty: nothing to copy), and the plan it followed.</summary>
public sealed record ExportJobDto(IReadOnlyList<long> RunIds, ExportPlanDto Plan, string Message);
/// <summary>«Copia di nuovo» of a copy «Tolto» or «Superato» (the viewer).</summary>
public sealed record CopyAgainRequest(long CopyId);
/// <summary>
/// <c>GET /api/export/progress</c>, polled by the Dashboard tab. <paramref name="Phase"/>: preparing, checking,
/// waitingForSession, copying, finished. <paramref name="ByState"/>: files of the job per state.
/// </summary>
public sealed record ExportProgressDto(
long? RunId,
string Phase,
double Fraction,
int FilesDone,
int FilesTotal,
long BytesDone,
long BytesTotal,
string? CurrentFile,
string? Destination,
IReadOnlyDictionary<string, int> ByState,
bool Running,
string? Error);
/// <summary>An export job. <paramref name="Kind"/>: copy or recognize; <paramref name="Origin"/>: manual or automatic.</summary>
public sealed record ExportRunDto(
long Id,
long DestinationId,
string Destination,
string Kind,
string Origin,
string State,
LocalTimeDto StartedAt,
LocalTimeDto? CompletedAt,
string? Error,
int Total,
int Done,
bool Running = false);
/// <summary>
/// The files of one account in a job (<paramref name="Copied"/> counts written and adopted files).
/// <paramref name="AsIs"/>: files copied as they are, by kind («HEIC» → 3).
/// </summary>
public sealed record ExportReportAccountDto(long? AccountId, string Username, int Copied, int AlreadyCopied, int Skipped, int Failed, IReadOnlyDictionary<string, int>? AsIs = null);
/// <summary>A file of the report that needs a look, with its reason in Italian.</summary>
public sealed record ExportReportLineDto(long ItemId, string Username, string? Path, string State, string Text);
/// <summary>
/// The report of a job (at most 200 problems). <paramref name="Notes"/> (tappa E3): files copied or adopted with a note
/// (what a conversion could not keep, a file copied as it is), at most 200.
/// </summary>
public sealed record ExportReportDto(
ExportRunDto Run,
IReadOnlyDictionary<string, int> ByState,
long BytesCopied,
IReadOnlyList<ExportReportAccountDto> Accounts,
IReadOnlyList<ExportReportLineDto> Problems,
IReadOnlyList<ExportReportLineDto>? Notes = null);
/// <summary>
/// A copy of a file of the viewer (spec §4.6, §4.10). <paramref name="State"/>: copied, removed, superseded, failed;
/// <paramref name="Variant"/>: whole, converted or frame; <paramref name="Format"/>: the wire name of a converted copy or
/// of a frame (null for a whole one); <paramref name="FrameAtMs"/> and <paramref name="FrameLabel"/> («0:01,25») for a
/// frame. <paramref name="ForAccount"/>: with «Una copia sola», the account it was copied for when it is another one.
/// <paramref name="CanCopyAgain"/>: «Copia di nuovo» of that same form. <paramref name="Notes"/>: why it failed.
/// </summary>
public sealed record MediaCopyDto(
long CopyId,
string Destination,
bool DestinationRetired,
string State,
string Variant,
string? Format,
long? FrameAtMs,
LocalTimeDto At,
string? ForAccount,
bool CanCopyAgain,
string? FrameLabel = null,
string? Notes = null);
/// <summary>
/// A converted file of the library next to its original (tappa E3, spec §4.10): <paramref name="Format"/> (wire name),
/// <paramref name="State"/> <c>pending</c>, <c>converted</c>, <c>failed</c>, <c>asIs</c> («non si converte»),
/// <c>superseded</c> or <c>removed</c>, its size, and <paramref name="Notes"/>: what was not kept, or why it failed or
/// does not convert. <paramref name="Available"/>: the file is on disk («Scarica», «Mostra nella cartella»).
/// </summary>
public sealed record MediaConversionDto(long Id, string Format, string State, long? Bytes, string? Notes, bool Available, string? FileName);
/// <summary>
/// «Copie esterne» of the account card. <paramref name="Destination"/>: the effective one (its own folder, else the
/// general folder), null when there is none. Counts are of due files (decision D3 of tappa E2): with the switch off
/// they are zero.
/// </summary>
public sealed record ExportAccountDto(
bool Enabled,
bool HasOwnFolder,
ExportDestinationDto? Destination,
int Due,
int NotCopied,
int RemovedOrSuperseded,
int Failed);
// ---------------------------------------------------------------------------------------------- frames (tappa E3)
/// <summary>
/// <c>GET /api/media/{id}/frames/info</c>: whether frames can be taken from the video (<paramref name="Unavailable"/>:
/// «Fotogramma non disponibile per questo video»), its length and its size as shown (rotation applied).
/// </summary>
public sealed record FrameInfoDto(bool Available, string? Unavailable, long DurationMs, int Width, int Height, bool HasAudio);
/// <summary>
/// One instant of a frames request: the one asked for, the one really shown (the frame's identity, ms rounded up), its
/// label («0:01,25») and the suffix of its file name (<c>_t0m01s250</c>, <c>_f001</c>).
/// </summary>
public sealed record FrameInstantDto(int Index, long RequestedMs, long ActualMs, string Label, string Suffix);
/// <summary>
/// <c>GET /api/media/{id}/frames/instants</c>: the instants of a mode for one video (at most 1.000). <paramref name="Total"/>:
/// how many it asks; <paramref name="Problem"/>: why none is given (over 1.000, not available).
/// </summary>
public sealed record FrameInstantsDto(long DurationMs, int Total, bool OverCap, string? Problem, IReadOnlyList<FrameInstantDto> Instants);
/// <summary>
/// The frames of a selection («Fotogrammi…» from the selection bars): exactly one of <paramref name="MediaIds"/>,
/// <paramref name="EntryIds"/> (every video of those entries) or <paramref name="Query"/> with <paramref name="Mode"/>,
/// and which frames.
/// </summary>
public sealed record FramesSelectionRequest(IReadOnlyList<long>? MediaIds, IReadOnlyList<long>? EntryIds, string? Query, string? Mode, FramesRequestDto? Frames);
/// <summary>
/// <c>POST /api/frames/plan</c>: what «Scarica» would give. <paramref name="NotAvailable"/>: videos without frames (or
/// not on disk); <paramref name="OverCap"/>: videos over 1.000 frames; <paramref name="TooManyToDownload"/>: more than
/// 500 frames («Nella cartella delle copie»); <paramref name="NeedsQuiet"/>: more than 20 (only outside engine sessions
/// and other long work). <paramref name="Problem"/>: why «Scarica» cannot run now; <paramref name="Summary"/>: the line
/// of the dialog («12 fotogrammi da 4 video · le 3 foto si saltano»).
/// </summary>
public sealed record FramesPlanDto(int Videos, int PhotosSkipped, int NotAvailable, int Frames, int OverCap, bool TooManyToDownload, bool NeedsQuiet, string? Problem, string Summary);
/// <summary>A download of frames ready: open <paramref name="Url"/> once within 5 minutes.</summary>
public sealed record FramesTokenDto(string Token, int Frames, string Url);
/// <summary>A converted file of the library («Mostra nella cartella»).</summary>
public sealed record ConversionActionRequest(long ConversionId);
/// <summary>
/// What «Elimina dalla libreria» would remove (tappa E3, spec §4.6): the entries, their files and the converted files of
/// the library made from them («elimino gli elementi interi, 9 file e 2 file convertiti»).
/// </summary>
public sealed record EntryDeletionPreviewDto(int Entries, int Files, int ConvertedFiles);