feat(archive): photo delete, tombstones, trash kinds and emptying, library API

Owner review 2, R6: the web panel manages the library without editing it, so
the engine and the server must delete single photos safely, keep them out of
sync afterwards, and let an administrator restore or finally erase the trash.

- Migration 0008: frame_removals (tombstones by sequence and SHA-256, reason,
  replacement); the sidecar gains "removed" (omitted when empty) and frames a
  reserved "source"; the indexer writes the tombstones on every sync, so a
  rebuild keeps them, and drops a hero frame that is gone.
- FrameTrash: dry run (busy, frames changed, offline, would empty), delete under
  the sequence lease with a write-ahead journal that the next writer undoes
  after a crash, files to trash/photos/<seq>-<time>/originals with a record,
  sidecar without the frames plus tombstones, index sync clearing analyses,
  thumbnails and proxies, proxies renamed to follow their frames, follow-up
  jobs. Restore re-hashes every file, keeps mismatches in the trash, puts the
  same frame records back and drops their tombstones, or files the photos into
  a new sequence through the ingest when theirs is gone.
- Project positions on vanished photos are translated by photo and wait as
  pending frames, so they come back with a restore.
- Trash entries have a kind (sequence, photos, replaced); emptying is a dry run
  with a fingerprint and a new EmptyTrash job (18) that erases exactly the
  planned entries, refuses a stale plan and erases replaced originals only
  while their replacements still hash right.
- Sync honours tombstones: nothing one side deleted is offered back, local
  files are never deleted, replaced photos count as their replacement; the
  server answers an upload of a tombstoned SHA-256 as already there.
- Server: sequence thumbnail, photo delete, bulk delete/retag/jobs, trash
  list/restore/empty endpoints with their error messages; a verify of
  sequences now targets their archive (POST /jobs failed before).
- Desktop trash dialog lists photo entries and empties the trash after a
  typed confirmation through the same job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 35bb56690a1d69eae57153d036e1409201cd73f7)
This commit is contained in:
Alby96 committed 2026-10-27 10:49:34 +01:00
1 parent 4b9ba04fe4
commit 51782a3ada
63 files changed
+3303 -60

No files matched your search

@@ -242,6 +242,9 @@
<DockPanel Grid.Row="3" Margin="0,16,0,0">
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Close}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsCancel="True"
IsDefault="True" MinWidth="96" />
<!-- Erasing for good: a dry run and a typed confirmation first, never the default button. -->
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Trash.EmptyAction}" Command="{Binding EmptyCommand}" ToolTip="{Binding EmptyToolTip}"
ToolTipService.ShowOnDisabled="True" MinWidth="96" Margin="0,0,8,0" />
<Grid Margin="0,0,12,0">
<TextBlock Style="{StaticResource Text.Live}" Text="{Binding BusyText}" infra:LiveRegion.Text="{Binding BusyText}" />
<ui:StatusGlyph Style="{StaticResource Status.DialogError}" />
+8 -3
View File
@@ -32,14 +32,19 @@ public static class SampleReports
? new OrphanReport([], [], [])
: new OrphanReport([new SequenceOrphans(sequences[2].Folder, ["IMG_0412.CR2", "IMG_0413.CR2"], [])], [sequences[3]], ["2024/2024-12-31 Unsorted"]);
/// <summary>The trash dialog's rows: the first two sample sequences, deleted an hour and a day ago (nothing moves on disk).</summary>
/// <summary>
/// The trash dialog's rows: the first sample sequence, deleted an hour ago, and 24 photos of the second, deleted a day ago
/// (nothing moves on disk).
/// </summary>
public static IReadOnlyList<TrashEntry> Trash(Guid archiveId, IReadOnlyList<SequenceLocation> sequences)
{
var now = SampleData.Now;
return
[
.. sequences.Take(2).Select((s, i) => new TrashEntry(archiveId, s.Id.ToString("N"), s.Id, s.Title ?? s.Folder, s.Folder, 1_200 * (i + 1), 1_206 * (i + 1),
31_457_280L * 1_200 * (i + 1), now.AddHours(-1 - (23 * i)), "alberto")),
.. sequences.Take(1).Select(s => new TrashEntry(archiveId, s.Id.ToString("N"), s.Id, s.Title ?? s.Folder, s.Folder, 1_200, 1_206,
31_457_280L * 1_200, now.AddHours(-1), "alberto")),
.. sequences.Skip(1).Take(1).Select(s => new TrashEntry(archiveId, FrameTrash.EntryPrefix + s.Id.ToString("N") + "-20260927180400", s.Id,
s.Title ?? s.Folder, s.Folder, 24, 24, 31_457_280L * 24, now.AddHours(-24), "alberto", TrashKind.Photos)),
];
}
+119 -12
View File
@@ -1,3 +1,4 @@
using System.Globalization;
using System.IO;
using System.Windows.Input;
using Chronos.App.Infrastructure;
@@ -6,18 +7,24 @@ using Chronos.Core.Diagnostics;
using Chronos.Core.Localization;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Jobs;
using Chronos.Ui.Mvvm;
namespace Chronos.App.Archiving;
/// <summary>One deleted sequence in the trash: what it was, when it went, and Restore.</summary>
/// <summary>One entry of the trash: a deleted sequence or photos deleted from one, when it went, and Restore.</summary>
public sealed class TrashRowViewModel(TrashEntry entry, ICommand restore)
{
public TrashEntry Entry { get; } = entry;
public string Title => Entry.Title;
/// <summary>"3,600 photos · 96.2 GB · 2026/2026-09-28 Canon EOS R5" (the folder left to right in every language).</summary>
public string Detail => string.Join(Loc.Separator, Loc.Plural("Shell.Status.Photos", Entry.Frames), Formatting.Bytes(Entry.Bytes), Formatting.LeftToRight(Entry.Folder));
/// <summary>"Photos", "Sequence": what the entry holds.</summary>
public string KindText => TrashEmptyPlans.KindText(Entry.Kind);
/// <summary>"Photos · 12 photos · 340 MB · 2026/2026-09-28 Canon EOS R5" (the folder left to right in every language).</summary>
public string Detail => string.Join(Loc.Separator, KindText, Loc.Plural("Shell.Status.Photos", Entry.Frames), Formatting.Bytes(Entry.Bytes),
Formatting.LeftToRight(Entry.Folder));
/// <summary>"Deleted 02/10/2026 18:04".</summary>
public string DeletedText => Loc.L("Archive.Trash.Deleted", Formatting.Date(Entry.DeletedAt) + " " + Formatting.TimeOfDay(Entry.DeletedAt));
@@ -25,23 +32,71 @@ public sealed class TrashRowViewModel(TrashEntry entry, ICommand restore)
public ICommand RestoreCommand { get; } = restore;
}
/// <summary>The words of an emptying of the trash (<see cref="TrashEmptyPlan"/>): the destructive, typed confirmation.</summary>
public static class TrashEmptyPlans
{
/// <summary>"Photos", "Sequence", "Replaced".</summary>
public static string KindText(TrashKind kind) => Loc.L("Archive.Trash.Kind." + kind);
/// <summary>The confirmation of erasing the planned entries for good; null when the plan holds none.</summary>
public static ConfirmRequest? Request(TrashEmptyPlan plan)
{
ArgumentNullException.ThrowIfNull(plan);
if (plan.Entries.Count == 0) return null;
var count = plan.Entries.Count.ToString(CultureInfo.InvariantCulture);
var lines = plan.Entries.Take(DeletePlans.ListedLines).Select(e => Loc.L("Archive.Delete.Line", e.Title,
KindText(e.Kind) + Loc.Separator + Loc.Plural("Shell.Status.Photos", e.Frames), Formatting.Bytes(e.Bytes))).ToList();
if (plan.Entries.Count > DeletePlans.ListedLines) lines.Add(Loc.Plural("Archive.Delete.More", plan.Entries.Count - DeletePlans.ListedLines));
return new ConfirmRequest
{
Heading = Loc.Plural("Archive.Trash.EmptyHeading", plan.Entries.Count),
Message = Loc.L("Archive.Trash.EmptyMessage", Loc.Plural("Shell.Status.Photos", plan.Photos), Loc.Plural("Archive.Delete.Files", plan.Files),
Formatting.Bytes(plan.Bytes)),
Detail = string.Join(Environment.NewLine, lines),
IsDetailMonospaced = false,
DetailToolTip = Loc.L("Tooltips.Archive.TrashEmptyPlan"),
SafeText = Loc.L("Archive.Delete.Keep"),
SafeToolTip = Loc.L("Tooltips.Archive.DeleteKeep"),
ActionText = Loc.L("Archive.Trash.Erase"),
ActionToolTip = Loc.Plural("Tooltips.Archive.TrashErase", plan.Entries.Count),
IsDestructive = true,
TypedConfirmation = count,
TypedPrompt = Loc.L("Archive.Delete.Type", count),
};
}
}
/// <summary>
/// The archive's trash (BRIEF §0.2 rule 8): every sequence deleted from the Library or the Archive manager, newest
/// first, each restorable into its folder (or a free one next to it) with its ids, settings and renders.
/// The archive's trash (BRIEF §0.2 rule 8, §12.5): every sequence deleted from the Library or the Archive manager and the
/// photos deleted from sequences (owner review 2, R6), newest first, each restorable — a sequence into its folder (or a
/// free one next to it) with its ids, settings and renders, photos into their sequence after their files are re-hashed.
/// Empty… erases the entries for good: a dry run, a typed confirmation, then the <c>EmptyTrash</c> job, which refuses when
/// the trash changed since.
/// </summary>
public sealed class TrashDialogViewModel : ArchiveDialogViewModel
{
private readonly ArchiveService _archives;
private readonly Core.Model.Archive _archive;
private readonly Func<Task> _restored;
private readonly Func<ConfirmRequest, bool>? _confirm;
private readonly Func<ArchiveJobRequest, Task>? _enqueue;
private readonly JobEngine? _followUps;
private IReadOnlyList<TrashRowViewModel> _rows = [];
public TrashDialogViewModel(ArchiveService archives, Core.Model.Archive archive, Func<Task> restored, Action<ArchiveDialogViewModel> close)
/// <param name="confirm">Asks the typed confirmation of an emptying (null: the trash cannot be emptied here).</param>
/// <param name="enqueue">Queues the emptying job and says so (null: the trash cannot be emptied here).</param>
/// <param name="followUps">The engine that takes the analyses and images restored photos need again.</param>
public TrashDialogViewModel(ArchiveService archives, Core.Model.Archive archive, Func<Task> restored, Action<ArchiveDialogViewModel> close,
Func<ConfirmRequest, bool>? confirm = null, Func<ArchiveJobRequest, Task>? enqueue = null, JobEngine? followUps = null)
: base(close)
{
_archives = archives;
_archive = archive;
_restored = restored;
_confirm = confirm;
_enqueue = enqueue;
_followUps = followUps;
EmptyCommand = new AsyncRelayCommand(EmptyAsync, () => CanEmpty);
}
public string Heading => Loc.L("Archive.Trash.Heading", _archive.Name);
@@ -55,6 +110,8 @@ public sealed class TrashDialogViewModel : ArchiveDialogViewModel
OnPropertyChanged(nameof(IsEmpty));
OnPropertyChanged(nameof(HasRows));
OnPropertyChanged(nameof(SummaryText));
OnPropertyChanged(nameof(EmptyToolTip));
CommandManager.InvalidateRequerySuggested();
}
}
@@ -63,9 +120,17 @@ public sealed class TrashDialogViewModel : ArchiveDialogViewModel
/// <summary>The list shows; an empty trash is its summary sentence alone.</summary>
public bool HasRows => _rows.Count > 0;
/// <summary>"3 sequences · 182 GB", or "The trash is empty".</summary>
/// <summary>"3 entries · 182 GB", or "The trash is empty".</summary>
public string SummaryText => _rows.Count == 0 ? Loc.L("Archive.Trash.Empty")
: Loc.Plural("Shell.Status.Sequences", _rows.Count) + Loc.Separator + Formatting.Bytes(_rows.Sum(r => r.Entry.Bytes));
: Loc.Plural("Archive.Trash.Entries", _rows.Count) + Loc.Separator + Formatting.Bytes(_rows.Sum(r => r.Entry.Bytes));
/// <summary>Empty…: the dry run, the typed confirmation, then the job.</summary>
public ICommand EmptyCommand { get; }
/// <summary>Emptying is offered here, and there is something to erase.</summary>
public bool CanEmpty => !IsBusy && HasRows && _confirm is not null && _enqueue is not null;
public string EmptyToolTip => HasRows ? Loc.L("Tooltips.Archive.TrashEmpty") : Loc.L("Archive.Trash.Empty");
/// <summary>Reads the trash of the archive (off the UI thread).</summary>
public async Task LoadAsync()
@@ -75,7 +140,7 @@ public sealed class TrashDialogViewModel : ArchiveDialogViewModel
try
{
var entries = await Task.Run(() => _archives.ListTrashAsync(_archive.Id));
Rows = [.. entries.Select(e => new TrashRowViewModel(e, new AsyncRelayCommand(() => RestoreAsync(e), () => !IsBusy)))];
Rows = [.. entries.Select(Row)];
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException or ArgumentException)
{
@@ -92,6 +157,8 @@ public sealed class TrashDialogViewModel : ArchiveDialogViewModel
public void Show(IReadOnlyList<TrashEntry> entries) =>
Rows = [.. entries.Select(e => new TrashRowViewModel(e, new AsyncRelayCommand(() => Task.CompletedTask)))];
private TrashRowViewModel Row(TrashEntry entry) => new(entry, new AsyncRelayCommand(() => RestoreAsync(entry), () => !IsBusy));
private async Task RestoreAsync(TrashEntry entry)
{
ClearError();
@@ -99,10 +166,19 @@ public sealed class TrashDialogViewModel : ArchiveDialogViewModel
BusyText = Loc.L("Archive.Trash.Restoring", entry.Title);
try
{
await Task.Run(() => _archives.RestoreAsync(entry.ArchiveId, entry.Name));
Log.Info("archive", $"{entry.Title} restored from the trash");
Rows = [.. _rows.Where(r => r.Entry != entry)];
var result = await Task.Run(() => _archives.RestoreEntryAsync(entry.ArchiveId, entry.Name, _followUps));
Log.Info("archive", $"{entry.Title} restored from the trash ({entry.Kind}, {result.Photos} photo(s), {result.Kept.Count} kept)");
BusyText = null;
if (result.Kept.Count > 0)
{
// Files that no longer match their record stay in the trash: the entry stays, with what is left.
await LoadAsync();
ShowError(new InvalidDataException(Loc.Plural("Archive.Trash.KeptFiles", result.Kept.Count)));
}
else
{
Rows = [.. _rows.Where(r => r.Entry != entry)];
}
await _restored();
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or SequenceInLibraryException or NewerFormatException
@@ -117,4 +193,35 @@ public sealed class TrashDialogViewModel : ArchiveDialogViewModel
BusyText = null;
}
}
/// <summary>
/// Empty…: measures every entry (the dry run), asks to type how many entries go, and queues the job that erases exactly
/// those; the dialog closes, and the job says how it ended.
/// </summary>
private async Task EmptyAsync()
{
if (_confirm is null || _enqueue is null) return;
ClearError();
IsBusy = true;
BusyText = Loc.L("Archive.Trash.Checking");
TrashEmptyPlan plan;
try
{
plan = await Task.Run(() => _archives.PlanEmptyTrashAsync(_archive.Id));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException or ArgumentException)
{
Log.Warning("archive", "The dry run of emptying the trash failed", ex);
ShowError(ex);
return;
}
finally
{
IsBusy = false;
BusyText = null;
}
if (TrashEmptyPlans.Request(plan) is not { } request || !_confirm(request)) return;
await _enqueue(ArchiveJobs.EmptyTrash(_archive, plan));
Close();
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ public static class JobNotices
private static bool Announces(JobKind kind) =>
kind is JobKind.Render or JobKind.DeepAnalyse or JobKind.Verify or JobKind.Rebuild or JobKind.Maintenance or JobKind.UploadCommit
or JobKind.Move or JobKind.Adopt;
or JobKind.Move or JobKind.Adopt or JobKind.EmptyTrash;
/// <summary>
/// Work that keeps the index and its previews current: the next run repeats it, the Archive screen shows what is missing.
+6 -1
View File
@@ -782,11 +782,16 @@ public sealed class ArchiveViewModel : SectionViewModel
public async Task OpenTrashAsync()
{
if (Services.Archives is not { } archives || _archive is not { } archive) return;
var engine = Services.Engine;
var dialog = new TrashDialogViewModel(archives, archive, async () =>
{
await LoadAsync();
await Shell.Library.RefreshAsync();
}, CloseDialog);
}, CloseDialog, Services.Dialogs.Confirm, engine is null ? null : async request =>
{
await engine.EnqueueAsync(request);
Queued(request.Kind, archive.Name);
}, engine);
OpenDialog(dialog);
await dialog.LoadAsync();
}
@@ -1130,7 +1130,7 @@ public sealed class SettingsViewModel : SectionViewModel
[
JobKind.Render, JobKind.Import, JobKind.Download, JobKind.UploadCommit, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse,
JobKind.DeepAnalyse, JobKind.Thumbs, JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
JobKind.Backup, JobKind.Cleanup,
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash,
];
/// <summary>Stores <paramref name="level"/> for <paramref name="kind"/>, keeping only the levels that differ from the defaults.</summary>