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
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:
1 parent
af9eeaab9b
commit
9aa818ed47
283 files changed
+24922
-293
No files matched your search
@@ -14,6 +14,7 @@ namespace Chronos.Core.Archiving;
|
||||
[JsonSerializable(typeof(SequenceManifest))]
|
||||
[JsonSerializable(typeof(LeaseRecord))]
|
||||
[JsonSerializable(typeof(IngestJournal))]
|
||||
[JsonSerializable(typeof(FrameRemovalJournal))]
|
||||
[JsonSerializable(typeof(RenameJournal))]
|
||||
internal sealed partial class ArchiveJson : JsonSerializerContext;
|
||||
|
||||
|
||||
@@ -30,6 +30,12 @@ public static class ArchiveLayout
|
||||
/// <summary>Moves of an ingest batch that were started but not yet recorded in <see cref="SequenceManifestFile"/>.</summary>
|
||||
public const string IngestJournalFile = "ingest.pending.json";
|
||||
|
||||
/// <summary>Moves of a photo deletion into the trash that were started but not yet recorded in <see cref="SequenceManifestFile"/>.</summary>
|
||||
public const string RemovalJournalFile = "remove.pending.json";
|
||||
|
||||
/// <summary>Moves of photos restored from the trash that were started but not yet settled in <see cref="SequenceManifestFile"/> and the trash record.</summary>
|
||||
public const string RestoreJournalFile = "restore.pending.json";
|
||||
|
||||
/// <summary>Folder names inside a sequence folder that never hold a sequence of their own.</summary>
|
||||
public static bool IsReservedFolder(string name) =>
|
||||
name.Equals(MetaFolder, StringComparison.OrdinalIgnoreCase)
|
||||
@@ -74,11 +80,15 @@ public sealed class SequencePaths
|
||||
internal SequencePaths(ArchivePaths archive, string relativeFolder)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(relativeFolder);
|
||||
Archive = archive;
|
||||
RelativeFolder = relativeFolder.Replace('\\', '/').Trim('/');
|
||||
Folder = archive.FromRelative(RelativeFolder);
|
||||
MetaDirectory = Path.Combine(Folder, ArchiveLayout.MetaFolder);
|
||||
}
|
||||
|
||||
/// <summary>The archive the sequence belongs to.</summary>
|
||||
public ArchivePaths Archive { get; }
|
||||
|
||||
/// <summary>Folder relative to the archive root, forward slashes; empty when the root itself holds the photos (adopted folder).</summary>
|
||||
public string RelativeFolder { get; }
|
||||
|
||||
@@ -92,6 +102,8 @@ public sealed class SequencePaths
|
||||
public string ProjectPath => Path.Combine(MetaDirectory, ArchiveLayout.ProjectFile);
|
||||
public string ThumbsPackPath => Path.Combine(MetaDirectory, ArchiveLayout.ThumbsPackFile);
|
||||
public string IngestJournalPath => Path.Combine(MetaDirectory, ArchiveLayout.IngestJournalFile);
|
||||
public string RemovalJournalPath => Path.Combine(MetaDirectory, ArchiveLayout.RemovalJournalFile);
|
||||
public string RestoreJournalPath => Path.Combine(MetaDirectory, ArchiveLayout.RestoreJournalFile);
|
||||
|
||||
public string Proxy(int index) => Path.Combine(Proxies, ArchiveLayout.ProxyFileName(index));
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
using System.Text.Json;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.IO;
|
||||
|
||||
namespace Chronos.Core.Archiving;
|
||||
|
||||
/// <summary>One file of a photo deletion: where it was in the sequence folder and where it went in the archive's trash.</summary>
|
||||
/// <param name="From">Path relative to the sequence folder (forward slashes).</param>
|
||||
/// <param name="To">Path relative to the archive root (forward slashes), inside the trash entry.</param>
|
||||
public sealed record FrameRemovalMove(string From, string To);
|
||||
|
||||
/// <summary>
|
||||
/// Write-ahead record of a photo deletion (<c>.chronos/remove.pending.json</c>, owner review 2, R6): the trash entry the
|
||||
/// photos move into, the frames leaving the sidecar and every file move. Written before the first move and removed once
|
||||
/// <c>sequence.json</c> no longer lists the frames, so a crash in between is undone by <see cref="Recover"/>: the files go
|
||||
/// back to their places, the entry's record and folder go, and the sequence is as it was. Until the sidecar is written
|
||||
/// the entry's record has its <see cref="PendingRecord"/> name, which the trash never lists, so half an entry can be
|
||||
/// neither restored nor emptied.
|
||||
/// </summary>
|
||||
/// <param name="Record">The entry's record, relative to the archive root (its name once the deletion is complete).</param>
|
||||
/// <param name="Folder">The entry's folder, relative to the archive root.</param>
|
||||
public sealed record FrameRemovalJournal(string Record, string Folder, IReadOnlyList<Guid> Frames, IReadOnlyList<FrameRemovalMove> Moves)
|
||||
{
|
||||
/// <summary>The name a deletion's record has until its sidecar is written.</summary>
|
||||
public static string PendingRecord(string record) => record + ".pending";
|
||||
|
||||
public static void Write(SequencePaths sequence, FrameRemovalJournal journal)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sequence);
|
||||
Directory.CreateDirectory(sequence.MetaDirectory);
|
||||
AtomicFile.WriteAllBytes(sequence.RemovalJournalPath, JsonSerializer.SerializeToUtf8Bytes(journal, ArchiveJson.Default.FrameRemovalJournal));
|
||||
}
|
||||
|
||||
public static void Delete(SequencePaths sequence)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sequence);
|
||||
if (File.Exists(sequence.RemovalJournalPath)) File.Delete(sequence.RemovalJournalPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Undoes a deletion a crash interrupted before its sidecar was written: while <paramref name="manifest"/> still lists a
|
||||
/// frame of the journal, each file that reached the trash moves back (one whose place is taken again stays in the trash,
|
||||
/// logged, and so does the entry then, listed under its record's own name), and the entry's record and its emptied
|
||||
/// folder go. A deletion whose sidecar was written is complete: its record takes its own name, and the journal goes.
|
||||
/// Returns whether a deletion was undone. The caller holds the lease.
|
||||
/// </summary>
|
||||
public static bool Recover(SequencePaths sequence, SequenceManifest manifest)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sequence);
|
||||
ArgumentNullException.ThrowIfNull(manifest);
|
||||
if (!File.Exists(sequence.RemovalJournalPath)) return false;
|
||||
FrameRemovalJournal? journal;
|
||||
try
|
||||
{
|
||||
journal = JsonSerializer.Deserialize(AtomicFile.ReadAllBytes(sequence.RemovalJournalPath), ArchiveJson.Default.FrameRemovalJournal);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
journal = null; // torn while being written: nothing was moved yet
|
||||
}
|
||||
var undone = false;
|
||||
var archive = sequence.Archive;
|
||||
if (journal is not null && manifest.Frames.Any(f => journal.Frames.Contains(f.Id)))
|
||||
{
|
||||
var kept = 0;
|
||||
foreach (var move in journal.Moves)
|
||||
{
|
||||
var trashed = archive.FromRelative(move.To);
|
||||
var place = sequence.File(move.From);
|
||||
if (!File.Exists(trashed)) continue;
|
||||
if (File.Exists(place))
|
||||
{
|
||||
kept++;
|
||||
Log.Warning("archive", $"{sequence.ArchiveRelative(move.From)} is there again; its deleted copy stays in {move.To}");
|
||||
continue;
|
||||
}
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(place)!);
|
||||
File.Move(trashed, place, overwrite: false);
|
||||
}
|
||||
var record = archive.FromRelative(journal.Record);
|
||||
if (kept == 0)
|
||||
{
|
||||
if (File.Exists(record)) File.Delete(record);
|
||||
if (File.Exists(PendingRecord(record))) File.Delete(PendingRecord(record));
|
||||
RemoveEmpty(archive.FromRelative(journal.Folder));
|
||||
}
|
||||
else
|
||||
{
|
||||
// What stays in the trash is listed, restorable and erasable like any entry.
|
||||
Publish(record);
|
||||
}
|
||||
Log.Warning("archive", $"An interrupted photo deletion in {sequence.RelativeFolder} was undone");
|
||||
undone = true;
|
||||
}
|
||||
else if (journal is not null)
|
||||
{
|
||||
Publish(archive.FromRelative(journal.Record));
|
||||
}
|
||||
Delete(sequence);
|
||||
return undone;
|
||||
}
|
||||
|
||||
/// <summary>Gives a deletion's record its own name (<see cref="PendingRecord"/>), once its photos are out of the sidecar.</summary>
|
||||
public static void Publish(string record)
|
||||
{
|
||||
var pending = PendingRecord(record);
|
||||
if (File.Exists(pending) && !File.Exists(record)) File.Move(pending, record, overwrite: false);
|
||||
}
|
||||
|
||||
/// <summary>Removes <paramref name="folder"/> and its subfolders when they hold no file.</summary>
|
||||
public static void RemoveEmpty(string folder)
|
||||
{
|
||||
if (!Directory.Exists(folder)) return;
|
||||
foreach (var child in Directory.EnumerateDirectories(folder)) RemoveEmpty(child);
|
||||
if (!Directory.EnumerateFileSystemEntries(folder).Any()) Directory.Delete(folder);
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,9 @@ public sealed class LeaseFile : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The current holder of the lease <paramref name="name"/> in <paramref name="locksDirectory"/>, or null when free or unreadable.</summary>
|
||||
public static LeaseRecord? Holder(string locksDirectory, string name) => Read(PathFor(locksDirectory, name));
|
||||
|
||||
/// <summary>The current holder of a lease, or null when free or unreadable.</summary>
|
||||
/// <remarks>
|
||||
/// Readers share read, write and delete so they never block a renewal, a release or a takeover. A renewal rewrites
|
||||
|
||||
@@ -42,6 +42,13 @@ public sealed record SequenceManifest
|
||||
/// <summary>Session keys of automatic grouping (uploads, card imports) that resolve to this sequence.</summary>
|
||||
public IReadOnlyList<string> SessionKeys { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Tombstones of the photos removed from the sequence (owner review 2, R6), by SHA-256; null when there are none, so a
|
||||
/// sidecar without removals is written as before. A build that does not know the field keeps it in its
|
||||
/// <see cref="Extra"/> and writes it back unchanged.
|
||||
/// </summary>
|
||||
public IReadOnlyList<RemovedPhoto>? Removed { get; init; }
|
||||
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? Extra { get; set; }
|
||||
}
|
||||
@@ -127,6 +134,53 @@ public sealed record SidecarFrame
|
||||
/// <summary><see cref="FrameFlags"/> bits, stored as a number so bits of newer builds survive.</summary>
|
||||
public FrameFlags Flags { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The file this frame was converted from (reserved for the conversion of owner review 2, R7); null for an original.
|
||||
/// Read and written only: nothing acts on it yet.
|
||||
/// </summary>
|
||||
public FrameSource? Source { get; init; }
|
||||
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? Extra { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tombstone of a photo removed from a sequence (owner review 2, R6): sync never offers that content back to the
|
||||
/// sequence, and an upload of it is answered as already there. <see cref="Replacement"/> names the converted file that took
|
||||
/// its place (<see cref="RemovalReason.Replaced"/>), which sync then counts as the same photo.
|
||||
/// </summary>
|
||||
public sealed record RemovedPhoto
|
||||
{
|
||||
/// <summary>Lower-case hex SHA-256 of the removed photo.</summary>
|
||||
public required string Sha256 { get; init; }
|
||||
|
||||
/// <summary>Lower-case hex SHA-256 of the file that replaced it; null for a photo deleted outright.</summary>
|
||||
public string? Replacement { get; init; }
|
||||
|
||||
[JsonConverter(typeof(TolerantEnumConverter<RemovalReason>))]
|
||||
public RemovalReason Reason { get; init; }
|
||||
|
||||
/// <summary>When it was removed (UTC).</summary>
|
||||
public DateTimeOffset At { get; init; }
|
||||
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? Extra { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>The original a converted frame was made from (reserved for owner review 2, R7): its content, format, file and size.</summary>
|
||||
public sealed record FrameSource
|
||||
{
|
||||
/// <summary>Lower-case hex SHA-256 of the source file.</summary>
|
||||
public string? Sha256 { get; init; }
|
||||
|
||||
[JsonConverter(typeof(TolerantEnumConverter<ImageFileFormat>))]
|
||||
public ImageFileFormat Format { get; init; }
|
||||
|
||||
/// <summary>The source's path relative to the sequence folder (forward slashes) when it was converted.</summary>
|
||||
public string? File { get; init; }
|
||||
|
||||
public long Size { get; init; }
|
||||
|
||||
[JsonExtensionData]
|
||||
public Dictionary<string, JsonElement>? Extra { get; set; }
|
||||
}
|
||||
@@ -346,6 +346,30 @@ public sealed class ThumbPackWriter : IDisposable
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves each thumbnail to the frame index <paramref name="indices"/> maps its own to (old → new) and drops those it
|
||||
/// does not map (frames removed), then commits: only a new index is written, the thumbnails stay where they are. Their
|
||||
/// entry headers keep the old index, so a pack whose index a crash cut off reads back under those, where each one's
|
||||
/// source fingerprint (<see cref="ThumbPack.IsFrom"/>) still tells it from the frame now at that index.
|
||||
/// </summary>
|
||||
public void Rekey(IReadOnlyDictionary<int, int> indices)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(indices);
|
||||
if (_entries.All(e => indices.TryGetValue(e.Key, out var to) && to == e.Key)) return;
|
||||
var moved = new List<ThumbEntry>(_entries.Count);
|
||||
foreach (var (index, entry) in _entries)
|
||||
{
|
||||
if (indices.TryGetValue(index, out var to)) moved.Add(entry with { FrameIndex = to });
|
||||
}
|
||||
_entries.Clear();
|
||||
foreach (var entry in moved) _entries[entry.FrameIndex] = entry;
|
||||
// The new index replaces the last committed one at the end of the pack.
|
||||
if (_indexOffset is { } offset) _stream.SetLength(offset);
|
||||
_indexOffset = null;
|
||||
_dirty = true;
|
||||
Commit();
|
||||
}
|
||||
|
||||
/// <summary>Writes the index and footer and flushes to disk.</summary>
|
||||
public void Commit()
|
||||
{
|
||||
|
||||
@@ -17,6 +17,13 @@ public sealed record Archive
|
||||
public int ProxyLongEdge { get; init; } = 1920;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tombstone of a photo removed from a sequence (owner review 2, R6): its SHA-256, the replacement's when it was
|
||||
/// replaced by a converted file, why and when. Kept in the sidecar (<c>removed</c>) and the index (<c>frame_removals</c>), so
|
||||
/// sync never offers the photo back and an upload of that content into the sequence is answered as already there.
|
||||
/// </summary>
|
||||
public sealed record FrameRemoval(Guid SequenceId, string Sha256, string? ReplacementSha256, RemovalReason Reason, DateTimeOffset RemovedAt);
|
||||
|
||||
/// <summary>One shoot: a folder of frames that becomes one project (BRIEF §5).</summary>
|
||||
public sealed record Sequence
|
||||
{
|
||||
|
||||
@@ -87,6 +87,22 @@ public enum JobKind
|
||||
|
||||
/// <summary>Housekeeping steps: job history, audit log, trash report and the host's own (owner review 2, R10); stored as 17.</summary>
|
||||
Cleanup = 17,
|
||||
|
||||
/// <summary>
|
||||
/// Erases exactly the trash entries of a confirmed plan, refused when the trash changed since (owner review 2, R6); stored
|
||||
/// as 18.
|
||||
/// </summary>
|
||||
EmptyTrash = 18,
|
||||
}
|
||||
|
||||
/// <summary>Why a photo left a sequence (its tombstone, owner review 2, R6); stored as a number.</summary>
|
||||
public enum RemovalReason
|
||||
{
|
||||
/// <summary>Deleted by a user into the archive's trash.</summary>
|
||||
Deleted = 0,
|
||||
|
||||
/// <summary>Replaced by a converted file (a later phase): the tombstone names the replacement's SHA-256.</summary>
|
||||
Replaced = 1,
|
||||
}
|
||||
|
||||
public enum JobState
|
||||
|
||||
Reference in new issue
Block a user