merge: integration branch claude/keen-knuth-uhxv8w (remote editor after review) into the Library workstream
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
81 files changed
+3827
-263
No files matched your search
@@ -2,10 +2,12 @@ using System.Buffers.Text;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Titano.Core.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Repositories;
|
||||
using Titano.Protocol;
|
||||
using Titano.Server.Configuration;
|
||||
@@ -37,6 +39,7 @@ public static class SequenceEndpoints
|
||||
sequences.MapGet("/{id:guid}/manifest", ManifestAsync).Requires(Permissions.Read);
|
||||
sequences.MapGet("/{id:guid}/frames", FramesAsync).Requires(Permissions.Read);
|
||||
sequences.MapGet("/{id:guid}/analysis", AnalysisAsync).Requires(Permissions.Read);
|
||||
sequences.MapGet("/{id:guid}/analysis/report", ReportAsync).Requires(Permissions.Read);
|
||||
sequences.MapGet("/{id:guid}/stats", StatsAsync).Requires(Permissions.Read);
|
||||
sequences.MapGet("/{id:guid}/renders", RendersAsync).Requires(Permissions.Read);
|
||||
// Renders made on a client, sent on request (BRIEF §14.5); chunks go through /uploads.
|
||||
@@ -125,7 +128,17 @@ public static class SequenceEndpoints
|
||||
if (request.SettingsJson is not null && !IsJson(request.SettingsJson)) return ApiErrors.BadRequest(context, "invalid_settings");
|
||||
|
||||
var expected = request.ExpectedSettingsVersion ?? IfMatchVersion(context);
|
||||
var edit = new SequenceEdit { Title = request.Title, Tags = request.Tags, Rating = request.Rating, Notes = request.Notes, SettingsJson = request.SettingsJson };
|
||||
var edit = new SequenceEdit
|
||||
{
|
||||
Title = request.Title,
|
||||
Tags = request.Tags,
|
||||
Rating = request.Rating,
|
||||
Notes = request.Notes,
|
||||
SettingsJson = request.SettingsJson,
|
||||
// A client that sends only the settings (the sync of a local copy) moves the hero frame with the project's hero.
|
||||
HeroFrameId = request.HeroFrameId
|
||||
?? (request.SettingsJson is { } settings ? await SettingsHeroAsync(db, id, settings, context.RequestAborted) : null),
|
||||
};
|
||||
var result = await db.Sequences.EditAsync(id, edit, expected, context.RequestAborted);
|
||||
switch (result.Outcome)
|
||||
{
|
||||
@@ -245,6 +258,18 @@ public static class SequenceEndpoints
|
||||
_ => ApiErrors.NotFound(context, "analysis"),
|
||||
};
|
||||
|
||||
/// <summary>The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence.</summary>
|
||||
private static async Task<IResult> ReportAsync(HttpContext context, Guid id, TitanoDatabase db, ServerArchive archive)
|
||||
{
|
||||
if (await db.Sequences.GetAsync(id, context.RequestAborted) is not { } sequence) return ApiErrors.NotFound(context, "sequence");
|
||||
if (string.IsNullOrEmpty(sequence.Folder)) return ApiErrors.NotFound(context, "analysis");
|
||||
var path = new Core.Archiving.ArchivePaths(archive.Root).Sequence(sequence.Folder).AnalysisPath;
|
||||
var file = new FileInfo(path);
|
||||
if (!file.Exists || file.LinkTarget is not null || !ArchivePathGuard.IsInside(archive.Root, path)) return ApiErrors.NotFound(context, "analysis");
|
||||
var etag = string.Create(CultureInfo.InvariantCulture, $"a-{file.Length}-{file.LastWriteTimeUtc.Ticks}");
|
||||
return FileResponses.Serve(context, file, 0, file.Length, "application/json; charset=utf-8", "no-cache", etag) ?? ApiErrors.NotFound(context, "analysis");
|
||||
}
|
||||
|
||||
private static async Task<IResult> StatsAsync(HttpContext context, Guid id, TitanoDatabase db)
|
||||
{
|
||||
if (await db.Sequences.GetAsync(id, context.RequestAborted) is not { } s) return ApiErrors.NotFound(context, "sequence");
|
||||
@@ -305,6 +330,22 @@ public static class SequenceEndpoints
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>The hero frame edit of new settings: the frame of their hero when it is not the stored settings' hero.</summary>
|
||||
private static async Task<Guid?> SettingsHeroAsync(TitanoDatabase db, Guid id, string settingsJson, CancellationToken ct)
|
||||
{
|
||||
if (await db.Sequences.GetAsync(id, ct) is not { } current) return null;
|
||||
try
|
||||
{
|
||||
var before = string.IsNullOrWhiteSpace(current.SettingsJson) ? null : ProjectSettings.FromJson(current.SettingsJson).HeroFrame;
|
||||
return await HeroFrame.EditAsync(db, id, before, ProjectSettings.FromJson(settingsJson).HeroFrame, ct);
|
||||
}
|
||||
catch (Exception ex) when (ex is JsonException or InvalidDataException)
|
||||
{
|
||||
// Not a project of this Titano (a newer one, or free JSON): its hero is unknown here, the stored one stays.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsJson(string text)
|
||||
{
|
||||
try
|
||||
@@ -326,6 +367,7 @@ public static class SequenceEndpoints
|
||||
if (r.Rating is not null) fields.Add("rating");
|
||||
if (r.Notes is not null) fields.Add("notes");
|
||||
if (r.SettingsJson is not null) fields.Add("settings");
|
||||
if (r.HeroFrameId is not null) fields.Add("hero");
|
||||
return string.Join(", ", fields);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user