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

+44 -7
View File
@@ -49,7 +49,8 @@ public sealed class UploadService(
public async Task<Outcome<StartUploadResponse>> StartAsync(Caller caller, StartUploadRequest request, CancellationToken cancellationToken)
{
if (UploadRules.SafeFileName(request.FileName) is not { } fileName) return Fail<StartUploadResponse>(400, "invalid_file_name");
if (UploadRules.SafeFileName(request.FileName) is not { } fileName || UploadRules.IsHiddenName(fileName))
return Fail<StartUploadResponse>(400, "invalid_file_name");
if (!UploadRules.IsSha256(request.Sha256)) return Fail<StartUploadResponse>(400, "invalid_hash");
if (request.Size <= 0) return Fail<StartUploadResponse>(400, "bad_request", "size");
if (request.Size > options.MaxUploadBytes) return Fail<StartUploadResponse>(413, "too_large", options.MaxUploadBytes.ToString(CultureInfo.InvariantCulture));
@@ -60,9 +61,16 @@ public sealed class UploadService(
var sha = request.Sha256.ToLowerInvariant();
var sessionKey = string.IsNullOrWhiteSpace(request.SessionKey) ? null : request.SessionKey.Trim();
var copies = await db.Frames.FindBySha256Async(sha, cancellationToken);
var target = copies.Count == 0 ? null : await UploadRules.TargetAsync(db, archive.Id, request.SequenceId, sessionKey, caller.Id, cancellationToken);
// Only a copy that is still whole stands for the upload: a client may delete its file on this answer.
if (UploadRules.StandIn(archive.Root, copies, target) is { } known)
var target = await UploadRules.TargetAsync(db, archive.Id, request.SequenceId, sessionKey, caller.Id, cancellationToken);
// A photo deleted from the target sequence is not filed into it again: an old client syncing a copy that still holds
// it, or a watch folder sending it again, hears that the server has it (owner review 2, R6). A restore from the trash
// brings it back while the trash holds it; a user who uploads it again on purpose asks with Restore, and filing it
// drops its tombstone.
var removed = await UploadRules.RemovedFromTargetAsync(db, sha, target, copies, cancellationToken);
if (removed && !request.Restore) return new StartUploadResponse(null, options.ChunkSizeBytes, [], AlreadyExists: true, null);
// Only a copy that is still whole stands for the upload: a client may delete its file on this answer. A photo
// brought back is filed into its sequence, whatever other sequences hold it.
if (UploadRules.StandIn(archive.Root, removed ? [] : copies, target) is { } known)
return new StartUploadResponse(null, options.ChunkSizeBytes, [], AlreadyExists: true, known.Id);
var resumable = await db.Uploads.FindReceivingAsync(caller.Id, sha, cancellationToken);
@@ -154,9 +162,11 @@ public sealed class UploadService(
/// <summary>
/// Verifies and commits a frame upload. Completing an already committed upload answers its frame again, so a client
/// may retry a completion whose response it lost. Runs to the end even if the client disconnects.
/// may retry a completion whose response it lost. Runs to the end even if the client disconnects. A photo deleted from
/// the target sequence since the upload started is not filed (409 <see cref="UploadErrors.PhotoRemoved"/>, the upload
/// cancelled) unless <paramref name="restore"/> repeats the start's <see cref="StartUploadRequest.Restore"/>.
/// </summary>
public async Task<Outcome<CompleteUploadResponse>> CompleteAsync(Caller caller, Guid id)
public async Task<Outcome<CompleteUploadResponse>> CompleteAsync(Caller caller, Guid id, bool restore = false)
{
var stopping = lifetime.ApplicationStopping;
var upload = await db.Uploads.GetAsync(id, stopping);
@@ -170,6 +180,10 @@ public sealed class UploadService(
if (!ArchiveHasRoom(upload)) return Fail<CompleteUploadResponse>(507, "insufficient_storage");
if (!await db.Uploads.TryTransitionAsync(id, UploadState.Receiving, UploadState.Committing, cancellationToken: stopping))
return Fail<CompleteUploadResponse>(409, "upload_state");
// Deleted from the target while its bytes were on the way (the start checked before): the upload does not bring the
// photo back (owner review 2, R6). Asked here to answer early; the ingest asks again under the sequence's lease, which
// a deletion takes, so one that lands after this check is caught there.
if (!restore && await RemovedFromTargetAsync(upload, stopping)) return await RemovedAsync(upload);
var user = await db.Users.GetAsync(caller.Id, stopping);
if (user is { QuotaBytes: > 0 } && user.UsedBytes + upload.Size > user.QuotaBytes && !await HeldByTargetAsync(upload, stopping))
@@ -194,7 +208,13 @@ public sealed class UploadService(
upload.Size,
upload.Sha256,
upload.CapturedAt,
caller.Id), stopping);
caller.Id,
RefuseRemoved: !restore), stopping);
}
catch (PhotoRemovedException)
{
UploadStore.TryDelete(staged);
return await RemovedAsync(upload);
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
@@ -301,6 +321,23 @@ public sealed class UploadService(
return copies.Any(f => f.SequenceId == target);
}
/// <summary>An upload whose photo was deleted from its sequence meanwhile: cancelled, its part file gone, 409 <see cref="UploadErrors.PhotoRemoved"/>.</summary>
private async Task<Outcome<CompleteUploadResponse>> RemovedAsync(Upload upload)
{
logger.LogInformation("Upload {Upload} ({File}) not filed: the photo was deleted from its sequence meanwhile", upload.Id, upload.FileName);
await db.Uploads.TryTransitionAsync(upload.Id, UploadState.Committing, UploadState.Cancelled, cancellationToken: CancellationToken.None);
store.Delete(upload.Id);
return Fail<CompleteUploadResponse>(409, UploadErrors.PhotoRemoved);
}
/// <summary>The sequence the upload files into tombstoned its content (<see cref="UploadRules.RemovedFromTargetAsync"/>).</summary>
private async Task<bool> RemovedFromTargetAsync(Upload upload, CancellationToken cancellationToken)
{
var target = await UploadRules.TargetAsync(db, archive.Id, upload.SequenceId, upload.SessionKey, upload.UserId, cancellationToken);
return target is not null && await UploadRules.RemovedFromTargetAsync(db, upload.Sha256, target,
await db.Frames.FindBySha256Async(upload.Sha256, cancellationToken), cancellationToken);
}
private StartUploadResponse Started(Upload upload) =>
new(upload.Id, upload.ChunkSize, UploadRules.ReceivedChunks(upload), AlreadyExists: false, FrameId: null);