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; }
}
+102
View File
@@ -0,0 +1,102 @@
using Febe.Core.Domain;
using Febe.Core.Storage;
namespace Febe.Core.Export;
/// <summary>Setting keys of Impostazioni → Esportazione (spec §4.10). Values are the English names of the enumerations.</summary>
public static class ExportSettingKeys
{
/// <summary>Format of the copies of photos (Original, Jpg, Png, WebpLossless).</summary>
public const string PhotoFormat = "esportazione.formato-foto";
/// <summary>Format of the copies of videos (Original, Mp4).</summary>
public const string VideoFormat = "esportazione.formato-video";
/// <summary>Conversion of photos for the library; Original: off.</summary>
public const string LibraryPhotoFormat = "esportazione.libreria-formato-foto";
/// <summary>Conversion of videos for the library; Original: off.</summary>
public const string LibraryVideoFormat = "esportazione.libreria-formato-video";
/// <summary>The same post in two accounts: «Una copia per account» or «Una copia sola».</summary>
public const string SamePost = "esportazione.stesso-post";
public static IReadOnlyList<string> All { get; } = [PhotoFormat, VideoFormat, LibraryPhotoFormat, LibraryVideoFormat, SamePost];
}
/// <summary>How many copies the same post gets when it is in two accounts (spec §4.10).</summary>
public enum SamePostCopies
{
/// <summary>«Una copia per account» (default).</summary>
OnePerAccount,
/// <summary>«Una copia sola».</summary>
OneOnly,
}
/// <summary>
/// General settings of the export (spec §4.10, Impostazioni → Esportazione), in the <c>setting</c> table. Both
/// conversions are off by default. The general folder, its content types, naming schemes and «Automatica» are columns
/// of the general destination, not settings.
/// </summary>
public sealed record ExportSettings(
ExportFormat PhotoFormat = ExportFormat.Original,
ExportFormat VideoFormat = ExportFormat.Original,
ExportFormat LibraryPhotoFormat = ExportFormat.Original,
ExportFormat LibraryVideoFormat = ExportFormat.Original,
SamePostCopies SamePost = SamePostCopies.OnePerAccount)
{
/// <summary>Quality of the only lossy conversion, JPG (spec §4.10): fixed, not a setting.</summary>
public const int JpegQuality = 92;
public static ExportSettings Default { get; } = new();
/// <summary>The conversion for the copies is on for photos or videos.</summary>
public bool ConvertsCopies => PhotoFormat != ExportFormat.Original || VideoFormat != ExportFormat.Original;
/// <summary>The conversion for the library is on for photos or videos.</summary>
public bool ConvertsLibrary => LibraryPhotoFormat != ExportFormat.Original || LibraryVideoFormat != ExportFormat.Original;
/// <summary>Loads the settings in one read. A missing or invalid value gives that key's default; the others are not affected.</summary>
public static async Task<ExportSettings> LoadAsync(ISettingsStore store, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(store);
return From(await store.GetAllAsync(ct).ConfigureAwait(false));
}
/// <summary>Stores the five keys in one transaction.</summary>
public Task SaveAsync(ISettingsStore store, CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(store);
return store.SetManyAsync(
new Dictionary<string, string?>
{
[ExportSettingKeys.PhotoFormat] = PhotoFormat.ToString(),
[ExportSettingKeys.VideoFormat] = VideoFormat.ToString(),
[ExportSettingKeys.LibraryPhotoFormat] = LibraryPhotoFormat.ToString(),
[ExportSettingKeys.LibraryVideoFormat] = LibraryVideoFormat.ToString(),
[ExportSettingKeys.SamePost] = SamePost.ToString(),
},
ct);
}
/// <summary>The settings from stored values: exact, case-sensitive names; anything else gives the key's default.</summary>
internal static ExportSettings From(IReadOnlyDictionary<string, string> values)
{
ArgumentNullException.ThrowIfNull(values);
ExportFormat Format(string key, Func<ExportFormat, bool> fits) =>
Parse<ExportFormat>(values.GetValueOrDefault(key)) is { } format && fits(format) ? format : ExportFormat.Original;
return new ExportSettings(
Format(ExportSettingKeys.PhotoFormat, ExportFormats.IsPhotoFormat),
Format(ExportSettingKeys.VideoFormat, ExportFormats.IsVideoFormat),
Format(ExportSettingKeys.LibraryPhotoFormat, ExportFormats.IsPhotoFormat),
Format(ExportSettingKeys.LibraryVideoFormat, ExportFormats.IsVideoFormat),
Parse<SamePostCopies>(values.GetValueOrDefault(ExportSettingKeys.SamePost)) ?? SamePostCopies.OnePerAccount);
}
// Not Enum.TryParse: it accepts numbers («2») and lists («Jpg, Png») and returns values that are not names.
private static T? Parse<T>(string? text)
where T : struct, Enum =>
text is not null && Enum.GetNames<T>().Contains(text, StringComparer.Ordinal) ? Enum.Parse<T>(text, ignoreCase: false) : null;
}
+2 -1
View File
@@ -60,7 +60,8 @@ public interface IAccountStore
/// <summary>
/// Removes the account record and, by cascade, its entries, files records and highlights. Files on disk are not
/// touched: removing an account with its files is a library operation, and the default is to keep them and make
/// the account «Solo archivio» (spec §4.2).
/// the account «Solo archivio» (spec §4.2). Its export destinations stay, without account and with the user name;
/// its «Esporta questo account» choice goes with it (spec §4.10).
/// </summary>
Task DeleteAsync(long accountId, CancellationToken ct = default);
}
+173
View File
@@ -0,0 +1,173 @@
using Febe.Core.Domain;
namespace Febe.Core.Storage;
/// <summary>
/// Export destinations, the switch «Esporta questo account», copies, jobs and their files (spec §4.10; §8.3
/// <c>export_destination</c>, <c>export_account</c>, <c>export_copy</c>, <c>export_run</c>, <c>export_item</c>).
/// Only records: no method touches a file.
/// </summary>
public interface IExportStore
{
// Destinations ---------------------------------------------------------------------------------------------------
/// <summary>
/// Adds a destination. General: <see cref="ExportDestination.AccountId"/> null; Account: set.
/// <see cref="ExportDestination.RemovedAt"/> and <see cref="ExportDestination.RemovedAccountUsername"/> must be null.
/// <see cref="DuplicateRecordException"/> when a general folder is already in use, or the account already has an own
/// folder in use (retire it first).
/// </summary>
Task<ExportDestination> AddDestinationAsync(ExportDestination destination, CancellationToken ct = default);
/// <summary>
/// Writes label, content types, formats, naming schemes, «Automatica» and its answer, pause and error.
/// <see cref="KeyNotFoundException"/> for a missing id; <see cref="ArgumentException"/> if scope, account or root
/// differ from the stored row, the row is retired, or «Automatica» is turned on for an own folder whose account was
/// removed (it is attached to an account first).
/// </summary>
Task UpdateDestinationAsync(ExportDestination destination, CancellationToken ct = default);
Task<ExportDestination?> GetDestinationAsync(long id, CancellationToken ct = default);
/// <summary>The general folder in use, or null.</summary>
Task<ExportDestination?> GetGeneralDestinationAsync(CancellationToken ct = default);
/// <summary>The own folder in use of an account, or null.</summary>
Task<ExportDestination?> GetAccountDestinationAsync(long accountId, CancellationToken ct = default);
/// <summary>The general folder first, then by id; retired rows only when asked.</summary>
Task<IReadOnlyList<ExportDestination>> ListDestinationsAsync(bool includeRetired = false, CancellationToken ct = default);
/// <summary>
/// Retires a destination (removed by Alberto, or replaced by another folder): sets the removal time and turns
/// «Automatica» off. No row and no file is deleted. <see cref="KeyNotFoundException"/> for a missing id.
/// </summary>
Task RetireDestinationAsync(long id, DateTimeOffset at, CancellationToken ct = default);
/// <summary>
/// Gives an orphan own folder in use back to a re-added account: sets the account, clears the user name and, in the
/// same transaction, sets the account on its orphan copies. «Automatica» stays off (the removal of the account turned
/// it off and forgot «Solo i nuovi»), so turning it on again asks. <see cref="InvalidOperationException"/> if it is not
/// an orphan in use, or the account already has an own folder in use; <see cref="DuplicateRecordException"/> if an
/// orphan copy would collide with a current copy of the account.
/// </summary>
Task AttachDestinationAsync(long id, long accountId, CancellationToken ct = default);
// «Esporta questo account» ---------------------------------------------------------------------------------------
/// <summary>The choice of the account; null when none is recorded (the default applies).</summary>
Task<bool?> GetAccountExportEnabledAsync(long accountId, CancellationToken ct = default);
Task SetAccountExportEnabledAsync(long accountId, bool enabled, CancellationToken ct = default);
// Copies ---------------------------------------------------------------------------------------------------------
/// <summary>
/// Records a copy. <see cref="ArgumentException"/> when the account is null (only the removal of an account clears it);
/// <see cref="DuplicateRecordException"/> when its identity already has a current (Copied or Failed) row, or its path
/// in the destination is held by a Copied or Superseded row.
/// </summary>
Task<ExportCopy> AddCopyAsync(ExportCopy copy, CancellationToken ct = default);
/// <summary>
/// Writes state, superseded-by, media, origin, path, bytes, copy SHA-256, state time and error.
/// <see cref="KeyNotFoundException"/> for a missing id; <see cref="ArgumentException"/> if an identity column
/// (destination, account, source SHA-256, variant, format, frame) differs from the stored row;
/// <see cref="DuplicateRecordException"/> when the new state collides with another current row or path (as in
/// <see cref="AddCopyAsync"/>).
/// </summary>
Task UpdateCopyAsync(ExportCopy copy, CancellationToken ct = default);
Task<ExportCopy?> GetCopyAsync(long id, CancellationToken ct = default);
/// <summary>The current (Copied or Failed) copy of an identity.</summary>
Task<ExportCopy?> FindCurrentCopyAsync(ExportCopyIdentity identity, CancellationToken ct = default);
/// <summary>The newest row of an identity in any state: Removed or Superseded means «never queued by itself».</summary>
Task<ExportCopy?> FindLatestCopyAsync(ExportCopyIdentity identity, CancellationToken ct = default);
/// <summary>Every copy whose original has this SHA-256 or was replaced by it, any destination, account and state, newest first.</summary>
Task<IReadOnlyList<ExportCopy>> ListCopiesBySha256Async(string sha256, CancellationToken ct = default);
/// <summary>The Copied or Superseded copy recorded on this path of a destination (case-insensitive for ASCII).</summary>
Task<ExportCopy?> FindCopyByPathAsync(long destinationId, string relativePath, CancellationToken ct = default);
/// <summary>Copies of a destination by key, with an optional state.</summary>
Task<IReadOnlyList<ExportCopy>> ListCopiesAsync(long destinationId, ExportCopyState? state = null, long afterId = 0, int limit = 500, CancellationToken ct = default);
/// <summary>Counts per state of a destination; every state is present, zero included.</summary>
Task<IReadOnlyDictionary<ExportCopyState, int>> CountCopiesAsync(long destinationId, CancellationToken ct = default);
/// <summary>
/// Re-links an orphan row (account removed) to a re-added account, when its file is adopted again.
/// <see cref="KeyNotFoundException"/> for a missing id; <see cref="InvalidOperationException"/> if the row is not an orphan;
/// <see cref="DuplicateRecordException"/> if the account already has a current copy of that identity.
/// </summary>
Task<ExportCopy> RelinkOrphanCopyAsync(long copyId, long accountId, long? mediaId, DateTimeOffset at, CancellationToken ct = default);
/// <summary>
/// The library file of an account changed from <paramref name="oldSha256"/> to <paramref name="newSha256"/>: its
/// Copied rows of the old file become Superseded, its Removed rows of the old file get the new SHA-256, and its rows
/// superseded by the old file move to the new one. A row whose own original is the new file (the library went back to
/// it, A→B→A) is never superseded by itself: a Removed one loses the stamp, and the newest Superseded one of each
/// identity becomes Copied again, unless that identity already has a current row (then it stays Superseded by the old
/// file, as history). Returns the rows changed. The caller calls it only when no present file of that account still
/// has the old SHA-256.
/// </summary>
Task<int> SupersedeCopiesAsync(long accountId, string oldSha256, string newSha256, DateTimeOffset at, CancellationToken ct = default);
// Jobs and their files -------------------------------------------------------------------------------------------
Task<ExportRun> CreateRunAsync(ExportRun run, CancellationToken ct = default);
Task UpdateRunAsync(ExportRun run, CancellationToken ct = default);
Task<ExportRun?> GetRunAsync(long runId, CancellationToken ct = default);
/// <summary>Jobs, newest first.</summary>
Task<IReadOnlyList<ExportRun>> ListRunsAsync(CancellationToken ct = default);
/// <summary>Running, Interrupted and Paused jobs, oldest first.</summary>
Task<IReadOnlyList<ExportRun>> ListUnfinishedRunsAsync(CancellationToken ct = default);
/// <summary>
/// Adds items in one transaction; an item already there for the same job, file, variant, format and frame is left
/// unchanged (so a resumed job adds nothing twice). <see cref="ArgumentException"/> when an item has no account or no
/// library file (only the deletion of the file clears it, and an item without one would not be recognised again).
/// </summary>
Task AddItemsAsync(IReadOnlyList<ExportItem> items, CancellationToken ct = default);
/// <summary>
/// Writes account (never cleared), source SHA-256, state, note, path, copy and error of items. Job, file, variant,
/// format and frame are the identity of an item and are never rewritten: <see cref="ArgumentException"/> if they
/// differ from the stored row (a file deleted meanwhile stays cleared); <see cref="KeyNotFoundException"/> for a
/// missing item of the job.
/// </summary>
Task UpdateItemsAsync(IReadOnlyList<ExportItem> items, CancellationToken ct = default);
Task<ExportItem?> GetItemAsync(long itemId, CancellationToken ct = default);
/// <summary>Items of a job, by key, with an optional state.</summary>
Task<IReadOnlyList<ExportItem>> ListItemsAsync(ExportItemQuery query, CancellationToken ct = default);
/// <summary>Counts by state of a job's items; every state is present, zero included.</summary>
Task<ExportRunSummary> GetRunSummaryAsync(long runId, CancellationToken ct = default);
/// <summary>Removes a job with its items. Only records: copies stay.</summary>
Task DeleteRunAsync(long runId, CancellationToken ct = default);
}
/// <summary>A page of the items of an export job.</summary>
public sealed record ExportItemQuery
{
public required long RunId { get; init; }
public ExportItemState? State { get; init; }
public long AfterId { get; init; }
public int Limit { get; init; } = 500;
}
/// <summary>Counts of the items of an export job.</summary>
public sealed record ExportRunSummary(int Total, IReadOnlyDictionary<ExportItemState, int> ByState);
+6
View File
@@ -30,6 +30,12 @@ public interface IFebeStorage : IAsyncDisposable
IImportStore Imports { get; }
IExportStore Exports { get; }
IVideoAnalysisStore VideoAnalyses { get; }
IMediaConversionStore Conversions { get; }
ISettingsStore Settings { get; }
IDatabaseMaintenance Maintenance { get; }
@@ -0,0 +1,33 @@
using Febe.Core.Domain;
namespace Febe.Core.Storage;
/// <summary>
/// Converted files added to entries by the conversion for the library (spec §4.10, §8.3 <c>media_conversion</c>).
/// Only records: no method touches a file.
/// </summary>
public interface IMediaConversionStore
{
/// <summary>
/// Records a conversion. <see cref="DuplicateRecordException"/> when the file already has a current (Pending,
/// Converted or Failed) conversion in that format.
/// </summary>
Task<MediaConversion> AddAsync(MediaConversion conversion, CancellationToken ct = default);
/// <summary>
/// Writes state, path, bytes, SHA-256, times and error. <see cref="KeyNotFoundException"/> for a missing id;
/// <see cref="DuplicateRecordException"/> when the new state collides with another current conversion (as in <see cref="AddAsync"/>).
/// </summary>
Task UpdateAsync(MediaConversion conversion, CancellationToken ct = default);
Task<MediaConversion?> GetAsync(long id, CancellationToken ct = default);
/// <summary>The conversions of one library file, in creation order.</summary>
Task<IReadOnlyList<MediaConversion>> ListByMediaAsync(long mediaId, CancellationToken ct = default);
/// <summary>Conversions whose converted file has this SHA-256 (a converted file found again is never a duplicate).</summary>
Task<IReadOnlyList<MediaConversion>> FindBySha256Async(string sha256, CancellationToken ct = default);
/// <summary>The queue of the conversion, in order, by key.</summary>
Task<IReadOnlyList<MediaConversion>> ListPendingAsync(long afterId = 0, int limit = 500, CancellationToken ct = default);
}
@@ -0,0 +1,19 @@
using Febe.Core.Domain;
namespace Febe.Core.Storage;
/// <summary>
/// Outcomes of «È un video fermo?» by SHA-256 of the video and number of the algorithm (spec §4.10, §8.3
/// <c>video_analysis</c>). No link to the library: an outcome outlives deletion and re-import of the same file.
/// </summary>
public interface IVideoAnalysisStore
{
/// <summary>The analysis with the highest algorithm number for this SHA-256, or null.</summary>
Task<VideoAnalysis?> GetAsync(string sha256, CancellationToken ct = default);
/// <summary>The analysis with the highest algorithm number for each SHA-256 that has one, keyed by lower-case SHA-256.</summary>
Task<IReadOnlyDictionary<string, VideoAnalysis>> GetManyAsync(IReadOnlyCollection<string> sha256s, CancellationToken ct = default);
/// <summary>Stores (or replaces) the outcome of one algorithm for one SHA-256.</summary>
Task SetAsync(VideoAnalysis analysis, CancellationToken ct = default);
}