feat: owner review 2 phase 5c: originals, local render, clean-up and the workspace settings (#18)
CI / Build and test (push) Successful in 9m26s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 8s
Release / Build, test and publish (push) Successful in 14m31s
CI / PostgreSQL 16 integration (push) Successful in 9m53s
CI / PostgreSQL 17 integration (push) Successful in 9m22s
CI / Docker image (push) Successful in 44s
Release / Server image (push) Successful in 1m36s
CI / Build and test (push) Successful in 9m26s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 8s
Release / Build, test and publish (push) Successful in 14m31s
CI / PostgreSQL 16 integration (push) Successful in 9m53s
CI / PostgreSQL 17 integration (push) Successful in 9m22s
CI / Docker image (push) Successful in 44s
Release / Server image (push) Successful in 1m36s
Originals in the workspace, local render and send home with provenance, the workspace clean-up, size limit and trash, moving the workspace folder, and the complete Settings › Workspace page (owner review 2, R8, phase 5c). One adversarial review round (35 findings, 32 fixed), a copy-cancel race fixed, 184 strings in all 38 languages. 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 #18.
This commit is contained in:
1 parent
81c303f484
commit
db389a54f2
364 files changed
+17417
-595
No files matched your search
@@ -23,7 +23,8 @@ public static class Dto
|
||||
f.Id, f.SequenceId, f.Index, f.FileName, f.Size, f.Sha256, f.CapturedAt, f.UtcOffsetMinutes, f.ExposureTime, f.FNumber, f.Iso,
|
||||
f.FocalLength, f.Orientation, f.Width, f.Height, f.Format.ToString().ToLowerInvariant(), (long)f.Flags, f.PreviewWidth, f.PreviewHeight);
|
||||
|
||||
public static RenderDto Render(Render r) => new(r.Id, r.PresetName, r.Codec, r.Width, r.Height, r.Fps, r.DurationSeconds, r.Bytes, r.Created, r.ProducedBy);
|
||||
public static RenderDto Render(Render r) => new(r.Id, r.PresetName, r.Codec, r.Width, r.Height, r.Fps, r.DurationSeconds, r.Bytes, r.Created, r.ProducedBy,
|
||||
r.ProjectId, r.ProjectVersionId);
|
||||
|
||||
public static JobDto Job(Job j) => new(
|
||||
j.Id, JobWire.Kind(j.Kind), j.TargetIds, j.TargetLabel, JobWire.State(j.State), JobWire.Priority(j.Priority), j.ProgressDone,
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Text.Json;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Server.Api;
|
||||
@@ -17,7 +18,12 @@ namespace Chronos.Server.Storage;
|
||||
/// Renders a client sends on request (BRIEF §14.5): chunked like frame uploads (same store, chunk endpoint and
|
||||
/// retention), verified against their SHA-256 at completion and filed by <see cref="RenderStore"/> under the
|
||||
/// sequence's exports with the client's render id, so both sides recognise the same render.
|
||||
/// A render a workspace made (phase 5c) names its project and version: both are checked against the sequence when the upload
|
||||
/// starts and again when it completes (422 <c>project_mismatch</c>: the project is not one of the sequence's, or the version
|
||||
/// not one of the project's) and recorded with the render; a version alone names its project. Without them a render is filed
|
||||
/// as before, recording neither.
|
||||
/// </summary>
|
||||
/// <param name="archives">The archive engine whose projects are read when the index does not know one yet; one of its own when none is registered.</param>
|
||||
public sealed class RenderUploads(
|
||||
ChronosDatabase db,
|
||||
ServerOptions options,
|
||||
@@ -26,7 +32,8 @@ public sealed class RenderUploads(
|
||||
RenderStore renders,
|
||||
EventHub events,
|
||||
VolumeSpace volumes,
|
||||
TimeProvider time)
|
||||
TimeProvider time,
|
||||
ArchiveService? archives = null)
|
||||
{
|
||||
public async Task<Outcome<StartUploadResponse>> StartAsync(Caller caller, Guid sequenceId, RenderUploadRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -45,6 +52,8 @@ public sealed class RenderUploads(
|
||||
? new StartUploadResponse(null, options.ChunkSizeBytes, [], AlreadyExists: true, null)
|
||||
: Outcome<StartUploadResponse>.Fail(409, "render_exists");
|
||||
}
|
||||
// Checked before a byte is sent, and again at completion.
|
||||
if (await ProjectOfAsync(sequenceId, request, cancellationToken) is null) return Outcome<StartUploadResponse>.Fail(422, "project_mismatch");
|
||||
var sha = request.Sha256.ToLowerInvariant();
|
||||
if (await db.Uploads.FindReceivingAsync(caller.Id, sha, cancellationToken) is { } open && open.SequenceId == sequenceId && open.Size == request.Size
|
||||
&& Read(open)?.RenderId == request.RenderId && store.Exists(open.Id))
|
||||
@@ -81,6 +90,8 @@ public sealed class RenderUploads(
|
||||
if (upload.State != UploadState.Receiving) return Outcome<RenderDto>.Fail(409, "upload_state");
|
||||
if (!upload.IsComplete)
|
||||
return Outcome<RenderDto>.Fail(409, "incomplete", (upload.ChunkCount - upload.ReceivedCount).ToString(CultureInfo.InvariantCulture));
|
||||
// Asked again: the upload may have been started before the project was deleted from the index, or by an earlier server.
|
||||
if (await ProjectOfAsync(sequenceId, output, cancellationToken) is not { } provenance) return Outcome<RenderDto>.Fail(422, "project_mismatch");
|
||||
if (!uploads.ArchiveHasRoom(upload)) return Outcome<RenderDto>.Fail(507, "insufficient_storage");
|
||||
if (!await db.Uploads.TryTransitionAsync(upload.Id, UploadState.Receiving, UploadState.Committing, cancellationToken: cancellationToken))
|
||||
return Outcome<RenderDto>.Fail(409, "upload_state");
|
||||
@@ -93,7 +104,7 @@ public sealed class RenderUploads(
|
||||
try
|
||||
{
|
||||
render = sequence is null ? null : await renders.CommitAsync(sequence, staged, result, output.ProducedBy ?? caller.ClientName ?? caller.User.Username,
|
||||
output.RenderId, cancellationToken);
|
||||
output.RenderId, provenance.ProjectId, provenance.ProjectVersionId, cancellationToken);
|
||||
}
|
||||
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException or FolderMovedException)
|
||||
{
|
||||
@@ -113,6 +124,33 @@ public sealed class RenderUploads(
|
||||
return Dto.Render(render);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The project and version <paramref name="request"/> names, checked against sequence <paramref name="sequenceId"/>: the
|
||||
/// project one of its own (deleted ones included: their versions are kept), the version one of that project's (a version
|
||||
/// alone names its project). One the index does not know yet may be in the sequence's sidecars: listing reads them first.
|
||||
/// Both null when the request names neither; null when they do not hold.
|
||||
/// </summary>
|
||||
private async Task<(Guid? ProjectId, Guid? ProjectVersionId)?> ProjectOfAsync(Guid sequenceId, RenderUploadRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.ProjectId is null && request.ProjectVersionId is null) return (null, null);
|
||||
var (project, version) = await FindAsync();
|
||||
if (project is null || (request.ProjectVersionId is not null && version is null))
|
||||
{
|
||||
await LibraryEndpoints.Engine(archives, db).Projects.ListAsync(sequenceId, cancellationToken);
|
||||
(project, version) = await FindAsync();
|
||||
}
|
||||
if (project is null || project.SequenceId != sequenceId || (version is not null && version.ProjectId != project.Id)) return null;
|
||||
return (project.Id, version?.Id);
|
||||
|
||||
async Task<(SequenceProject? Project, ProjectVersion? Version)> FindAsync()
|
||||
{
|
||||
var known = request.ProjectVersionId is { } versionId ? await db.Projects.GetVersionAsync(versionId, cancellationToken) : null;
|
||||
if (request.ProjectVersionId is not null && known is null) return (null, null);
|
||||
var projectId = request.ProjectId ?? known!.ProjectId;
|
||||
return (await db.Projects.GetAsync(projectId, cancellationToken), known);
|
||||
}
|
||||
}
|
||||
|
||||
private static RenderUploadRequest? Read(Upload upload)
|
||||
{
|
||||
if (upload.RenderJson is not { } json) return null;
|
||||
|
||||
Reference in new issue
Block a user