Files
Chronos/src/Chronos.Server/Storage/ArchiveModule.cs
T
Alby96andClaude Opus 5.5 efa87f68ce
CI / Build and test (push) Failing after 3m1s
CI / PostgreSQL 16 integration (push) Skipped
CI / PostgreSQL 17 integration (push) Skipped
CI / Docker image (push) Skipped
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
Release / Build, test and publish (push) Successful in 15m31s
Release / Server image (push) Successful in 1m13s
feat: owner review 2 phase 4b: mass conversion after import (#13)
Convert photos already in the archive to JPEG, TIFF-16 or Linear DNG, from the panel's Library and the desktop's Archive and Library. Each run asks Replace (same frames, originals to the trash, recoverable) or New sequence. A dry run lists what converts, what is skipped and why, size before and after, and free space; the job converts exactly the confirmed photos, resumes, and commits all or nothing per sequence. A conversion never changes what Chronos reads from a photo. Replaced originals are erased only on the archive's own word that their conversion is gone. Desktop TIFFs that WIC showed black or as noise now go to the managed reader; the Edit picker no longer spins a core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-03 10:41:50 +01:00

62 lines
3.5 KiB
C#

using Chronos.Core.Imaging.Decoders;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Housekeeping;
using Chronos.Data.Jobs;
using Chronos.Protocol;
using Chronos.Server.Configuration;
using Chronos.Server.Events;
namespace Chronos.Server.Storage;
/// <summary>
/// The archive engine behind the server (BRIEF §7, §14.4): ingest of verified uploads, lookup of proxies and
/// thumbnails, and its job handlers (scan, rebuild, verify, import, thumbnails, proxies, maintenance, the duplicates and
/// orphans reports, index backups and clean-ups with the server's own steps, the <see cref="ICleanupStep"/>s in DI, Reorganize's
/// <c>move</c> jobs and the <c>convert</c> jobs, which tell connected clients of the sequences they change or make, and check
/// their space against the space volume's free bytes, <see cref="VolumeSpace.Report"/>); a scan
/// queues thumbnails and proxies of what it indexes, as an upload does. Decoding is managed only (BRIEF §4.2). Recurring
/// work (the periodic scan, the nightly backup of an SQLite index, clean-ups) is queued by the server's system schedules
/// (<see cref="Jobs.ServerScheduleHost"/>, owner review 2, R10).
/// </summary>
public static class ArchiveModule
{
/// <summary>Name the server writes into the archive's lease files.</summary>
public static string Owner { get; } = "server@" + Environment.MachineName;
public static void Register(IServiceCollection services)
{
services.AddSingleton(sp =>
{
var options = sp.GetRequiredService<ServerOptions>();
var db = sp.GetRequiredService<ChronosDatabase>();
var events = sp.GetRequiredService<EventHub>();
var volumes = sp.GetService<VolumeSpace>();
// Photos the running job processes at once: the settings' value as it is when each sequence starts (owner review 1).
return new ArchiveService(db, new ArchiveServiceOptions
{
// A Reorganize or a conversion tells connected clients of every sequence it changed or made (BRIEF §14.3).
SequenceChanged = async (id, change, ct) =>
{
if (await db.Sequences.GetAsync(id, ct) is { } sequence)
events.Publish(new SequenceChangedEvent(id, change, sequence.FramesVersion, sequence.SettingsVersion));
},
Decoder = DecoderFactory.CreateServer(),
// Where a conversion writes (owner review 2, R7): the tighter of what the panel shows as the archive's free space
// (R2: the space path's volume) and the volume the archive's folders are on, which takes every byte it stages
// and files (on Unraid the cache, until the mover runs).
FreeSpace = volumes is null ? null : volumes.WritableFree,
Owner = Owner,
ImagesAfterScan = true,
Parallelism = () => options.Parallelism,
CleanupSteps = [.. sp.GetServices<ICleanupStep>()],
// Next to the index in the data folder, where the daily backups always went.
BackupDirectory = Path.Combine(options.DataPath, DatabaseBackups.DirectoryName),
});
});
services.AddSingleton<IArchiveIngest>(sp => sp.GetRequiredService<ArchiveService>().Ingest);
services.AddSingleton<IJobHandlerProvider>(sp => sp.GetRequiredService<ArchiveService>());
services.AddSingleton<IFrameAssetLocator, ArchiveAssetLocator>();
}
}