E3: API di formati e fotogrammi, conversione della libreria e demo

Porta le funzioni della tappa E3 fino all'interfaccia web, così che WP4
possa costruire le schermate su indirizzi veri.

- Impostazioni, cartelle delle copie e «Copia in…» hanno i formati
  (nomi original, jpg, png, webplossless, mp4); il riepilogo dice cosa si
  converte, cosa resta com'è e se c'è perdita. «Copia di nuovo» rifà la
  copia nella sua forma esatta.
- Fotogrammi: informazioni di un video, un fotogramma (anteprima o
  scaricamento), gli istanti di una modalità, «Scarica» di uno o di uno
  zip scritto mentre parte, con il permesso dei lavori lunghi oltre 20.
  Kestrel non vede mai scritture sincrone: il piccolo descrittore che lo
  zip di .NET 10 scrive in modo sincrono parte con la scrittura seguente.
- Conversione della libreria: stato, la domanda «Converti anche i N già
  in libreria?», riprova, pausa e ripresa; il visualizzatore mostra i
  file convertiti, e le eliminazioni li contano.
- Demo: un video H.264 scritto in casa (solo macroblocchi I_PCM) per
  ogni video, una copia in PNG, un fotogramma e due conversioni; la
  conversione non parte mai.

Due prove cambiano con il comportamento: i video della demo ora si
aprono, e un file non copiato può avere il segno «solo fotogramma».

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-28 01:02:37 +01:00
1 parent 724c5bda6f
commit ab0d717424
25 files changed
+2559 -95

No files matched your search

+62 -1
View File
@@ -12,7 +12,8 @@ namespace Febe.Tests.Web;
/// <summary>
/// The copies of the demo (spec §10.6, tappa E2) tell one story everywhere: the block «Copie esterne» of each account
/// counts what the «Copie» filter finds and what the tiles mark; every job has its files; a copy «Copiato» is a real
/// file with its SHA-256 in its folder, a copy «Tolto» has none, the old file of a «Superato» is still there.
/// file with its SHA-256 in its folder, a copy «Tolto» has none, the old file of a «Superato» is still there. Tappa E3:
/// a copy converted to PNG, a frame of a video and two conversions of the library, which the demo never runs.
/// </summary>
[TestClass]
public sealed class DemoExportTests
@@ -61,12 +62,18 @@ public sealed class DemoExportTests
var destinations = await demo.Storage.Exports.ListDestinationsAsync(includeRetired: true, ct);
Assert.IsGreaterThanOrEqualTo(2, destinations.Count);
var states = new HashSet<ExportCopyState>();
var forms = new List<ExportCopy>();
foreach (var destination in destinations)
{
Assert.IsTrue(Directory.Exists(destination.RootPath), destination.RootPath);
foreach (var copy in await demo.Storage.Exports.ListCopiesAsync(destination.Id, null, 0, 100_000, ct))
{
states.Add(copy.State);
if (copy.State == ExportCopyState.Copied && copy.Variant != ExportVariant.Whole)
{
forms.Add(copy);
}
var path = copy.RelativePath is { } relative ? Path.Combine(destination.RootPath, LibraryLayout.ToPlatform(relative)) : null;
switch (copy.State)
{
@@ -149,5 +156,59 @@ public sealed class DemoExportTests
}
Assert.IsGreaterThanOrEqualTo(2, checkedAccounts, "the demo has accounts with files to copy");
// Tappa E3: the converted copy (by the real engine) and the frame are real files with their SHA-256 (checked above).
var convertedCopy = forms.SingleOrDefault(c => c.Variant == ExportVariant.Converted);
Assert.IsNotNull(convertedCopy, "a copy converted to PNG");
Assert.AreEqual(ExportFormat.Png, convertedCopy.Format);
StringAssert.EndsWith(convertedCopy.RelativePath, ".png");
var frameCopy = forms.Single(c => c.Variant == ExportVariant.Frame);
Assert.AreEqual(TimeSpan.FromMilliseconds(1125), frameCopy.FrameAt, "1.234 s shows the picture shown from 1.125 s");
StringAssert.EndsWith(frameCopy.RelativePath, "_t0m01s125.png");
// The demo video gives frames: the preview of that instant is the frame copied.
var videoId = frameCopy.MediaId!.Value;
var info = await GetAsync($"/api/media/{videoId}/frames/info");
Assert.IsTrue(info.Bool("available"), info.ToString());
Assert.AreEqual(2000L, info.Long("durationMs"));
using (var frame = await client.GetAsync($"/api/media/{videoId}/frame?at=1234&format=png&download=1", ct))
{
Assert.AreEqual(HttpStatusCode.OK, frame.StatusCode);
Assert.AreEqual("image/png", frame.Content.Headers.ContentType?.MediaType);
Assert.AreEqual(frameCopy.CopySha256, Convert.ToHexStringLower(SHA256.HashData(await frame.Content.ReadAsByteArrayAsync(ct))));
}
var video = await demo.Storage.Media.GetAsync(videoId, ct);
var viewer = (await GetAsync($"/api/entries/{video!.EntryId}")).Items("media").Single(m => m.Long("id") == videoId);
Assert.IsTrue(viewer.Bool("framesAvailable"));
var frameRow = viewer.Items("copies").Single(c => c.Str("variant") == "frame");
Assert.AreEqual(1125L, frameRow.Long("frameAtMs"));
Assert.AreEqual("0:01,125", frameRow.Str("frameLabel"));
// Two conversions of the library, which the demo never runs: nothing waits and nothing changes.
var conversion = await GetAsync("/api/export/library-conversion");
Assert.AreEqual(0, conversion.Int("pending"));
Assert.AreEqual(1, conversion.Int("converted"));
Assert.AreEqual(1, conversion.Int("asIs"));
Assert.AreEqual(0, conversion.Int("failed"));
var (rowId, file) = demo.World.ConversionFiles.Single();
var row = await demo.Storage.Conversions.GetAsync(rowId, ct);
Assert.AreEqual(MediaConversionState.Converted, row!.State);
using (var converted = await client.GetAsync($"/api/conversions/{rowId}/file", ct))
{
Assert.AreEqual(HttpStatusCode.OK, converted.StatusCode);
Assert.AreEqual("image/png", converted.Content.Headers.ContentType?.MediaType);
Assert.AreEqual(row.Sha256, Convert.ToHexStringLower(SHA256.HashData(await converted.Content.ReadAsByteArrayAsync(ct))));
}
var photo = await demo.Storage.Media.GetAsync(row.MediaId, ct);
var shown = (await GetAsync($"/api/entries/{photo!.EntryId}")).Items("media").Single(m => m.Long("id") == row.MediaId);
var shownRow = shown.Items("conversions").Single();
Assert.AreEqual("converted", shownRow.Str("state"));
Assert.AreEqual("png", shownRow.Str("format"));
Assert.IsTrue(shownRow.Bool("available"));
await Task.Delay(TimeSpan.FromSeconds(1), ct);
Assert.AreEqual(MediaConversionState.Converted, (await demo.Storage.Conversions.GetAsync(rowId, ct))!.State, "the demo never converts");
Assert.IsTrue(File.Exists(file));
}
}