Il visualizzatore dice «File danneggiato o incompleto» (risposta 3 del 25 novembre)
verifica / controlli (push) Successful in 20s
verifica / prove (push) Canceled after 2m22s
verifica / installatore (push) Canceled after 0s
verifica / immagine (push) Canceled after 0s

I codec di casa rifiutavano già un PNG o un JPEG troncato: niente miniatura
(la tessera neutra nel mosaico), niente impronta visiva, file tenuto con il
suo SHA-256. Ma il visualizzatore mostrava il file a metà, come lo disegna il
browser. Ora la foto di un elemento ha «damaged» quando è sul disco, non ha
miniatura e i codec la riconoscono ma non riescono a decodificarla
(DamagedImage): al posto dell'immagine il visualizzatore scrive «File
danneggiato o incompleto», e le azioni sul file restano.

Il controllo si fa all'apertura, solo per le foto senza miniatura, senza
colonne nuove nel database: vale anche per le librerie già scaricate e non
pesa con 200.000 elementi. HEIC, formati sconosciuti e immagini oltre i
limiti non contano come danneggiati. Il file si legge soltanto.

Prove: rilevamento su PNG e JPEG troncati, interi, HEIC e sconosciuti;
scaricamento di foto troncate (stato, SHA-256, niente impronta né miniatura,
file intatto); API della libreria (tessera neutra, «damaged», file ancora
scaricabile). Guida (Problemi comuni) e una riga in decisioni.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-25 11:12:48 +01:00
1 parent a0e7404297
commit 5dfbe85614
10 files changed
+227 -3

No files matched your search

+45
View File
@@ -111,6 +111,8 @@ public sealed class LibraryApiTests
Assert.AreEqual("foto_1.jpg", media[0].Str("fileName"));
Assert.AreEqual(Path.Combine("marta.demo", "post"), media[0].Str("folder"));
Assert.IsFalse(media[1].Bool("available"), "a file missing from disk is said, not hidden");
Assert.IsFalse(media[0].Bool("damaged"), "a whole photo without a thumbnail yet is not damaged");
Assert.IsFalse(media[1].Bool("damaged"));
using (var file = await server.Client.GetAsync($"/api/media/{media[0].Long("id")}/file?download=1"))
{
@@ -149,6 +151,49 @@ public sealed class LibraryApiTests
Assert.AreEqual(JsonValueKind.Null, after.GetProperty("instagramUrl").ValueKind);
}
[TestMethod]
public async Task ADamagedPhotoHasTheNeutralTileTheViewerSaysSoAndItsFileStays()
{
await using var server = await WebTestServer.StartAsync();
var account = await server.Db.Accounts.AddAsync(Make.Account("marta.demo"));
var folder = server.Library.Layout.AccountFolder(account);
Directory.CreateDirectory(Path.Combine(folder, "post"));
var whole = TestImages.Jpeg(TestImages.Scene(7, 240, 180));
var cut = whole[..(whole.Length / 2)];
var png = TestImages.Png(TestImages.Scene(8, 120, 90));
var cutPng = png[..(png.Length / 2)];
await File.WriteAllBytesAsync(Path.Combine(folder, "post", "foto_1.jpg"), cut);
await File.WriteAllBytesAsync(Path.Combine(folder, "post", "foto_2.png"), cutPng);
await File.WriteAllBytesAsync(Path.Combine(folder, "post", "foto_3.jpg"), whole);
var added = await server.Db.Entries.AddAsync(
Make.Entry(account.Id, "1", Make.T0) with { State = EntryState.Downloaded },
[
Make.Stored(Make.Photo(1), Make.Sha(1), "post/foto_1.jpg") with { Bytes = cut.Length },
Make.Stored(Make.Photo(2), Make.Sha(2), "post/foto_2.png") with { Bytes = cutPng.Length },
Make.Stored(Make.Photo(3), Make.Sha(3), "post/foto_3.jpg") with { Bytes = whole.Length },
]);
var id = added.Stored.Entry.Id;
var tile = (await server.GetJsonAsync("/api/library")).Items("tiles").Single();
Assert.AreEqual(JsonValueKind.Null, tile.GetProperty("cover").GetProperty("thumb").ValueKind, "the neutral tile in the mosaic");
var media = (await server.GetJsonAsync($"/api/entries/{id}")).Items("media").ToList();
Assert.IsTrue(media[0].Bool("damaged"), "a JPEG cut in its scan: «File danneggiato o incompleto»");
Assert.IsTrue(media[1].Bool("damaged"), "a PNG cut in its data");
Assert.IsFalse(media[2].Bool("damaged"));
Assert.IsTrue(media.All(m => m.Bool("available")), "the file is in the library: its actions stay");
// The file stays as it came, and can still be downloaded (rule 12: Febe never deletes or replaces it).
using (var file = await server.Client.GetAsync($"/api/media/{media[0].Long("id")}/file?download=1"))
{
Assert.AreEqual(HttpStatusCode.OK, file.StatusCode);
CollectionAssert.AreEqual(cut, await file.Content.ReadAsByteArrayAsync());
}
CollectionAssert.AreEqual(cut, await File.ReadAllBytesAsync(Path.Combine(folder, "post", "foto_1.jpg")));
Assert.AreEqual(MediaState.Downloaded, (await server.Db.Media.GetAsync(media[0].Long("id")))!.State);
}
[TestMethod]
public async Task DeletionCanLetTheEntryComeBack()
{