merge: proxy and decode-tier fixes (V-1, V-24, V-25, V-26, V-27, V-28)
Merge branch fix2/proxies-tiers into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
28 files changed
+1049
-92
No files matched your search
@@ -60,8 +60,8 @@ public static class FileEndpoints
|
||||
/// <summary>
|
||||
/// Files the body (a JPEG made from the original, its Exif capture time the frame's, as large as the archive's proxies,
|
||||
/// at most <see cref="ArchiveImages.MaxProxyBytes"/>) as the proxy of a frame the server cannot decode
|
||||
/// (<see cref="ServerProxies"/>); the sequence's thumbnails and proxy state follow as background jobs. 204; 413
|
||||
/// <c>too_large</c>; 422 <c>proxy_not_wanted</c> (the server decodes that original itself, or it is missing or
|
||||
/// (<see cref="ServerProxies"/>); the sequence's thumbnails, proxy state and light analysis follow as background jobs.
|
||||
/// 204; 413 <c>too_large</c>; 422 <c>proxy_not_wanted</c> (the server decodes that original itself, or it is missing or
|
||||
/// damaged), <c>invalid_proxy</c>, <c>proxy_mismatch</c> or <c>proxy_too_small</c>, which concern that proxy only; 409
|
||||
/// <c>proxies_disabled</c>, which concerns them all; 503 <c>archive_offline</c>.
|
||||
/// </summary>
|
||||
|
||||
@@ -254,7 +254,11 @@ public static class SequenceEndpoints
|
||||
_ => ApiErrors.NotFound(context, "analysis"),
|
||||
};
|
||||
|
||||
/// <summary>The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence.</summary>
|
||||
/// <summary>
|
||||
/// The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence, while it
|
||||
/// describes the frames as the server reads them now (<see cref="DeepReports.ReadCurrentAsync"/>): one that found
|
||||
/// frames unreadable before their proxies arrived answers 404 <c>analysis</c>, so no editor advises excluding them.
|
||||
/// </summary>
|
||||
private static async Task<IResult> ReportAsync(HttpContext context, Guid id, TitanoDatabase db, ServerArchive archive)
|
||||
{
|
||||
if (await db.Sequences.GetAsync(id, context.RequestAborted) is not { } sequence) return ApiErrors.NotFound(context, "sequence");
|
||||
@@ -262,6 +266,16 @@ public static class SequenceEndpoints
|
||||
var path = new Core.Archiving.ArchivePaths(archive.Root).Sequence(sequence.Folder).AnalysisPath;
|
||||
var file = new FileInfo(path);
|
||||
if (!file.Exists || file.LinkTarget is not null || !ArchivePathGuard.IsInside(archive.Root, path)) return ApiErrors.NotFound(context, "analysis");
|
||||
try
|
||||
{
|
||||
if (await DeepReports.ReadCurrentAsync(db, archive.Current, sequence, Core.Imaging.Decoders.DecoderFactory.CreateServer(), context.RequestAborted) is null)
|
||||
return ApiErrors.NotFound(context, "analysis");
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
|
||||
{
|
||||
// archive.json cannot be read now, so whether the proxies count is not known.
|
||||
return ApiErrors.NotFound(context, "analysis");
|
||||
}
|
||||
var etag = string.Create(CultureInfo.InvariantCulture, $"a-{file.Length}-{file.LastWriteTimeUtc.Ticks}");
|
||||
return FileResponses.Serve(context, file, 0, file.Length, "application/json; charset=utf-8", "no-cache", etag) ?? ApiErrors.NotFound(context, "analysis");
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ namespace Titano.Server.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Follow-up work after frames arrive (BRIEF §14.4): thumbnails, proxies and light analysis of the sequence; after a
|
||||
/// proxy sent by a client or render node arrives, the thumbnails and the sequence's proxy state. Queued at background
|
||||
/// proxy sent by a client or render node arrives, the thumbnails, the sequence's proxy state and the light analysis (a
|
||||
/// frame read from its proxy is no longer preview-only, so the advisor's Auto values change). Queued at background
|
||||
/// priority once per sequence while one is still waiting, and only for kinds this server can run.
|
||||
/// </summary>
|
||||
public sealed class SequenceJobs(TitanoDatabase db, JobEngineHost jobs)
|
||||
{
|
||||
private static readonly JobKind[] AfterNewFrames = [JobKind.Thumbs, JobKind.Proxies, JobKind.LightAnalyse];
|
||||
private static readonly JobKind[] AfterProxy = [JobKind.Thumbs, JobKind.Proxies];
|
||||
private static readonly JobKind[] AfterProxy = [JobKind.Thumbs, JobKind.Proxies, JobKind.LightAnalyse];
|
||||
|
||||
private readonly SemaphoreSlim _gate = new(1, 1);
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using Titano.Core.Archiving;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Archiving;
|
||||
|
||||
namespace Titano.Server.Storage;
|
||||
|
||||
/// <summary>
|
||||
/// Proxies are files under the sequence's <c>proxies/</c> folder; a thumbnail is the JPEG byte range of its entry in
|
||||
/// <c>thumbs.pack</c>. A thumbnail made from a different original (the frame was renumbered or replaced) counts as not
|
||||
/// built yet, like a missing one.
|
||||
/// built yet, like a missing one, and so does a proxy whose capture time is another frame's, or one smaller than the
|
||||
/// archive's policy sent for a frame the server cannot decode (<see cref="ServerProxies.HasProxy"/>).
|
||||
/// </summary>
|
||||
internal sealed class ArchiveAssetLocator : IFrameAssetLocator
|
||||
{
|
||||
@@ -15,13 +17,17 @@ internal sealed class ArchiveAssetLocator : IFrameAssetLocator
|
||||
public ValueTask<AssetLocation?> LocateAsync(Archive archive, Sequence sequence, Frame frame, FrameAsset asset, CancellationToken cancellationToken)
|
||||
{
|
||||
var paths = new ArchivePaths(archive.RootPath).Sequence(sequence.Folder);
|
||||
return ValueTask.FromResult(asset == FrameAsset.Proxy ? Proxy(paths, frame) : Thumbnail(paths, frame));
|
||||
return ValueTask.FromResult(asset == FrameAsset.Proxy ? Proxy(archive, paths, frame) : Thumbnail(paths, frame));
|
||||
}
|
||||
|
||||
private static AssetLocation? Proxy(SequencePaths paths, Frame frame)
|
||||
private static AssetLocation? Proxy(Archive archive, SequencePaths paths, Frame frame)
|
||||
{
|
||||
var file = new FileInfo(paths.Proxy(frame.Index));
|
||||
return file.Exists ? new AssetLocation(file.FullName, 0, file.Length, Jpeg) : null;
|
||||
if (!file.Exists) return null;
|
||||
var own = ServerProxies.CannotDecode(frame.Format)
|
||||
? ServerProxies.HasProxy(paths, frame, ServerProxies.Spec(archive))
|
||||
: ArchiveImages.IsProxyOf(file.FullName, frame.CapturedAt, frame.Width, frame.Height, policy: null);
|
||||
return own ? new AssetLocation(file.FullName, 0, file.Length, Jpeg) : null;
|
||||
}
|
||||
|
||||
private static AssetLocation? Thumbnail(SequencePaths paths, Frame frame)
|
||||
|
||||
@@ -34,9 +34,20 @@ public static class ServerProxies
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every frame of <paramref name="sequence"/> in index order, as a manifest lists it: a proxy is there when the server
|
||||
/// built them all or one was sent for the frame; it is wanted for a frame the server cannot decode that has none
|
||||
/// (and is not missing), unless <paramref name="spec"/> is null.
|
||||
/// Whether the proxy of <paramref name="frame"/>, one the server cannot decode, is in <paramref name="folder"/>: the
|
||||
/// frame's own (<see cref="ArchiveImages.IsProxyOf"/>: one left at its index by a frame renumbered since is another
|
||||
/// photo's) and as large as <paramref name="spec"/> asks (null: the archive makes none, or its manifest cannot be read
|
||||
/// now, so the size is not judged).
|
||||
/// </summary>
|
||||
public static bool HasProxy(SequencePaths folder, Frame frame, ProxySpec? spec) =>
|
||||
ArchiveImages.IsProxyOf(folder.Proxy(frame.Index), frame.CapturedAt, frame.Width, frame.Height,
|
||||
spec is null ? null : new ProxyPolicy { LongEdge = spec.LongEdge, Quality = spec.Quality });
|
||||
|
||||
/// <summary>
|
||||
/// Every frame of <paramref name="sequence"/> in index order, as a manifest lists it. A frame the server cannot decode
|
||||
/// has its proxy when its own is there (<see cref="HasProxy"/>), whatever the sequence's built status says (frames
|
||||
/// added or renumbered since keep it until the next proxy pass), and wants one otherwise (unless it is missing or
|
||||
/// damaged, or <paramref name="spec"/> is null); any other frame has one when the server built them all.
|
||||
/// </summary>
|
||||
public static async Task<List<ManifestFrame>> FramesAsync(TitanoDatabase db, Archive archive, Sequence sequence, ProxySpec? spec,
|
||||
CancellationToken cancellationToken)
|
||||
@@ -51,9 +62,10 @@ public static class ServerProxies
|
||||
var batch = await db.Frames.ListBySequenceAsync(sequence.Id, after, Page, cancellationToken);
|
||||
foreach (var f in batch)
|
||||
{
|
||||
var sent = !proxies && CannotDecode(f.Format) && File.Exists(folder.Proxy(f.Index));
|
||||
var wanted = spec is not null && !proxies && !sent && CannotDecode(f.Format) && (f.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) == 0;
|
||||
frames.Add(new ManifestFrame(f.Id, f.Index, f.FileName, f.Size, f.Sha256 ?? string.Empty, proxies || sent, thumbs, (long)f.Flags, wanted));
|
||||
var elsewhere = CannotDecode(f.Format);
|
||||
var has = elsewhere ? HasProxy(folder, f, spec) : proxies;
|
||||
var wanted = spec is not null && elsewhere && !has && (f.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) == 0;
|
||||
frames.Add(new ManifestFrame(f.Id, f.Index, f.FileName, f.Size, f.Sha256 ?? string.Empty, has, thumbs, (long)f.Flags, wanted));
|
||||
}
|
||||
if (batch.Count < Page) return frames;
|
||||
after = batch[^1].Index;
|
||||
|
||||
Reference in new issue
Block a user