fix(proxies): ask again for preview-sized proxies and refuse unwanted ones

Earlier versions made the server's proxies of HEIF frames from their embedded
previews. Those carry the frame's capture time, so the proxy pass kept them
and the sequence stayed marked as having all its proxies; renders and
analysis then read thumbnail-sized files and no client or render node was
asked for a real one. The proxy pass now treats a proxy whose long edge falls
short of the policy's for the frame (its own size when smaller, a tenth of
slack, frames of unknown size not judged) as stale, and the server refuses
such a proxy when one is sent (422 proxy_too_small).

PUT /api/v1/frames/{id}/proxy also took a proxy of a frame the server
decodes itself, replacing its own proxy with any JPEG of the right capture
time; it now answers 422 proxy_not_wanted for those and for frames missing or
damaged. Its follow-up jobs are queued even when the sender disconnects once
the proxy is filed.

A render node cleared the server's Undecodable flag on every frame, so a
damaged frame the server's own render skips was downloaded and failed the
node's job. Only a format the server cannot decode and the node can loses the
flag now; other undecodable originals are neither fetched nor rendered unless
read from their proxy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 11:06:42 +00:00
1 parent 9588ed7f4b
commit f215b99ca5
9 files changed
+112 -25

No files matched your search

+13 -5
View File
@@ -58,10 +58,12 @@ public static class FileEndpoints
}
/// <summary>
/// Files the body (a JPEG made from the original, its Exif capture time the frame's, at most
/// <see cref="ArchiveImages.MaxProxyBytes"/>) as the frame's proxy; the sequence's thumbnails and proxy state follow as
/// background jobs. 204; 413 <c>too_large</c>, 422 <c>invalid_proxy</c> or <c>proxy_mismatch</c>, 409
/// <c>proxies_disabled</c>, 503 <c>archive_offline</c>.
/// 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
/// 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>
private static async Task<IResult> StoreProxyAsync(HttpContext context, Guid id, TitanoDatabase db, ServerArchive archive,
[FromServices] ArchiveService? archives, SequenceJobs follow)
@@ -69,6 +71,9 @@ public static class FileEndpoints
var ct = context.RequestAborted;
if (await db.Frames.GetAsync(id, ct) is not { } frame || await db.Sequences.GetAsync(frame.SequenceId, ct) is not { } sequence)
return ApiErrors.NotFound(context, "frame");
// A proxy replaces the server's own of an original it decodes, which renders and remote views would then show.
if (!ServerProxies.CannotDecode(frame.Format) || (frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0)
return ApiErrors.Result(context, StatusCodes.Status422UnprocessableEntity, "proxy_not_wanted");
if (context.Request.ContentLength is > ArchiveImages.MaxProxyBytes) return ApiErrors.Result(context, StatusCodes.Status413PayloadTooLarge, "too_large");
// Proxies are larger than the JSON bodies Kestrel is limited to; reading past this answers 413.
if (context.Features.Get<IHttpMaxRequestBodySizeFeature>() is { IsReadOnly: false } limit) limit.MaxRequestBodySize = ArchiveImages.MaxProxyBytes;
@@ -93,8 +98,11 @@ public static class FileEndpoints
return ApiErrors.Result(context, StatusCodes.Status422UnprocessableEntity, "invalid_proxy");
case ProxyStoreResult.WrongFrame:
return ApiErrors.Result(context, StatusCodes.Status422UnprocessableEntity, "proxy_mismatch");
case ProxyStoreResult.TooSmall:
return ApiErrors.Result(context, StatusCodes.Status422UnprocessableEntity, "proxy_too_small");
}
await follow.ProxyArrivedAsync(sequence, ct);
// The proxy is filed: its follow-up is queued even when the sender is gone by now.
await follow.ProxyArrivedAsync(sequence, CancellationToken.None);
return Results.NoContent();
}
+2 -6
View File
@@ -1,6 +1,5 @@
using Titano.Core.Archiving;
using Titano.Core.Imaging;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Model;
using Titano.Data;
using Titano.Data.Archiving;
@@ -17,11 +16,8 @@ public static class ServerProxies
{
private const int Page = 1000;
/// <summary>The server's decoders (BRIEF §4.2: managed only).</summary>
private static readonly ImageDecoder Decoder = DecoderFactory.CreateServer();
/// <summary>The server takes this format's pixels from proxies made elsewhere.</summary>
public static bool CannotDecode(ImageFileFormat format) => ArchiveImages.NeedsProxy(Decoder, format);
/// <summary>The server takes this format's pixels from proxies made elsewhere (its decoders are managed only, BRIEF §4.2).</summary>
public static bool CannotDecode(ImageFileFormat format) => ArchiveImages.ServerNeedsProxy(format);
/// <summary>How proxies of the archive are made; null when it makes none (or its manifest cannot be read now).</summary>
public static ProxySpec? Spec(Archive archive)