Files
Chronos/src/Chronos.Server/Storage/ServerProxies.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

75 lines
3.9 KiB
C#

using Chronos.Core.Archiving;
using Chronos.Core.Imaging;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Protocol;
namespace Chronos.Server.Storage;
/// <summary>
/// Proxies the server asks for (BRIEF §2.3, §8.5): it decodes with managed decoders only, so the frames whose originals
/// it cannot decode (HEIF) get their proxies from a Windows client or render node, made as the archive's proxy policy
/// says. Manifests (sync and render nodes) list every frame with its flags and whether its proxy is wanted.
/// </summary>
public static class ServerProxies
{
private const int Page = 1000;
/// <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)
{
try
{
var policy = ManifestStore.ReadArchive(new ArchivePaths(archive.RootPath).ManifestPath).ProxyPolicy;
return policy.LongEdge == ProxyPolicy.Disabled ? null : new ProxySpec(policy.LongEdge, policy.Quality);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
{
return null;
}
}
/// <summary>
/// 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(ChronosRepositories db, Archive archive, Sequence sequence, ProxySpec? spec,
CancellationToken cancellationToken)
{
var proxies = sequence.Status.HasFlag(SequenceStatus.ProxiesBuilt);
var thumbs = sequence.Status.HasFlag(SequenceStatus.ThumbsBuilt);
var folder = new ArchivePaths(archive.RootPath).Sequence(sequence.Folder);
var frames = new List<ManifestFrame>(sequence.FrameCount);
var after = -1;
while (true)
{
var batch = await db.Frames.ListBySequenceAsync(sequence.Id, after, Page, cancellationToken);
foreach (var f in batch)
{
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;
}
}
}