fix(server): trash and photo-delete API answers, body limit and audit

- frames/delete carries its own request body limit (about 4.8 MB), so the
  documented 100,000 ids fit; the server's 1 MiB stopped at about 26,900.
- Restore tells a damaged or foreign sidecar of the target sequence
  (409 sidecar_mismatch) from an entry whose files no longer match its
  record (422 trash_mismatch, now a TrashMismatchException); frames/delete
  answers sidecar_mismatch instead of 500, and 404 when the sequence left
  the index between plan and delete, also on the re-plan.
- With the archive offline, the trash list and the empty plan answer
  503 archive_offline instead of an empty trash; a read-only archive still
  lists and plans but cannot be emptied.
- The empty request is audited as trash_empty_requested: the job checks
  the plan again and may erase nothing, so the entry no longer claims an
  erase that has not happened.
- API tests for these paths, a named subset emptied, sequence-entry
  restore and sequence_in_library, photos restored into a new sequence,
  viewer 403 on bulk routes and admin deletes of another user's photos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fa35831d55c44746f7f76e0cff262ed6aecf8e72)
This commit is contained in:
Alby96 committed 2026-10-27 12:46:06 +01:00
1 parent 316c182b19
commit 66c3662954
9 files changed
+350 -24

No files matched your search

@@ -32,6 +32,8 @@ public sealed partial class FrameTrash
/// </summary>
/// <param name="name">The entry's <see cref="TrashEntry.Name"/> (<c>photos-…</c>).</param>
/// <exception cref="DirectoryNotFoundException">The entry is not in the trash.</exception>
/// <exception cref="TrashMismatchException">No file of the entry matches its record; nothing moved.</exception>
/// <exception cref="InvalidDataException">The sequence's sidecar is damaged or belongs to another sequence; nothing moved.</exception>
public async Task<PhotoRestoreResult> RestoreAsync(Archive archive, string name, JobEngine? followUps = null, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(archive);
@@ -55,7 +57,7 @@ public sealed partial class FrameTrash
throw new DirectoryNotFoundException($"{name} is not in the trash of {archive.Name}.");
var (intact, kept) = await CheckAsync(entryFolder, record, cancellationToken).ConfigureAwait(false);
// Nothing that matches its record: the entry stays as it is.
if (intact.Count == 0) throw new InvalidDataException(Core.Localization.Loc.L("Archive.Error.TrashMismatch"));
if (intact.Count == 0) throw new TrashMismatchException();
var had = into?.Status ?? SequenceStatus.None;
PhotoRestoreResult result;
List<TrashedPhoto> stays;
@@ -82,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