«È un video fermo?» dal visualizzatore (POST /api/media/{id}/still, con
400/404/409/503 e niente salvato negli errori) e l'esito su ogni video
dell'elemento (media[].still), perché l'interfaccia di WP6 lo mostri.
«Salva il fotogramma» salva il fotogramma scelto dall'analisi (il più
nitido, mai uno scuro, risposta 45): «Scarica» da
/api/media/{id}/still/frame con il nome …_fotogramma.png, e «Nella
cartella delle copie» con frames.mode "fermo" attraverso pianificatore,
impostazioni del lavoro e copiatore (FrameMode.Still, suffisso
_fotogramma, stessa identità delle copie dei fotogrammi di E3). Vale per
un video solo (risposta 46); un video non fermo o mai analizzato si
conta come notStill e non si copia.
«Cerca i video fermi» per una selezione: conferma con i conteggi,
avvio, avanzamento e «Interrompi» (/api/still-videos/*). Tutti i DTO nel
FebeJsonContext; i comandi passano dal controllo dell'Origin. Il servizio
registra con ILogger e FebeApp lo chiude all'arresto prima dell'archivio.
LEGGIMI di Febe.Web aggiornato; prove dell'API su video costruiti.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
359 lines
23 KiB
C#
359 lines
23 KiB
C#
using System.Net;
|
|
using System.Text.Json;
|
|
using Febe.Core.Abstractions;
|
|
using Febe.Core.Domain;
|
|
using Febe.Core.Export;
|
|
using Febe.Core.Library;
|
|
using Febe.Core.Library.StillVideos;
|
|
using Febe.Core.Storage;
|
|
using Febe.Tests.Codecs.Containers;
|
|
using Febe.Tests.Export.Support;
|
|
using Febe.Tests.Support;
|
|
using Febe.Tests.Web.Support;
|
|
using Febe.Web;
|
|
using Febe.Web.Library;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Febe.Tests.Web;
|
|
|
|
/// <summary>
|
|
/// Still videos over the API of a real web host (spec §4.10, tappa E4, D7, D8, D9, D15), with videos built by the test
|
|
/// (<see cref="PcmVideos"/>): «È un video fermo?» from the viewer and what the entry says afterwards, its answers for a
|
|
/// photo, a missing or changed file and an analysis past its time, «Salva il fotogramma» with «Scarica» (the frame the
|
|
/// analysis chose, <c>…_fotogramma.png</c>) and to the folder of the copies (an <c>export_copy</c> row of a frame, never
|
|
/// overwritten, «già copiato» the second time), and «Cerca i video fermi» with its counts, its wait for an engine session,
|
|
/// «Interrompi» and its end.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class StillVideosApiTests
|
|
{
|
|
public TestContext TestContext { get; set; } = null!;
|
|
|
|
[TestMethod]
|
|
[Timeout(120_000, CooperativeCancellation = true)]
|
|
public async Task TheViewerAnalysesAVideoAndTheEntrySaysIt()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var server = await StartAsync();
|
|
var marta = await AccountAsync(server);
|
|
var post = await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(FadeInStill(3)), WebLibrary.Video(Moving()), WebLibrary.Photo(4));
|
|
var (still, moving, photo) = (post.Media[0], post.Media[1], post.Media[2]);
|
|
|
|
// Before: nothing is known, the viewer offers «È un video fermo?».
|
|
var before = (await server.GetJsonAsync($"/api/entries/{post.Entry.Id}")).Items("media").ToList();
|
|
Assert.IsTrue(before.All(m => m.GetProperty("still").ValueKind == JsonValueKind.Null), "no analysis yet");
|
|
|
|
server.Clock.Now = Make.T0.AddHours(3);
|
|
var (status, analysed) = await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{still.Id}/still");
|
|
Assert.AreEqual(HttpStatusCode.OK, status, analysed.ToString());
|
|
Assert.AreEqual(("still", true), (analysed.Str("outcome"), analysed.Bool("current")));
|
|
var frameAt = analysed.Long("frameAtMs");
|
|
Assert.IsGreaterThan(300L, frameAt, "the sharpest frame, after the fade from black (answer 45)");
|
|
Assert.AreEqual(ExportFrames.Label(TimeSpan.FromMilliseconds(frameAt)), analysed.Str("frameLabel"));
|
|
Assert.AreEqual($"{LocalCalendar.Today(server.Clock.Now, server.Clock.LocalZone):yyyy-MM-dd}", analysed.Str("day"));
|
|
var row = await server.Db.VideoAnalyses.GetAsync(still.Sha256!, ct);
|
|
Assert.AreEqual((VideoAnalysisOutcome.Still, StillVideoAnalyzer.Algorithm, TimeSpan.FromMilliseconds(frameAt)), (row!.Outcome, row.Algorithm, row.FrameAt!.Value));
|
|
|
|
var other = (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{moving.Id}/still")).Body;
|
|
Assert.AreEqual("moving", other.Str("outcome"));
|
|
Assert.AreEqual(JsonValueKind.Null, other.GetProperty("frameAtMs").ValueKind);
|
|
Assert.AreEqual(JsonValueKind.Null, other.GetProperty("frameLabel").ValueKind);
|
|
|
|
// The viewer reads them from the entry; a photo has none.
|
|
var shown = (await server.GetJsonAsync($"/api/entries/{post.Entry.Id}")).Items("media").ToDictionary(m => m.Long("id"));
|
|
Assert.AreEqual(("still", frameAt), (shown[still.Id].GetProperty("still").Str("outcome"), shown[still.Id].GetProperty("still").Long("frameAtMs")));
|
|
Assert.AreEqual("moving", shown[moving.Id].GetProperty("still").Str("outcome"));
|
|
Assert.AreEqual(JsonValueKind.Null, shown[photo.Id].GetProperty("still").ValueKind);
|
|
|
|
// A photo, an unknown file.
|
|
var (photoStatus, photoBody) = await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{photo.Id}/still");
|
|
Assert.AreEqual((HttpStatusCode.BadRequest, StillVideoText.NotAVideo), (photoStatus, photoBody.Str("message")));
|
|
Assert.AreEqual(HttpStatusCode.NotFound, (await server.SendJsonAsync(HttpMethod.Post, "/api/media/999999/still")).Status);
|
|
|
|
// A video Febe cannot decode is «Non analizzabile», with its reason.
|
|
var noise = new byte[40_000];
|
|
new Random(5).NextBytes(noise);
|
|
var junk = await WebLibrary.AddPostAsync(server, marta, "rumore", Make.T0.AddDays(-2), WebLibrary.Video(noise));
|
|
var notAnalyzable = (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{junk.Media[0].Id}/still")).Body;
|
|
Assert.AreEqual(("notAnalyzable", VideoAnalysisNotes.FrameNotAvailable), (notAnalyzable.Str("outcome"), notAnalyzable.Str("note")));
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(120_000, CooperativeCancellation = true)]
|
|
public async Task AMissingOrChangedFileAndASlowAnalysisStoreNothing()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var server = await StartAsync();
|
|
var marta = await AccountAsync(server);
|
|
var gone = (await WebLibrary.AddPostAsync(server, marta, "andato", Make.T0.AddDays(-1), WebLibrary.Video(Still(5)))).Media[0];
|
|
var changed = (await WebLibrary.AddPostAsync(server, marta, "cambiato", Make.T0.AddDays(-2), WebLibrary.Video(Still(6)))).Media[0];
|
|
|
|
File.Delete(WebLibrary.PathOf(server, marta, gone));
|
|
var (goneStatus, goneBody) = await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{gone.Id}/still");
|
|
Assert.AreEqual(HttpStatusCode.NotFound, goneStatus);
|
|
Assert.IsNotEmpty(goneBody.Str("message"));
|
|
|
|
await File.WriteAllBytesAsync(WebLibrary.PathOf(server, marta, changed), Still(7), ct);
|
|
var (changedStatus, changedBody) = await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{changed.Id}/still");
|
|
Assert.AreEqual((HttpStatusCode.Conflict, StillVideoText.SourceChanged), (changedStatus, changedBody.Str("message")));
|
|
Assert.IsNull(await server.Db.VideoAnalyses.GetAsync(gone.Sha256!, ct));
|
|
Assert.IsNull(await server.Db.VideoAnalyses.GetAsync(changed.Sha256!, ct));
|
|
|
|
// Past its 30 seconds the viewer says to use the selection, and stores nothing (answer 43).
|
|
await using var slow = await WebTestServer.StartAsync(
|
|
Options,
|
|
s => s.AddSingleton(sp => new StillVideoService(new StillVideoEnvironment
|
|
{
|
|
Storage = sp.GetRequiredService<IFebeStorage>(),
|
|
Resolve = sp.GetRequiredService<IMediaFileResolver>().Resolve,
|
|
Clock = sp.GetRequiredService<IClock>(),
|
|
ViewerBudget = TimeSpan.Zero,
|
|
})));
|
|
var video = (await WebLibrary.AddPostAsync(slow, await AccountAsync(slow), "lento", Make.T0.AddDays(-1), WebLibrary.Video(Still(8)))).Media[0];
|
|
var (slowStatus, slowBody) = await slow.SendJsonAsync(HttpMethod.Post, $"/api/media/{video.Id}/still");
|
|
Assert.AreEqual((HttpStatusCode.ServiceUnavailable, StillVideoText.TooSlow), (slowStatus, slowBody.Str("message")));
|
|
Assert.IsNull(await slow.Db.VideoAnalyses.GetAsync(video.Sha256!, ct));
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(120_000, CooperativeCancellation = true)]
|
|
public async Task ScaricaGivesTheChosenFrameNamedFotogramma()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var server = await StartAsync();
|
|
var marta = await AccountAsync(server);
|
|
var post = await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(FadeInStill(9)), WebLibrary.Video(Moving()));
|
|
var (still, moving) = (post.Media[0], post.Media[1]);
|
|
|
|
// Not analysed yet, or not still: there is no frame to save.
|
|
var (notYet, notYetBody) = await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{still.Id}/still/frame?download=1");
|
|
Assert.AreEqual(HttpStatusCode.Conflict, notYet);
|
|
StringAssert.StartsWith(notYetBody.Str("message"), StillVideoText.NotStill);
|
|
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{moving.Id}/still")).Status);
|
|
Assert.AreEqual(HttpStatusCode.Conflict, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{moving.Id}/still/frame")).Status);
|
|
|
|
var frameAt = (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{still.Id}/still")).Body.Long("frameAtMs");
|
|
byte[] saved;
|
|
using (var response = await server.Client.GetAsync($"/api/media/{still.Id}/still/frame?download=1", ct))
|
|
{
|
|
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
|
Assert.AreEqual("image/png", response.Content.Headers.ContentType?.MediaType, "PNG by default (answer 35)");
|
|
Assert.AreEqual(Stem(still) + "_fotogramma.png", FileName(response));
|
|
Assert.IsTrue(response.Headers.CacheControl?.NoCache, "a new analysis may choose another frame");
|
|
saved = await response.Content.ReadAsByteArrayAsync(ct);
|
|
}
|
|
|
|
// The very frame at the instant of the analysis, as «Questo istante» would give it.
|
|
using (var same = await server.Client.GetAsync($"/api/media/{still.Id}/frame?at={frameAt}&format=png", ct))
|
|
{
|
|
CollectionAssert.AreEqual(await same.Content.ReadAsByteArrayAsync(ct), saved);
|
|
}
|
|
|
|
// Other formats, and the 480 px preview of the dialog.
|
|
using (var webp = await server.Client.GetAsync($"/api/media/{still.Id}/still/frame?format=webplossless&download=1", ct))
|
|
{
|
|
Assert.AreEqual(Stem(still) + "_fotogramma.webp", FileName(webp));
|
|
}
|
|
|
|
using (var preview = await server.Client.GetAsync($"/api/media/{still.Id}/still/frame?max=480", ct))
|
|
{
|
|
Assert.AreEqual("image/jpeg", preview.Content.Headers.ContentType?.MediaType);
|
|
Assert.IsNull(FileName(preview));
|
|
}
|
|
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{still.Id}/still/frame?format=gif")).Status);
|
|
|
|
// The frames of a selection never take this mode: only the viewer saves the frame of a still video (answer 46).
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Get, $"/api/media/{still.Id}/frames/instants?mode=fermo")).Status);
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Post, "/api/frames/plan", new { mediaIds = new[] { still.Id }, frames = new { mode = "fermo" } })).Status);
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(180_000, CooperativeCancellation = true)]
|
|
public async Task TheFrameGoesToTheFolderOfTheCopiesNeverOverwritten()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var server = await StartAsync();
|
|
var marta = await AccountAsync(server);
|
|
var post = await WebLibrary.AddPostAsync(server, marta, "fermo", Make.T0.AddDays(-1), WebLibrary.Video(FadeInStill(10)), WebLibrary.Video(Moving()));
|
|
var (still, moving) = (post.Media[0], post.Media[1]);
|
|
var usb = server.Temp.Combine("usb");
|
|
Directory.CreateDirectory(usb);
|
|
var (created, destination) = await server.SendJsonAsync(HttpMethod.Post, "/api/export/destinations", WebLibrary.Destination(usb));
|
|
Assert.AreEqual(HttpStatusCode.OK, created, destination.ToString());
|
|
var destinationId = destination.GetProperty("destination").Long("id");
|
|
object Request(long media, string format = "png") => new { mediaIds = new[] { media }, frames = new { mode = "fermo", format } };
|
|
|
|
// Never analysed: nothing to copy, and the dialog says why.
|
|
var none = (await server.SendJsonAsync(HttpMethod.Post, "/api/export/plan", Request(still.Id))).Body;
|
|
Assert.AreEqual((0, 1, 0), (none.Int("frames"), none.Int("notStill"), none.Int("videos")), none.ToString());
|
|
StringAssert.Contains(none.Str("summary"), StillVideoText.NotStill);
|
|
var (noneStatus, noneJob) = await server.SendJsonAsync(HttpMethod.Post, "/api/export/start", Request(still.Id));
|
|
Assert.AreEqual(HttpStatusCode.OK, noneStatus, noneJob.ToString());
|
|
Assert.IsEmpty(noneJob.Items("runIds").ToList());
|
|
StringAssert.StartsWith(noneJob.Str("message"), StillVideoText.NotStill);
|
|
|
|
var frameAt = (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{still.Id}/still")).Body.Long("frameAtMs");
|
|
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{moving.Id}/still")).Status);
|
|
Assert.AreEqual(1, (await server.SendJsonAsync(HttpMethod.Post, "/api/export/plan", Request(moving.Id))).Body.Int("notStill"), "«In movimento»: not still");
|
|
|
|
// One video only, from the viewer (answer 46), and nothing but the format.
|
|
foreach (var wrong in new object[]
|
|
{
|
|
new { mediaIds = new[] { still.Id, moving.Id }, frames = new { mode = "fermo", format = "png" } },
|
|
new { entryIds = new[] { post.Entry.Id }, frames = new { mode = "fermo", format = "png" } },
|
|
new { mediaIds = new[] { still.Id }, frames = new { mode = "fermo", format = "png", count = 3 } },
|
|
})
|
|
{
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, (await server.SendJsonAsync(HttpMethod.Post, "/api/export/plan", wrong)).Status, JsonSerializer.Serialize(wrong));
|
|
}
|
|
|
|
var plan = (await server.SendJsonAsync(HttpMethod.Post, "/api/export/plan", Request(still.Id))).Body;
|
|
Assert.AreEqual((1, 1, 0), (plan.Int("videos"), plan.Int("frames"), plan.Int("notStill")), plan.ToString());
|
|
Assert.AreEqual("1 fotogramma da 1 video", plan.Str("summary"));
|
|
|
|
await WebLibrary.StartAndWaitAsync(server, Request(still.Id));
|
|
var frame = Path.Combine(usb, "marta.demo", LibraryLayout.ToPlatform(Path.ChangeExtension(still.RelativePath!, null) + "_fotogramma.png"));
|
|
Assert.IsTrue(File.Exists(frame), string.Join(", ", Directory.GetFiles(usb, "*", SearchOption.AllDirectories)));
|
|
Assert.HasCount(1, Directory.GetFiles(usb, "*", SearchOption.AllDirectories), "only the frame: the video is not copied");
|
|
var copy = (await server.Db.Exports.ListCopiesAsync(destinationId, null, 0, 10, ct)).Single();
|
|
Assert.AreEqual((ExportCopyState.Copied, ExportVariant.Frame, ExportFormat.Png, TimeSpan.FromMilliseconds(frameAt)), (copy.State, copy.Variant, copy.Format, copy.FrameAt!.Value));
|
|
|
|
// The viewer row and the mark of the entry, as for any frame (E3): the video is not «Copiato».
|
|
var row = (await server.GetJsonAsync($"/api/entries/{post.Entry.Id}")).Items("media").Single(m => m.Long("id") == still.Id).Items("copies").Single();
|
|
Assert.AreEqual(("copied", "frame", frameAt), (row.Str("state"), row.Str("variant"), row.Long("frameAtMs")));
|
|
var tile = (await server.GetJsonAsync("/api/library?limit=50")).Items("tiles").Single(t => t.Long("id") == post.Entry.Id);
|
|
Assert.AreEqual("frameOnly", tile.Str("copies"), tile.ToString());
|
|
|
|
// Asked again: «già copiato», the file is not written twice.
|
|
var before = await File.ReadAllBytesAsync(frame, ct);
|
|
await WebLibrary.StartAndWaitAsync(server, Request(still.Id));
|
|
Assert.HasCount(1, Directory.GetFiles(usb, "*", SearchOption.AllDirectories));
|
|
CollectionAssert.AreEqual(before, await File.ReadAllBytesAsync(frame, ct));
|
|
Assert.HasCount(1, await server.Db.Exports.ListCopiesAsync(destinationId, null, 0, 10, ct));
|
|
|
|
// A file of that name that Febe did not write is never overwritten: the frame gets a number.
|
|
File.Delete(frame);
|
|
await File.WriteAllBytesAsync(frame, [1, 2, 3], ct);
|
|
await server.Db.Exports.UpdateCopyAsync(copy with { State = ExportCopyState.Removed, StateChangedAt = server.Clock.Now }, ct);
|
|
await WebLibrary.StartAndWaitAsync(server, Request(still.Id, "png"));
|
|
CollectionAssert.AreEqual(new byte[] { 1, 2, 3 }, await File.ReadAllBytesAsync(frame, ct), "not overwritten");
|
|
Assert.HasCount(2, Directory.GetFiles(usb, "*_fotogramma*.png", SearchOption.AllDirectories));
|
|
}
|
|
|
|
[TestMethod]
|
|
[Timeout(180_000, CooperativeCancellation = true)]
|
|
public async Task CercaIVideoFermiCountsWaitsStopsAndEnds()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
var session = new FakeSessionState();
|
|
await using var server = await StartAsync(session);
|
|
var marta = await AccountAsync(server);
|
|
var first = await WebLibrary.AddPostAsync(server, marta, "uno", Make.T0.AddDays(-1), WebLibrary.Video(Still(11)), WebLibrary.Video(Moving()), WebLibrary.Photo(4));
|
|
var second = await WebLibrary.AddPostAsync(server, marta, "due", Make.T0.AddDays(-2), WebLibrary.Video(Still(12)));
|
|
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, $"/api/media/{second.Media[0].Id}/still")).Status);
|
|
var selection = new { entryIds = new[] { first.Entry.Id, second.Entry.Id } };
|
|
|
|
var idle = await server.GetJsonAsync("/api/still-videos/progress");
|
|
Assert.AreEqual((false, 0), (idle.Bool("running"), idle.Int("total")));
|
|
|
|
var plan = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", selection)).Body;
|
|
Assert.AreEqual((3, 2, 1, 1, 0), (plan.Int("videos"), plan.Int("toAnalyse"), plan.Int("alreadyAnalysed"), plan.Int("photosSkipped"), plan.Int("missing")), plan.ToString());
|
|
Assert.AreEqual("2 video da analizzare · 1 già analizzato · la foto si salta", plan.Str("summary"));
|
|
Assert.AreEqual(JsonValueKind.Null, plan.GetProperty("waiting").ValueKind);
|
|
|
|
// During an engine session it waits, and says so (answer 41); «Interrompi» ends it with nothing stored.
|
|
session.InSession = true;
|
|
Assert.AreEqual(StillVideoText.InSession, (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", selection)).Body.Str("waiting"));
|
|
var started = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", selection)).Body;
|
|
Assert.AreEqual((true, 2), (started.Bool("running"), started.Int("total")), started.ToString());
|
|
await WebLibrary.WaitAsync(async () => (await server.GetJsonAsync("/api/still-videos/progress")).Str("waiting") == StillVideoText.InSession, "the job waits for the session");
|
|
var stopped = (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/stop")).Body;
|
|
Assert.IsTrue(stopped.Bool("stopped"));
|
|
await WebLibrary.WaitAsync(async () => !(await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"), "«Interrompi» ends the job");
|
|
Assert.IsNull(await server.Db.VideoAnalyses.GetAsync(first.Media[0].Sha256!, ct));
|
|
Assert.IsNull(await server.Db.VideoAnalyses.GetAsync(first.Media[1].Sha256!, ct));
|
|
|
|
// Started again after the session: it analyses what is left, the one already analysed is skipped.
|
|
session.InSession = false;
|
|
Assert.AreEqual(HttpStatusCode.OK, (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/start", selection)).Status);
|
|
await WebLibrary.WaitAsync(async () => !(await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"), "the job ends");
|
|
var done = await server.GetJsonAsync("/api/still-videos/progress");
|
|
Assert.AreEqual((2, 2, 1, 1, 0, false), (done.Int("total"), done.Int("done"), done.Int("still"), done.Int("moving"), done.Int("notAnalyzable"), done.Bool("stopped")), done.ToString());
|
|
Assert.AreEqual("Analizzati 2 video: 1 fermo, 1 in movimento", done.Str("summary"));
|
|
var shown = (await server.GetJsonAsync($"/api/entries/{first.Entry.Id}")).Items("media").ToList();
|
|
CollectionAssert.AreEqual(new[] { "still", "moving" }, shown.Take(2).Select(m => m.GetProperty("still").Str("outcome")).ToArray());
|
|
Assert.AreEqual(0, (await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", selection)).Body.Int("toAnalyse"));
|
|
|
|
// Exactly one selection.
|
|
foreach (var wrong in new object[] { new { }, new { entryIds = new[] { first.Entry.Id }, mediaIds = new[] { first.Media[0].Id } } })
|
|
{
|
|
var (status, body) = await server.SendJsonAsync(HttpMethod.Post, "/api/still-videos/plan", wrong);
|
|
Assert.AreEqual((HttpStatusCode.BadRequest, StillVideoText.NoSelection), (status, body.Str("message")));
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task CommandsOfStillVideosComeOnlyFromFebesPages()
|
|
{
|
|
var ct = TestContext.CancellationToken;
|
|
await using var server = await StartAsync();
|
|
var post = await WebLibrary.AddPostAsync(server, await AccountAsync(server), "fermo", Make.T0.AddDays(-1), WebLibrary.Video(Still(13)));
|
|
var selection = new { mediaIds = new[] { post.Media[0].Id } };
|
|
foreach (var (path, body) in new (string, object?)[]
|
|
{
|
|
($"/api/media/{post.Media[0].Id}/still", null),
|
|
("/api/still-videos/plan", selection),
|
|
("/api/still-videos/start", selection),
|
|
("/api/still-videos/stop", null),
|
|
})
|
|
{
|
|
using var request = server.Request(HttpMethod.Post, path, body, "http://altro.example");
|
|
using var response = await server.Client.SendAsync(request, ct);
|
|
Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, path);
|
|
}
|
|
|
|
Assert.IsNull(await server.Db.VideoAnalyses.GetAsync(post.Media[0].Sha256!, ct), "nothing was analysed");
|
|
Assert.IsFalse((await server.GetJsonAsync("/api/still-videos/progress")).Bool("running"));
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------- support
|
|
|
|
private static readonly FebeWebOptions Options = new() { Edition = FebeEdition.Desktop, Access = AccessMode.None };
|
|
|
|
private static Task<WebTestServer> StartAsync(IEngineSessionState? session = null) =>
|
|
WebTestServer.StartAsync(
|
|
Options,
|
|
s =>
|
|
{
|
|
s.AddSingleton<IExportDisk>(new FakeExportDisk(500_000_000_000));
|
|
if (session is not null)
|
|
{
|
|
s.AddSingleton(session);
|
|
}
|
|
});
|
|
|
|
private static Task<Account> AccountAsync(WebTestServer server) => server.Db.Accounts.AddAsync(Make.Account("marta.demo"));
|
|
|
|
/// <summary>A still picture for 12 pictures (0,4 s); <paramref name="seed"/> makes each one another file.</summary>
|
|
private static byte[] Still(int seed)
|
|
{
|
|
var photo = PcmVideos.Photo(seed);
|
|
return PcmVideos.Mp4(12, _ => photo);
|
|
}
|
|
|
|
/// <summary>One second of a photo, the first nine pictures fading in from black (the frame chosen comes after).</summary>
|
|
private static byte[] FadeInStill(int seed)
|
|
{
|
|
var photo = PcmVideos.Photo(seed);
|
|
return PcmVideos.Mp4(30, i => i < 9 ? PcmVideos.Fade(photo, i / 9.0) : photo, audio: true);
|
|
}
|
|
|
|
private static byte[] Moving() => PcmVideos.Mp4(12, i => PcmVideos.Photo(100 + i));
|
|
|
|
private static string Stem(Media media) => Path.GetFileNameWithoutExtension(LibraryLayout.ToPlatform(media.RelativePath!));
|
|
|
|
private static string? FileName(HttpResponseMessage response) =>
|
|
response.Content.Headers.ContentDisposition?.FileNameStar ?? response.Content.Headers.ContentDisposition?.FileName?.Trim('"');
|
|
}
|