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

+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;
}