feat(P3): videos API, server videos folder and the /videos volume
The server side of the videos library (owner review 1, R9): one list of every render, a delete into the archive's trash that is always a dry run first and must give the plan's fingerprint back, and a hash-verified copy into a videos folder as one video-copy job, so the panel and the desktop manage renders without editing anything. - /api/v1/videos: list (filters, sort, paging), get, delete (Delete, audited videos_deleted) and copy (Edit, audited videos_copied; 409 videos_folder_unset, 422 videos_folder_invalid, 507 videos_no_space). - The "videos" capability; format 3 comes from ProjectSettings.CurrentVersion. - Trash routes accept videos-<id>-<ticks> entries; restore goes through the videos library (hash re-check, same render id). - Render DTOs carry sha256 and kind; sent renders and node results record the verified hash and the kind. - VideosPath setting (CHRONOS_VIDEOS_PATH locks it): absolute, outside the archive and the data folder; video-copy gets a priority level. - Docker: /videos volume in compose with CHRONOS_VIDEOS_PATH, folder made in the image (not a VOLUME), entrypoint checks it; Unraid template rows. - .webm, .m4v and .apng served with their media types for the panel player. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d472dfdec1
commit
3812773999
17 files changed
+875
-13
No files matched your search
@@ -5,6 +5,7 @@ using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Videos;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Server.Events;
|
||||
using Chronos.Server.Jobs;
|
||||
@@ -15,7 +16,7 @@ namespace Chronos.Server.Api;
|
||||
|
||||
/// <summary>
|
||||
/// <c>/api/v1/archive/trash</c> (owner review 2, R6; administrators of the archive): the entries of the archive's trash —
|
||||
/// deleted sequences and photos deleted from sequences —, restoring one, and emptying it: a dry run that measures the
|
||||
/// deleted sequences, photos deleted from sequences and deleted videos (owner review 1, R9) —, restoring one, and emptying it: a dry run that measures the
|
||||
/// entries and fingerprints them, then an <c>empty-trash</c> job that erases exactly those entries and refuses when the
|
||||
/// trash changed since (BRIEF §0.2 rule 8: the only erase of user files, always an explicit, confirmed action).
|
||||
/// </summary>
|
||||
@@ -29,8 +30,11 @@ public static partial class TrashEndpoints
|
||||
trash.MapPost("/empty", EmptyAsync);
|
||||
}
|
||||
|
||||
/// <summary>Whether <paramref name="name"/> has the shape of an entry name (a sequence id, a time, <c>photos-</c>): never a path.</summary>
|
||||
public static bool IsEntryName(string? name) => name is not null && EntryName().IsMatch(name);
|
||||
/// <summary>
|
||||
/// Whether <paramref name="name"/> has the shape of an entry name (a sequence id, a time, <c>photos-</c>, or a videos entry
|
||||
/// <c>videos-<render id>-<ticks></c>, owner review 1, R9): never a path.
|
||||
/// </summary>
|
||||
public static bool IsEntryName(string? name) => name is not null && (EntryName().IsMatch(name) || VideoTrashNames.IsEntryName(name));
|
||||
|
||||
public static TrashEntryDto Entry(TrashEntry e) =>
|
||||
new(e.Name, e.Kind.ToString().ToLowerInvariant(), e.SequenceId, e.Title, e.Folder, e.Frames, e.Files, e.Bytes, e.DeletedBy, e.DeletedAt, e.ConversionDeleted);
|
||||
@@ -55,9 +59,11 @@ public static partial class TrashEndpoints
|
||||
/// a sequence, <c>frames</c> for photos.
|
||||
/// </summary>
|
||||
private static async Task<IResult> RestoreAsync(HttpContext context, Caller caller, string name, ChronosDatabase db, ServerArchive archive,
|
||||
[FromServices] ArchiveService? archives, JobEngineHost host, AuditLog audit, EventHub events, IHostApplicationLifetime lifetime)
|
||||
[FromServices] ArchiveService? archives, [FromServices] IVideoLibrary? videos, JobEngineHost host, AuditLog audit, EventHub events,
|
||||
IHostApplicationLifetime lifetime)
|
||||
{
|
||||
if (!IsEntryName(name)) return ApiErrors.NotFound(context, "trash_entry");
|
||||
if (VideoTrashNames.IsEntryName(name)) return await RestoreVideoAsync(context, caller, name, db, archive, VideoEndpoints.Library(videos, archives, db), audit, events, lifetime);
|
||||
TrashRestoreResult result;
|
||||
try
|
||||
{
|
||||
@@ -107,6 +113,49 @@ public static partial class TrashEndpoints
|
||||
result.Kept.Count == 0 ? null : string.Join(" ", KeptPhoto.Sentences(result.Kept, culture))), ProtocolJson.Default.TrashRestoreDto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Brings a deleted video back (owner review 1, R9, decision 18): the trashed file re-hashed against its record, moved back
|
||||
/// into its sequence's folder (a free name when its own is taken) and its entry recorded again with the same render id.
|
||||
/// 404 <c>not_found</c> (<c>trash_entry</c>); 409 <c>sequence_gone</c> (restore the sequence first), <c>sequence_busy</c>,
|
||||
/// <c>folder_in_use</c>; 422 <c>trash_hash_mismatch</c> (it stays in the trash); 503 <c>archive_offline</c>. Publishes
|
||||
/// <c>sequenceChanged</c> (<c>renders</c>).
|
||||
/// </summary>
|
||||
private static async Task<IResult> RestoreVideoAsync(HttpContext context, Caller caller, string name, ChronosDatabase db, ServerArchive archive,
|
||||
IVideoLibrary library, AuditLog audit, EventHub events, IHostApplicationLifetime lifetime)
|
||||
{
|
||||
if (!library.IsAvailable) return ApiErrors.NotFound(context, "trash_entry");
|
||||
Render render;
|
||||
try
|
||||
{
|
||||
render = await library.RestoreAsync(archive.Id, name, lifetime.ApplicationStopping);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
return ApiErrors.NotFound(context, "trash_entry");
|
||||
}
|
||||
catch (VideoLibraryException ex)
|
||||
{
|
||||
return VideoEndpoints.Refused(context, ex);
|
||||
}
|
||||
catch (ArchiveOfflineException)
|
||||
{
|
||||
return Offline(context);
|
||||
}
|
||||
catch (LeaseUnavailableException)
|
||||
{
|
||||
return ApiErrors.Conflict(context, "sequence_busy");
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
return ApiErrors.Conflict(context, "folder_in_use");
|
||||
}
|
||||
await audit.WriteAsync(caller, context, "trash_restored", "render", render.Id.ToString(), $"{name} · {Path.GetFileName(render.OutputPath.TrimEnd('/', '\\'))}");
|
||||
if (await db.Sequences.GetAsync(render.SequenceId, CancellationToken.None) is { } sequence)
|
||||
events.Publish(new SequenceChangedEvent(sequence.Id, "renders", sequence.FramesVersion, sequence.SettingsVersion));
|
||||
return Results.Json(new TrashRestoreDto(name, TrashKind.Videos.ToString().ToLowerInvariant(), render.SequenceId, 1, [], NewSequence: false),
|
||||
ProtocolJson.Default.TrashRestoreDto);
|
||||
}
|
||||
|
||||
/// <summary>The code of why a photo stayed in the trash (<see cref="TrashRestoreDto.KeptReasons"/>).</summary>
|
||||
private static string ReasonCode(KeptReason reason) => reason switch
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user