feat: owner review 2 phase 3: Library on the web panel, photo trash and web upload (#11)
CI / Build and test (push) Successful in 7m25s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
CI / PostgreSQL 16 integration (push) Successful in 5m20s
CI / PostgreSQL 17 integration (push) Successful in 5m22s
CI / Docker image (push) Successful in 50s
Release / Build, test and publish (push) Successful in 12m1s
Release / Server image (push) Successful in 1m26s

- Web panel Library: browse, view, delete sequences and photos, mass operations (analyse, proxies, thumbnails, verify, retag, delete, CSV). It never edits the video.
- Photo trash with tombstones (migration 0008): crash-safe delete and restore, hash-checked restore with reasons, and emptying only by an explicit fingerprinted job. Sync and uploads keep deleted photos deleted; an explicit "Upload again" brings one back.
- Upload from the web panel: in-house SHA-256 in a worker with a fail-closed self-test, capture time from EXIF, chunked, resumable; no folders.
- Desktop trash dialog with photo entries and Empty.
- Admin files are revalidated (no-cache + ETag).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #11.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-10-27 15:08:39 +01:00
1 parent af9eeaab9b
commit 9aa818ed47
283 files changed
+24922 -293

No files matched your search

+72 -15
View File
@@ -48,11 +48,27 @@ public sealed record DeletePlan(IReadOnlyList<DeleteStep> Steps, IReadOnlyList<B
public int Renders => Steps.Sum(s => s.Sequence.RenderedCount);
}
/// <summary>A deleted sequence kept in an archive's trash, as <see cref="SequenceTrash.ListAsync"/> lists it.</summary>
/// <param name="Name">Folder name inside the trash; pass it to <see cref="SequenceTrash.RestoreAsync"/>.</param>
/// <summary>What a trash entry holds (owner review 2, R6).</summary>
public enum TrashKind
{
/// <summary>A whole sequence folder (<see cref="SequenceTrash"/>).</summary>
Sequence,
/// <summary>Photos deleted from a sequence (<see cref="FrameTrash"/>).</summary>
Photos,
/// <summary>Originals a conversion replaced (a later phase): erased only while their replacements still match.</summary>
Replaced,
}
/// <summary>An entry of an archive's trash, as <see cref="SequenceTrash.ListAsync"/> lists it: a deleted sequence or deleted photos.</summary>
/// <param name="Name">The entry's name: the folder name inside the trash for a sequence, <c>photos-</c> and the folder name for
/// photos; pass it to <see cref="ArchiveService.RestoreEntryAsync"/>.</param>
/// <param name="Title">The sequence's title (the one the photos came from).</param>
/// <param name="Folder">Archive-relative folder the sequence came from (and returns to when it is free).</param>
/// <param name="Frames">Photos the entry holds.</param>
public sealed record TrashEntry(Guid ArchiveId, string Name, Guid SequenceId, string Title, string Folder, int Frames, int Files, long Bytes,
DateTimeOffset DeletedAt, string? DeletedBy);
DateTimeOffset DeletedAt, string? DeletedBy, TrashKind Kind = TrashKind.Sequence);
/// <summary>The plan no longer matches the index or the jobs (a sequence moved, vanished or got busy since it was made); nothing was deleted.</summary>
public sealed class StaleDeletePlanException(Guid sequenceId) : InvalidOperationException(Loc.L("Archive.Error.StalePlan"))
@@ -66,6 +82,12 @@ public sealed class SequenceInLibraryException(Guid sequenceId, string title) :
public Guid SequenceId { get; } = sequenceId;
}
/// <summary>
/// No file of a photo entry matches its record any more (each one re-hashed); the entry stays as it is and nothing moved.
/// A restore's <see cref="InvalidDataException"/> is about a sidecar instead (damaged, or another sequence's).
/// </summary>
public sealed class TrashMismatchException() : IOException(Loc.L("Archive.Error.TrashMismatch"));
/// <summary>
/// Deleting sequences without erasing anything (BRIEF §0.2 rule 8, §12.2, §12.5): <see cref="PlanAsync"/> is the dry
/// run; <see cref="DeleteAsync"/> moves each sequence folder whole — originals, proxies, exports and its sidecars — into
@@ -75,7 +97,7 @@ public sealed class SequenceInLibraryException(Guid sequenceId, string title) :
/// moved, its index step runs to the end whatever the caller cancels; when that step fails, the folder moves back, so
/// the trash and the index never disagree.
/// </summary>
public sealed class SequenceTrash
public sealed partial class SequenceTrash
{
/// <summary>Folder of the trash inside the archive's <c>.chronos</c>.</summary>
public const string FolderName = "trash";
@@ -153,6 +175,10 @@ public sealed class SequenceTrash
/// <param name="progress">Sequences moved so far.</param>
/// <exception cref="StaleDeletePlanException">A sequence moved, vanished or got busy since the plan; nothing was deleted.</exception>
/// <exception cref="ArchiveOfflineException">An archive is offline; sequences before it are in the trash.</exception>
/// <exception cref="LeaseUnavailableException">A sequence, or the trash entry of a restore into it a crash interrupted, is
/// busy; sequences before it are in the trash.</exception>
/// <exception cref="InvalidDataException">The sidecar of a sequence with an interrupted journal is damaged; sequences
/// before it are in the trash.</exception>
public async Task<IReadOnlyList<TrashEntry>> DeleteAsync(DeletePlan plan, string? deletedBy = null, IProgress<int>? progress = null,
CancellationToken cancellationToken = default)
{
@@ -168,7 +194,10 @@ public sealed class SequenceTrash
return entries;
}
/// <summary>The sequences in an archive's trash, newest first; records whose folder is gone are left out.</summary>
/// <summary>
/// The entries of an archive's trash, newest first: deleted sequences (<c>trash/*.json</c>) and deleted photos
/// (<c>trash/photos/*.json</c>); records whose folder is gone are left out.
/// </summary>
public async Task<IReadOnlyList<TrashEntry>> ListAsync(Archive archive, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(archive);
@@ -184,7 +213,8 @@ public sealed class SequenceTrash
if (!Directory.Exists(Path.Combine(trash, name)) || ReadRecord(path) is not { } record) continue;
entries.Add(Entry(archive.Id, name, record));
}
return entries.OrderByDescending(e => e.DeletedAt).ToList();
entries.AddRange(FrameTrash.List(archive, cancellationToken));
return entries.OrderByDescending(e => e.DeletedAt).ThenBy(e => e.Name, StringComparer.Ordinal).ToList();
}, cancellationToken).ConfigureAwait(false);
}
@@ -215,14 +245,18 @@ public sealed class SequenceTrash
.ToHashSet(StringComparer.OrdinalIgnoreCase);
var folder = FreeFolder(paths, record.Sequence.Folder, locations);
var sequence = paths.Sequence(folder);
// The entry's lease keeps an emptying of the trash out meanwhile.
using (await LeaseFile.AcquireAsync(paths.LocksDirectory, EntryLease(Path.GetFileName(name)), _writer.Options.Owner, _writer.Options.LeaseWait,
_writer.Options.LeaseDuration, cancellationToken).ConfigureAwait(false))
await using (await _writer.LockAsync(paths, id, cancellationToken).ConfigureAwait(false))
{
if (!Directory.Exists(source)) throw new DirectoryNotFoundException($"{name} is not in the trash of {archive.Name}.");
cancellationToken.ThrowIfCancellationRequested();
Directory.CreateDirectory(Path.GetDirectoryName(sequence.Folder)!);
Directory.Move(source, sequence.Folder);
try
{
var manifest = File.Exists(sequence.ManifestPath) ? SequenceWriter.ReadLocked(sequence, id) : Adopt(sequence, record.Sequence, cancellationToken);
var manifest = File.Exists(sequence.ManifestPath) ? SequenceWriter.ReadLocked(sequence, id) : Adopt(sequence, record, cancellationToken);
// The index step runs to the end once it starts: a cancel cannot leave half the rows written.
await IndexAsync(archive, sequence, manifest, record, CancellationToken.None).ConfigureAwait(false);
}
@@ -242,10 +276,12 @@ public sealed class SequenceTrash
/// <summary>
/// A sidecar for a restored folder that lost its own, built as a scan adopts a folder: its frames get new ids, the
/// sequence keeps its id, and the title, tags, rating and notes of the record go into it so sidecar and index agree.
/// sequence keeps its id, and the title, tags, rating, notes and tombstones of the record go into it so sidecar and
/// index agree, and a photo deleted before stays deleted.
/// </summary>
private SequenceManifest Adopt(SequencePaths sequence, Sequence kept, CancellationToken cancellationToken)
private SequenceManifest Adopt(SequencePaths sequence, TrashRecord record, CancellationToken cancellationToken)
{
var kept = record.Sequence;
var built = SequenceAdopter.Build(kept.Id, sequence, _writer.Options.Owner, cancellationToken);
var manifest = built with
{
@@ -254,6 +290,7 @@ public sealed class SequenceTrash
Rating = kept.Rating,
Notes = kept.Notes,
Versions = built.Versions with { Settings = System.Math.Max(built.Versions.Settings, kept.SettingsVersion) },
Removed = record.Removed is { Count: > 0 } removed ? removed : null,
};
Directory.CreateDirectory(sequence.MetaDirectory);
ManifestStore.WriteSequence(sequence.ManifestPath, manifest);
@@ -269,6 +306,7 @@ public sealed class SequenceTrash
await using var tx = await _db.BeginAsync(cancellationToken).ConfigureAwait(false);
await tx.Sequences.UpsertAsync(SequenceMapping.ToSequence(manifest, archive.Id, sequence, kept), cancellationToken).ConfigureAwait(false);
await tx.Frames.SyncSequenceAsync(deleted.Id, SequenceMapping.ToFrames(manifest, sequence), cancellationToken).ConfigureAwait(false);
await tx.FrameRemovals.SyncSequenceAsync(deleted.Id, SequenceMapping.ToRemovals(manifest), cancellationToken).ConfigureAwait(false);
foreach (var key in manifest.SessionKeys) await tx.Sequences.MapSessionKeyAsync(archive.Id, key, deleted.Id, cancellationToken).ConfigureAwait(false);
foreach (var render in record.Renders)
{
@@ -335,12 +373,25 @@ public sealed class SequenceTrash
var folder = paths.Sequence(sequence.Folder);
if (!Directory.Exists(folder.Folder) || (File.Exists(folder.ManifestPath) && SidecarId(folder.ManifestPath) != sequence.Id))
throw new StaleDeletePlanException(sequence.Id);
// A photo deletion, a restore from the trash or an ingest a crash interrupted is settled first, as any writer does
// (SequenceWriter.ReadLocked): neither its journal nor the files it moved travel into this entry, where emptying it
// would erase them while their own entry still lists them. A restore whose entry is busy keeps the folder here.
var (files, bytes) = (step.Files, step.Bytes);
if (File.Exists(folder.ManifestPath) && (File.Exists(folder.RemovalJournalPath) || File.Exists(folder.RestoreJournalPath)
|| File.Exists(folder.IngestJournalPath)))
{
SequenceWriter.ReadLocked(folder, sequence.Id);
FrameTrash.EnsureSettled(folder);
// Files came back into the folder, or left it: the record counts what moves.
(files, bytes) = Measure(folder.Folder, cancellationToken);
}
var trash = TrashDirectory(paths);
Directory.CreateDirectory(trash);
var name = EntryName(paths, sequence.Id, new HashSet<string>());
var target = Path.Combine(trash, name);
var record = new TrashRecord(row, await _db.Renders.ListBySequenceAsync(sequence.Id, cancellationToken).ConfigureAwait(false), step.Files,
step.Bytes, DateTimeOffset.UtcNow, deletedBy);
var tombstones = await _db.FrameRemovals.ListBySequenceAsync(sequence.Id, cancellationToken).ConfigureAwait(false);
var record = new TrashRecord(row, await _db.Renders.ListBySequenceAsync(sequence.Id, cancellationToken).ConfigureAwait(false), files,
bytes, DateTimeOffset.UtcNow, deletedBy, tombstones.Count > 0 ? SequenceMapping.ToTombstones(tombstones) : null);
cancellationToken.ThrowIfCancellationRequested();
// The record first: a crash before the move leaves a record without a folder, which the listing ignores.
var recordPath = target + RecordExtension;
@@ -366,7 +417,7 @@ public sealed class SequenceTrash
if (MoveBack(target, folder.Folder)) File.Delete(recordPath);
throw;
}
Log.Info("archive", $"{row.DisplayTitle} moved to the trash: {row.Folder} → {name} ({step.Files} files, {step.Bytes} bytes)");
Log.Info("archive", $"{row.DisplayTitle} moved to the trash: {row.Folder} → {name} ({files} files, {bytes} bytes)");
return Entry(archive.Id, name, record);
}
}
@@ -426,7 +477,7 @@ public sealed class SequenceTrash
/// archives of archive-wide ones (scan, rebuild, import, maintenance, a verify of everything). An import's folders
/// are known only to its plan, so it holds its whole archive; a verify of named sequences holds only those.
/// </summary>
private async Task<IReadOnlySet<Guid>> BusyAsync(CancellationToken cancellationToken)
internal async Task<IReadOnlySet<Guid>> BusyAsync(CancellationToken cancellationToken)
{
var busy = new HashSet<Guid>();
foreach (var state in new[] { JobState.Running, JobState.Paused })
@@ -545,10 +596,16 @@ public sealed class SequenceTrash
private sealed record ArchiveContext(ArchivePaths Paths, ArchiveAvailability Availability, IReadOnlyList<Repositories.SequenceLocation> Locations);
}
/// <summary>What the trash keeps next to a deleted folder: the index row and renders the sidecar does not carry.</summary>
internal sealed record TrashRecord(Sequence Sequence, IReadOnlyList<Render> Renders, int Files, long Bytes, DateTimeOffset DeletedAt, string? DeletedBy);
/// <summary>
/// What the trash keeps next to a deleted folder: the index row and renders the sidecar does not carry, and the
/// sequence's tombstones, which a sidecar rebuilt from the photos on restore takes back.
/// </summary>
internal sealed record TrashRecord(Sequence Sequence, IReadOnlyList<Render> Renders, int Files, long Bytes, DateTimeOffset DeletedAt, string? DeletedBy,
IReadOnlyList<RemovedPhoto>? Removed = null);
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
UseStringEnumConverter = true, IgnoreReadOnlyProperties = true)]
[JsonSerializable(typeof(TrashRecord))]
[JsonSerializable(typeof(PhotoTrashRecord))]
[JsonSerializable(typeof(FrameRestoreJournal))]
internal sealed partial class TrashJson : JsonSerializerContext;