E1: schema dell'esportazione, migrazione 0003, archivi ed ExportSettings (#58)
verifica / controlli (push) Successful in 19s
verifica / prove (push) Canceled after 10m59s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s

La tappa E1 della 0.3.0 prepara il database per le copie esterne senza cambiare
comportamento: nulla in interfaccia, motore o API usa ancora ciò che segue.

- Migrazione 0003: export_destination, export_account, export_copy, export_run,
  export_item, video_analysis e media_conversion (risposta di Alberto del 26
  novembre: i convertiti per la libreria in una tabella a parte, media non cambia),
  con i vincoli e gli indici di §8.3.
- Archivi IExportStore, IVideoAnalysisStore e IMediaConversionStore in IFebeStorage;
  ExportSettings sulle cinque chiavi esportazione.*.
- AccountStore.DeleteAsync spegne «Automatica» delle cartelle dell'account e vi
  scrive il suo nome prima di cancellarlo (finché non ci sono destinazioni non fa nulla).
- Prove: aggiornamento dei database delle versioni 1 e 2 con foreign_key_check
  pulito, database più nuovo rifiutato e lasciato intatto, vincoli, archivi,
  piani delle ricerche, impostazioni e documenti.
- SPECIFICA §4.10, §8.3 e §15, decisioni.md e stato.md aggiornati.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-26 19:29:14 +01:00
1 parent dc92cabe5c
commit ea4666d49b
23 files changed
+3756 -7

No files matched your search

+381
View File
@@ -0,0 +1,381 @@
namespace Febe.Core.Domain;
/// <summary>Scope of an export destination (spec §4.10 «Destinazioni»).</summary>
public enum ExportScope
{
/// <summary>«Cartella di esportazione generale»: every account, each under its own segment.</summary>
General,
/// <summary>«Cartella propria» of one account, which replaces the general folder for that account.</summary>
Account,
}
/// <summary>Format of an exported file or of a converted library file (spec §4.10 «Conversione del formato»).</summary>
public enum ExportFormat
{
/// <summary>«Originale»: the file as it is in the library, byte for byte.</summary>
Original,
/// <summary>JPG, quality 92: the only lossy choice («con perdita»).</summary>
Jpg,
/// <summary>PNG.</summary>
Png,
/// <summary>«WEBP senza perdita».</summary>
WebpLossless,
/// <summary>MP4, by remuxing only.</summary>
Mp4,
}
/// <summary>Which formats belong to photos and which to videos.</summary>
public static class ExportFormats
{
/// <summary>Originale, JPG, PNG, WEBP senza perdita.</summary>
public static bool IsPhotoFormat(ExportFormat format) =>
format is ExportFormat.Original or ExportFormat.Jpg or ExportFormat.Png or ExportFormat.WebpLossless;
/// <summary>Originale, MP4.</summary>
public static bool IsVideoFormat(ExportFormat format) => format is ExportFormat.Original or ExportFormat.Mp4;
}
/// <summary>What an export writes from a library file.</summary>
public enum ExportVariant
{
/// <summary>«Intero»: the whole file, byte for byte (format Original).</summary>
Whole,
/// <summary>«Convertito»: the file in another format.</summary>
Converted,
/// <summary>«Fotogramma»: a picture of a video at an instant.</summary>
Frame,
}
/// <summary>State of a copy in a destination (spec §4.10 «Già copiato»).</summary>
public enum ExportCopyState
{
/// <summary>«Copiato».</summary>
Copied,
/// <summary>«Tolto»: the file is no longer in the destination. Never copied again by itself.</summary>
Removed,
/// <summary>«Superato»: the library file changed after the copy. Never copied again by itself.</summary>
Superseded,
/// <summary>«Non riuscito».</summary>
Failed,
}
/// <summary>How a copy came to be recorded.</summary>
public enum ExportCopyOrigin
{
/// <summary>Written by Febe.</summary>
Written,
/// <summary>An existing file recognised by path (spec §4.10 «Adozione per percorso»).</summary>
Adopted,
}
/// <summary>Kind of an export job.</summary>
public enum ExportRunKind
{
/// <summary>«Copia in…» or the automatic export.</summary>
Copy,
/// <summary>«Riconosci le copie già presenti».</summary>
Recognize,
}
/// <summary>Who started an export job.</summary>
public enum ExportRunOrigin
{
Manual,
Automatic,
}
/// <summary>State of an export job (on the model of <see cref="ImportRunState"/>).</summary>
public enum ExportRunState
{
Running,
/// <summary>Febe was closed: resumes from the pending items.</summary>
Interrupted,
/// <summary>The destination is not reachable: resumes when a later check succeeds.</summary>
Paused,
Completed,
Cancelled,
}
/// <summary>Progress of one file of an export job.</summary>
public enum ExportItemState
{
Pending,
/// <summary>Written to the destination.</summary>
Copied,
/// <summary>An existing file recognised by path.</summary>
Adopted,
/// <summary>«Già copiato»: nothing to do.</summary>
AlreadyCopied,
Skipped,
/// <summary>«File non presente in libreria».</summary>
Missing,
/// <summary>«Non riuscito».</summary>
Failed,
}
/// <summary>Outcome of «È un video fermo?» (spec §4.10).</summary>
public enum VideoAnalysisOutcome
{
/// <summary>«Fermo».</summary>
Still,
/// <summary>«In movimento».</summary>
Moving,
/// <summary>«Non analizzabile».</summary>
NotAnalyzable,
}
/// <summary>State of a converted file added to an entry by the conversion for the library.</summary>
public enum MediaConversionState
{
/// <summary>«In attesa»: the queue of the conversion.</summary>
Pending,
/// <summary>«Convertito».</summary>
Converted,
/// <summary>«Superato»: the original changed after the conversion.</summary>
Superseded,
/// <summary>«Tolto»: the converted file was deleted with its remembered entry.</summary>
Removed,
/// <summary>«Non riuscito».</summary>
Failed,
}
/// <summary>
/// An export destination (spec §8.3 <c>export_destination</c>): the general folder or the own folder of an account.
/// One row is one root folder for ever: another folder is a new row, and the old one is retired with its copies.
/// </summary>
public sealed record ExportDestination
{
public long Id { get; init; }
public required ExportScope Scope { get; init; }
/// <summary>The account of an own folder; null for the general folder, and after the account was removed.</summary>
public long? AccountId { get; init; }
/// <summary>User name of the account when it was removed («era di @nome»). Written only by the account removal.</summary>
public string? RemovedAccountUsername { get; init; }
/// <summary>Name shown in the interface; null: the last segment of <see cref="RootPath"/>.</summary>
public string? Label { get; init; }
/// <summary>Root folder as chosen. Never created by Febe, never changed.</summary>
public required string RootPath { get; init; }
public required ContentTypes ContentTypes { get; init; }
/// <summary>Null: «Come le impostazioni generali».</summary>
public ExportFormat? PhotoFormat { get; init; }
/// <summary>Null: «Come le impostazioni generali».</summary>
public ExportFormat? VideoFormat { get; init; }
/// <summary>General naming scheme under the destination; null: «Come la libreria».</summary>
public string? NamingScheme { get; init; }
/// <summary>Naming scheme of highlight collections; null: «Come la libreria».</summary>
public string? HighlightNamingScheme { get; init; }
/// <summary>Naming scheme of profile pictures; null: «Come la libreria».</summary>
public string? ProfileNamingScheme { get; init; }
/// <summary>«Automatica» (off by default).</summary>
public bool Automatic { get; init; }
/// <summary>
/// «Solo i nuovi»: files downloaded at or after this instant; null with <see cref="Automatic"/>: everything. Must
/// be null when <see cref="Automatic"/> is off.
/// </summary>
public DateTimeOffset? AutomaticSince { get; init; }
/// <summary>The probe file could not be written: paused until a later check succeeds.</summary>
public DateTimeOffset? PausedAt { get; init; }
public string? LastError { get; init; }
public required DateTimeOffset CreatedAt { get; init; }
/// <summary>Retired: removed by Alberto, or replaced by a row with another folder.</summary>
public DateTimeOffset? RemovedAt { get; init; }
public bool IsRetired => RemovedAt is not null;
/// <summary>An own folder whose account was removed.</summary>
public bool IsOrphan => Scope == ExportScope.Account && AccountId is null;
}
/// <summary>
/// The identity of a copy: SHA-256 of the original, destination, effective account, variant, format and frame instant,
/// always the effective ones (a byte-for-byte result is <see cref="ExportVariant.Whole"/> and
/// <see cref="ExportFormat.Original"/> whatever was requested).
/// </summary>
public sealed record ExportCopyIdentity(long DestinationId, long AccountId, string SourceSha256, ExportVariant Variant, ExportFormat Format, TimeSpan? FrameAt);
/// <summary>A copy made in a destination (spec §8.3 <c>export_copy</c>). It outlives the library entry.</summary>
public sealed record ExportCopy
{
public long Id { get; init; }
public required long DestinationId { get; init; }
/// <summary>Effective account; null only after the account was removed («orphan»).</summary>
public long? AccountId { get; init; }
/// <summary>The library file; null after the entry or its files were deleted.</summary>
public long? MediaId { get; init; }
public required string SourceSha256 { get; init; }
public required ExportVariant Variant { get; init; }
public ExportFormat Format { get; init; } = ExportFormat.Original;
/// <summary>Instant of a frame; set only for <see cref="ExportVariant.Frame"/>.</summary>
public TimeSpan? FrameAt { get; init; }
public required ExportCopyState State { get; init; }
/// <summary>SHA-256 of the library file that took the place of the original: required for Superseded, allowed on Removed.</summary>
public string? SupersededBySha256 { get; init; }
public ExportCopyOrigin Origin { get; init; } = ExportCopyOrigin.Written;
/// <summary>Path relative to the destination root, '/' separated, NFC.</summary>
public string? RelativePath { get; init; }
public long? Bytes { get; init; }
public string? CopySha256 { get; init; }
public required DateTimeOffset CopiedAt { get; init; }
public DateTimeOffset? StateChangedAt { get; init; }
public string? LastError { get; init; }
/// <summary>The identity of the copy; null for an orphan row.</summary>
public ExportCopyIdentity? Identity =>
AccountId is { } account ? new ExportCopyIdentity(DestinationId, account, SourceSha256, Variant, Format, FrameAt) : null;
}
/// <summary>An export job (spec §8.3 <c>export_run</c>, on the model of <see cref="ImportRun"/>).</summary>
public sealed record ExportRun
{
public long Id { get; init; }
public required long DestinationId { get; init; }
public ExportRunKind Kind { get; init; } = ExportRunKind.Copy;
public ExportRunOrigin Origin { get; init; } = ExportRunOrigin.Manual;
public ExportRunState State { get; init; } = ExportRunState.Running;
public required DateTimeOffset StartedAt { get; init; }
public DateTimeOffset? CompletedAt { get; init; }
public string? LastError { get; init; }
}
/// <summary>
/// A file of an export job (spec §8.3 <c>export_item</c>, on the model of <see cref="ImportFile"/>): the request
/// (variant and format as asked) and how it went; the effective result goes to <see cref="ExportCopy"/>.
/// </summary>
public sealed record ExportItem
{
public long Id { get; init; }
public required long RunId { get; init; }
/// <summary>The library file; null when it was deleted meanwhile.</summary>
public long? MediaId { get; init; }
/// <summary>Effective account; required when the item is added.</summary>
public long? AccountId { get; init; }
/// <summary>SHA-256 of the original when queued; null when the file was not in the library.</summary>
public string? SourceSha256 { get; init; }
public ExportVariant Variant { get; init; } = ExportVariant.Whole;
public ExportFormat Format { get; init; } = ExportFormat.Original;
public TimeSpan? FrameAt { get; init; }
public ExportItemState State { get; init; } = ExportItemState.Pending;
/// <summary>English code of a note for the report.</summary>
public string? Note { get; init; }
/// <summary>Target path in the destination, written before the <c>.part</c> is created.</summary>
public string? RelativePath { get; init; }
public long? CopyId { get; init; }
public string? LastError { get; init; }
}
/// <summary>Outcome of the still-video analysis of one algorithm for one SHA-256 (spec §8.3 <c>video_analysis</c>).</summary>
public sealed record VideoAnalysis(string Sha256, int Algorithm, VideoAnalysisOutcome Outcome, DateTimeOffset AnalyzedAt);
/// <summary>
/// A converted file added to an entry by the conversion for the library (spec §4.10, §8.3 <c>media_conversion</c>),
/// linked to the media row of its original, which does not change.
/// </summary>
public sealed record MediaConversion
{
public long Id { get; init; }
public required long MediaId { get; init; }
public required ExportFormat Format { get; init; }
public MediaConversionState State { get; init; } = MediaConversionState.Pending;
/// <summary>SHA-256 of the original it was made from.</summary>
public required string SourceSha256 { get; init; }
/// <summary>Path relative to the account folder, like <see cref="Media.RelativePath"/>.</summary>
public string? RelativePath { get; init; }
public long? Bytes { get; init; }
/// <summary>SHA-256 of the converted file.</summary>
public string? Sha256 { get; init; }
public required DateTimeOffset CreatedAt { get; init; }
public DateTimeOffset? ConvertedAt { get; init; }
public DateTimeOffset? StateChangedAt { get; init; }
public string? LastError { get; init; }
}