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

@@ -0,0 +1,71 @@
using System.Globalization;
using System.Text;
using Chronos.Core.Model;
namespace Chronos.Data.Repositories;
/// <summary>
/// Tombstones of the photos removed from sequences (owner review 2, R6; <c>frame_removals</c>), by sequence and SHA-256.
/// The sidecar's <c>removed</c> list is the truth: the index writes a sequence's rows from it whenever it takes the
/// sidecar (<see cref="SyncSequenceAsync"/>), so a rebuild keeps them, and they go with the sequence's row.
/// </summary>
public sealed class FrameRemovalRepository
{
private const string Columns = "sequence_id, sha256, replacement_sha256, reason, removed_at";
/// <summary>Rows one INSERT writes (five parameters each, well inside both engines' limits).</summary>
private const int InsertRows = 200;
private readonly DbAccess _db;
internal FrameRemovalRepository(DbAccess db) => _db = db;
/// <summary>The tombstones of a sequence, oldest first.</summary>
public Task<IReadOnlyList<FrameRemoval>> ListBySequenceAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
_db.ListAsync($"SELECT {Columns} FROM frame_removals WHERE sequence_id = $1 ORDER BY removed_at, sha256", [sequenceId], Map, cancellationToken);
/// <summary>Whether <paramref name="sha256"/> was removed from the sequence (any reason).</summary>
public async Task<bool> IsRemovedAsync(Guid sequenceId, string sha256, CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrEmpty(sha256);
return await _db.ScalarAsync<long>("SELECT count(*) FROM frame_removals WHERE sequence_id = $1 AND sha256 = $2",
[sequenceId, sha256.ToLowerInvariant()], cancellationToken).ConfigureAwait(false) > 0;
}
/// <summary>
/// Replaces the tombstones of a sequence with <paramref name="removals"/> (the sidecar's list; one per SHA-256, the
/// last one given wins). Returns how many rows the sequence has now.
/// </summary>
public Task<int> SyncSequenceAsync(Guid sequenceId, IReadOnlyList<FrameRemoval> removals, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(removals);
var rows = removals.Where(r => !string.IsNullOrEmpty(r.Sha256)).GroupBy(r => r.Sha256.ToLowerInvariant(), StringComparer.Ordinal)
.Select(g => g.Last() with { Sha256 = g.Key, SequenceId = sequenceId }).ToList();
return _db.InTransactionAsync(async session =>
{
await session.ExecuteAsync("DELETE FROM frame_removals WHERE sequence_id = $1", [sequenceId], cancellationToken).ConfigureAwait(false);
for (var start = 0; start < rows.Count; start += InsertRows)
{
var count = Math.Min(InsertRows, rows.Count - start);
var sql = new StringBuilder($"INSERT INTO frame_removals ({Columns}) VALUES ");
var args = new DbParam[count * 5];
for (var i = 0; i < count; i++)
{
var row = rows[start + i];
sql.Append(i > 0 ? ", (" : "(").Append(string.Join(", ", Enumerable.Range(i * 5 + 1, 5).Select(n => "$" + n.ToString(CultureInfo.InvariantCulture))))
.Append(')');
args[i * 5] = row.SequenceId;
args[i * 5 + 1] = row.Sha256;
args[i * 5 + 2] = row.ReplacementSha256?.ToLowerInvariant();
args[i * 5 + 3] = (int)row.Reason;
args[i * 5 + 4] = row.RemovedAt;
}
await session.ExecuteAsync(sql.ToString(), args, cancellationToken).ConfigureAwait(false);
}
return rows.Count;
}, cancellationToken);
}
private static FrameRemoval Map(DbRow r) =>
new(r.GetGuid(0), r.GetString(1), r.GetStringOrNull(2), (RemovalReason)r.GetInt32(3), r.GetDateTimeOffset(4));
}
@@ -1,3 +1,4 @@
using System.Globalization;
using Chronos.Core.Imaging;
using Chronos.Core.Model;
@@ -103,6 +104,15 @@ public sealed record CameraBucket(string? Make, string? Model, int Sequences, lo
public sealed record FormatBucket(ImageFileFormat Format, long Photos, long Bytes);
/// <summary>
/// A value a Library filter offers, as <see cref="SequenceQuery"/> takes it (a year, an exact camera model, a tag), and
/// how many sequences have it; <see cref="Make"/> is a camera model's make, for its label.
/// </summary>
public sealed record ArchiveFacet(string Value, int Sequences, string? Make = null);
/// <summary>The years of first capture, camera models and tags of an archive's sequences (owner review 2, R6: the panel's filters).</summary>
public sealed record ArchiveFacets(IReadOnlyList<ArchiveFacet> Years, IReadOnlyList<ArchiveFacet> Cameras, IReadOnlyList<ArchiveFacet> Tags);
/// <summary>Health counters: sequences needing attention and flagged frames.</summary>
public sealed record ArchiveHealth(
int Unverified,
@@ -389,6 +399,32 @@ public sealed class SequenceRepository
}, cancellationToken);
}
/// <summary>
/// What the Library's filters offer for <paramref name="archiveId"/>: years of first capture (newest first), camera
/// models (most sequences first; one entry per model, as the camera filter matches the model alone) and the tags in use
/// (by name). Only sequence rows are read, never frames.
/// </summary>
public Task<ArchiveFacets> GetFacetsAsync(Guid archiveId, CancellationToken cancellationToken = default)
{
DbParam[] args = [archiveId];
var year = _db.Sql.Year("s.first_capture");
return _db.RunAsync(async session =>
{
var years = await session.QueryListAsync(
$"SELECT {year}, count(*) FROM sequences s WHERE s.archive_id = $1 AND s.first_capture IS NOT NULL GROUP BY 1 ORDER BY 1 DESC", args,
r => new ArchiveFacet(r.GetInt32(0).ToString(CultureInfo.InvariantCulture), r.GetInt32(1)), cancellationToken).ConfigureAwait(false);
var cameras = await session.QueryListAsync(
"SELECT s.camera_model, MIN(s.camera_make), count(*) FROM sequences s " +
"WHERE s.archive_id = $1 AND s.camera_model IS NOT NULL AND s.camera_model <> '' GROUP BY s.camera_model ORDER BY 3 DESC, 1", args,
r => new ArchiveFacet(r.GetString(0), r.GetInt32(2), r.GetStringOrNull(1)), cancellationToken).ConfigureAwait(false);
var tags = await session.QueryListAsync(
"SELECT MIN(t.name), count(*) FROM sequence_tags st JOIN tags t ON t.id = st.tag_id JOIN sequences s ON s.id = st.sequence_id " +
"WHERE s.archive_id = $1 GROUP BY t.name_key ORDER BY t.name_key", args,
r => new ArchiveFacet(r.GetString(0), r.GetInt32(1)), cancellationToken).ConfigureAwait(false);
return new ArchiveFacets(years, cameras, tags);
}, cancellationToken);
}
/// <summary>
/// The sequences of <paramref name="archiveId"/> a rolling verification checks next (owner review 2, R10): those never
/// verified first, then the longest unverified, at most <paramref name="limit"/>. With <paramref name="verifiedBefore"/>