M7 Importazione: sorgenti con sola lettura riconosciuta, analisi in sola lettura interrompibile e ripristinabile (tipo dal contenuto, SHA-256, impronta, date da nome, EXIF scritto a mano, mvhd e ffprobe facoltativo), riconoscitori Febe, generico e 4K Stogram come ipotesi spenta, confronto con la libreria e dentro la sorgente, associazione cartelle-account, decisioni sui doppioni, copia o spostamento verificati con sostituzione sicura, resoconto e CSV; prove

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 18:32:01 +00:00
1 parent 6ff11ac8e3
commit 5e77bdefe0
32 files changed
+7707 -3

No files matched your search

+46 -3
View File
@@ -17,6 +17,37 @@ public sealed record MediaContent
/// <summary>Drop the file beyond this size («Salta i video oltre», spec §4.4).</summary>
public long? MaxBytes { get; init; }
/// <summary>
/// Path relative to the account folder ('/' separated) to use instead of the naming scheme: imported files without
/// a known date and code go to <c>importati/</c> with their original name (spec §9.4). A taken name still becomes
/// «nome (2).ext»: nothing is overwritten.
/// </summary>
public string? FixedRelativePath { get; init; }
/// <summary>
/// The SHA-256 the content must have (lowercase hex), e.g. the one measured by the analysis of an import. When the
/// bytes read differ, nothing is kept and <see cref="ContentChangedException"/> is thrown.
/// </summary>
public string? ExpectedSha256 { get; init; }
}
/// <summary>The content read differs from <see cref="MediaContent.ExpectedSha256"/>: nothing was kept.</summary>
public sealed class ContentChangedException : IOException
{
public ContentChangedException()
{
}
public ContentChangedException(string message)
: base(message)
{
}
public ContentChangedException(string message, Exception innerException)
: base(message, innerException)
{
}
}
public enum MediaSaveOutcome
@@ -92,7 +123,9 @@ public sealed class LibraryIngest(
var folder = layout.AccountFolder(account);
var scheme = naming.For(entry.Kind);
var zone = clock.LocalZone;
var provisional = layout.RelativePathFor(folder, scheme, NamingValues.For(account.Username, entry, media.Position, content.Extension, highlightTitle), zone);
var provisional = content.FixedRelativePath is { } fixedPath
? LibraryLayout.ToStored(fixedPath)
: layout.RelativePathFor(folder, scheme, NamingValues.For(account.Username, entry, media.Position, content.Extension, highlightTitle), zone);
var directory = provisional.Contains('/', StringComparison.Ordinal) ? provisional[..provisional.LastIndexOf('/')] : string.Empty;
MediaLocation? identical = null;
@@ -102,10 +135,20 @@ public sealed class LibraryIngest(
directory,
async (digest, token) =>
{
if (content.ExpectedSha256 is { } expected && !string.Equals(expected, digest.Sha256, StringComparison.OrdinalIgnoreCase))
{
throw new ContentChangedException("Il contenuto letto è diverso da quello atteso: il file non viene salvato.");
}
var same = await storage.Media.FindBySha256Async(digest.Sha256, token).ConfigureAwait(false);
identical = same.FirstOrDefault(s => s.Entry.AccountId == account.Id && s.Media.Id != media.Id && EntryStateRules.IsPresent(s.Media.State));
return identical is not null
? null
if (identical is not null)
{
return null;
}
return content.FixedRelativePath is not null
? provisional
: layout.RelativePathFor(folder, scheme, NamingValues.For(account.Username, entry, media.Position, content.Extension, highlightTitle, digest.Sha256), zone);
},
new SafeWriteOptions