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:
Alby96 committed 2026-11-05 02:08:01 +01:00
1 parent d472dfdec1
commit 3812773999
17 files changed
+875 -13

No files matched your search

@@ -14,7 +14,8 @@ namespace Chronos.Server.Configuration;
/// The admin panel's view of the configuration (BRIEF §14.8 Settings). Saving writes <c>/data/server.json</c> (only the
/// edited keys; secrets and environment values are never written) and applies what can change while running, the
/// parallelism and the priority queue included (owner review 1), and the log settings through <see cref="ServerLogging"/>
/// (owner review 2, R11), and the public ports clients use (owner review 3); the listening ports, TLS and chunk size wait for
/// (owner review 2, R11), the public ports clients use (owner review 3) and the videos folder (owner review 1, R9; checked by
/// <see cref="IsVideosFolder"/>); the listening ports, TLS and chunk size wait for
/// a restart. In a container the listening ports are locked: the template maps them. Job history is what the housekeeping system
/// schedule is reset to (owner review 2, R10): the schedule's own value applies. The audit retention kept here is what the
/// audit clean-up schedule is reset to; the endpoint shows that schedule's age limit in its place and puts a new one there
@@ -27,9 +28,11 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
[
JobKind.Render, JobKind.Import, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse, JobKind.DeepAnalyse, JobKind.Thumbs,
JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move, JobKind.Backup, JobKind.Cleanup,
JobKind.EmptyTrash, JobKind.Convert,
JobKind.EmptyTrash, JobKind.Convert, JobKind.VideoCopy,
];
private static readonly StringComparison PathComparison = OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
private readonly Lock _gate = new();
private ServerSettingsDto? _saved;
@@ -52,8 +55,9 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
Logs = request.Logs ?? before.Logs,
PublicHttpPort = Public(request.PublicHttpPort, before.PublicHttpPort),
PublicHttpsPort = Public(request.PublicHttpsPort, before.PublicHttpsPort),
VideosPath = Videos(request.VideosPath, before.VideosPath),
};
if (Validate(request, before) is { } invalid) return ("invalid_setting", invalid);
if (Validate(request, before, options) is { } invalid) return ("invalid_setting", invalid);
lock (_gate)
{
var current = _saved ?? Snapshot(options, restartRequired: false);
@@ -100,6 +104,8 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
// Read by LAN discovery and the admin redirect at every use: they apply at once.
options.PublicHttpPort = request.PublicHttpPort;
options.PublicHttpsPort = request.PublicHttpsPort;
// Read by every copy request: it applies at once.
options.VideosPath = request.VideosPath;
logging.Apply(options);
var restart = request.HttpPort != options.HttpPort || request.HttpsPort != options.HttpsPort
|| !string.Equals(request.TlsMode, options.TlsMode.ToString(), StringComparison.OrdinalIgnoreCase)
@@ -123,7 +129,41 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
private static ServerSettingsDto Snapshot(ServerOptions o, bool restartRequired) => new(
o.ServerName, o.HttpPort, o.HttpsPort, o.TlsMode.ToString().ToLowerInvariant(), o.TlsCert, o.TlsKey, o.Language, o.Parallelism, o.PriorityQueue,
Priorities(PriorityQueue(o)), o.Discovery, o.MaxUploadBytes, o.ChunkSizeBytes, o.JobHistoryDays, o.TokenLifetimeDays, o.UploadRetentionHours,
Logs(o), LockedSettings(o), LockedBy(o), restartRequired, ProxyWarning: false, o.PublicHttpPort, o.PublicHttpsPort, o.InContainer);
Logs(o), LockedSettings(o), LockedBy(o), restartRequired, ProxyWarning: false, o.PublicHttpPort, o.PublicHttpsPort, o.InContainer,
string.IsNullOrWhiteSpace(o.VideosPath) ? null : o.VideosPath.Trim());
/// <summary>
/// Whether <paramref name="folder"/> may be the videos folder (owner review 1, R9): an absolute folder that is neither the
/// archive nor the data folder nor inside either, so a copy never lands among the files the server indexes or keeps.
/// </summary>
public static bool IsVideosFolder(string folder, ServerOptions options)
{
ArgumentNullException.ThrowIfNull(options);
if (string.IsNullOrWhiteSpace(folder) || folder.Contains('\0', StringComparison.Ordinal) || !Path.IsPathFullyQualified(folder.Trim())) return false;
string full;
try
{
full = Path.TrimEndingDirectorySeparator(Path.GetFullPath(folder.Trim()));
}
catch (Exception ex) when (ex is ArgumentException or NotSupportedException or PathTooLongException)
{
return false;
}
foreach (var root in new[] { options.ArchivePath, options.DataPath })
{
var rootFull = Path.TrimEndingDirectorySeparator(Path.GetFullPath(root));
if (string.Equals(full, rootFull, PathComparison) || full.StartsWith(rootFull + Path.DirectorySeparatorChar, PathComparison)) return false;
}
return true;
}
/// <summary>The videos folder as a request sets it: null keeps <paramref name="current"/>, an empty text clears it.</summary>
private static string? Videos(string? requested, string? current) => requested switch
{
null => current,
_ when string.IsNullOrWhiteSpace(requested) => null,
_ => requested.Trim(),
};
/// <summary>The listening ports, which a container's template maps (owner review 3).</summary>
private static readonly string[] ContainerPorts = [nameof(ServerOptions.HttpPort), nameof(ServerOptions.HttpsPort)];
@@ -177,8 +217,10 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
/// The first setting of <paramref name="r"/> out of range, or null. Listening ports are checked only when they change,
/// so a value the panel cannot change (a container's, the test server's 0) never blocks saving the others.
/// </summary>
private static string? Validate(ServerSettingsDto r, ServerSettingsDto current)
private static string? Validate(ServerSettingsDto r, ServerSettingsDto current, ServerOptions options)
{
// Checked when it changes, so a folder an environment variable sets never blocks saving the others.
if (r.VideosPath is { } videos && videos != current.VideosPath && !IsVideosFolder(videos, options)) return nameof(ServerOptions.VideosPath);
if (string.IsNullOrWhiteSpace(r.ServerName) || r.ServerName.Trim().Length > 60) return nameof(ServerOptions.ServerName);
var portsChanged = r.HttpPort != current.HttpPort || r.HttpsPort != current.HttpsPort;
if (portsChanged && r.HttpPort is < 1 or > 65535) return nameof(ServerOptions.HttpPort);
@@ -244,6 +286,8 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log
Add(nameof(ServerOptions.LogRotation), Rotation(a.Logs.Rotation), Rotation(b.Logs.Rotation), v => JsonValue.Create(v.ToString()));
Add(nameof(ServerOptions.AuditRetentionDays), a.Logs.AuditRetentionDays, b.Logs.AuditRetentionDays, v => JsonValue.Create(v));
Add(nameof(ServerOptions.DiagnosticsLogMb), a.Logs.DiagnosticsLogMb, b.Logs.DiagnosticsLogMb, v => JsonValue.Create(v));
// A cleared videos folder is stored as null, so server.json no longer sets one.
Add(nameof(ServerOptions.VideosPath), a.VideosPath, b.VideosPath, v => v is null ? null : JsonValue.Create(v));
return changes;
}
}