feat: export panel and Render menu, playback options, videos library (owner review 1 phase 5) (#27)
CI / Build and test (push) Successful in 9m41s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 14m49s
CI / PostgreSQL 16 integration (push) Successful in 8m51s
CI / PostgreSQL 17 integration (push) Successful in 9m48s
CI / Docker image (push) Successful in 54s
Release / Server image (push) Successful in 1m39s

Owner review 1 R3, R8, R9. A grouped Export step and Render menu; encoding, playback (reverse, boomerang, loops, fades, hold) and still frames; one videos library on the desktop and the server with a verified trash and copies to a videos folder.

Closes #21

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 #27.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-05 09:18:40 +01:00
1 parent 188b2c2e55
commit 728ffa35cb
729 files changed
+26954 -1652

No files matched your search

@@ -0,0 +1,56 @@
using Chronos.Core.Model;
namespace Chronos.Data.Repositories;
/// <summary>
/// The verified copies of renders in videos folders (owner review 1, R9; <c>render_copies</c>). There is no link to
/// <c>renders</c>: the copy of a server render downloaded to a PC is recorded too, and a copy outlives its render.
/// </summary>
public sealed class RenderCopyRepository
{
private const string Columns = "id, render_id, path, sha256, bytes, copied_at, copied_by";
private readonly DbAccess _db;
internal RenderCopyRepository(DbAccess db) => _db = db;
public Task<int> InsertAsync(RenderCopy copy, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(copy);
return _db.ExecuteAsync($"INSERT INTO render_copies ({Columns}) VALUES ($1, $2, $3, $4, $5, $6, $7)",
[copy.Id, copy.RenderId, copy.Path, copy.Sha256, copy.Bytes, copy.CopiedAt, copy.CopiedBy], cancellationToken);
}
/// <summary>The copies of a render, oldest first.</summary>
public Task<IReadOnlyList<RenderCopy>> ListByRenderAsync(Guid renderId, CancellationToken cancellationToken = default) =>
_db.ListAsync($"SELECT {Columns} FROM render_copies WHERE render_id = $1 ORDER BY copied_at, id", [renderId], Map, cancellationToken);
/// <summary>The copies of each of <paramref name="renderIds"/>, oldest first; a render without copies is left out.</summary>
public async Task<IReadOnlyDictionary<Guid, IReadOnlyList<RenderCopy>>> ListByRendersAsync(IReadOnlyCollection<Guid> renderIds,
CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(renderIds);
var copies = new Dictionary<Guid, IReadOnlyList<RenderCopy>>();
// In chunks, so the statement stays within every dialect's parameter limit.
foreach (var chunk in renderIds.Distinct().Chunk(200))
{
var p = new SqlParameters();
var list = string.Join(", ", chunk.Select(id => p.Add(id)));
var rows = await _db.ListAsync($"SELECT {Columns} FROM render_copies WHERE render_id IN ({list}) ORDER BY copied_at, id", p.ToArray(), Map,
cancellationToken).ConfigureAwait(false);
foreach (var group in rows.GroupBy(c => c.RenderId)) copies[group.Key] = [.. group];
}
return copies;
}
private static RenderCopy Map(DbRow r) => new()
{
Id = r.GetGuid(0),
RenderId = r.GetGuid(1),
Path = r.GetString(2),
Sha256 = r.GetStringOrNull(3),
Bytes = r.GetInt64(4),
CopiedAt = r.GetDateTimeOffset(5),
CopiedBy = r.GetStringOrNull(6),
};
}
@@ -1,4 +1,6 @@
using Chronos.Core.Model;
using Chronos.Data.Videos;
using Chronos.Protocol;
namespace Chronos.Data.Repositories;
@@ -7,7 +9,7 @@ public sealed class RenderRepository
{
private const string Columns =
"id, sequence_id, preset_name, settings_json, output_path, codec, width, height, fps, duration_seconds, bytes, created, produced_by, project_id, " +
"project_version_id";
"project_version_id, sha256, kind";
private const string RecountSql =
"UPDATE sequences SET rendered_count = (SELECT count(*) FROM renders WHERE sequence_id = $1) WHERE id = $1";
@@ -20,11 +22,11 @@ public sealed class RenderRepository
_db.InTransactionAsync(async session =>
{
await LockSequenceAsync(session, render.SequenceId, cancellationToken).ConfigureAwait(false);
await session.ExecuteAsync($"INSERT INTO renders ({Columns}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
await session.ExecuteAsync($"INSERT INTO renders ({Columns}) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)",
[
render.Id, render.SequenceId, render.PresetName, DbParam.Json(render.SettingsJson), render.OutputPath, render.Codec,
render.Width, render.Height, render.Fps, render.DurationSeconds, render.Bytes, render.Created, render.ProducedBy, render.ProjectId,
render.ProjectVersionId,
render.ProjectVersionId, render.Sha256, render.Kind,
], cancellationToken).ConfigureAwait(false);
return await session.ExecuteAsync(RecountSql, [render.SequenceId], cancellationToken).ConfigureAwait(false);
}, cancellationToken);
@@ -36,6 +38,80 @@ public sealed class RenderRepository
public Task<IReadOnlyList<Render>> ListBySequenceAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
_db.ListAsync($"SELECT {Columns} FROM renders WHERE sequence_id = $1 ORDER BY created DESC, id DESC", [sequenceId], Map, cancellationToken);
/// <summary>
/// One page of every render of the index matching <paramref name="query"/> (the videos library, owner review 1, R9), in
/// its order (<see cref="VideoSorts"/>: newest first unless asked), with the number of renders matching on every page.
/// Text matches the sequence's search text, the preset name or the output path (any case).
/// </summary>
/// <exception cref="FormatException">The cursor is not one of this listing in this order.</exception>
public Task<(IReadOnlyList<Render> Items, string? Next, long Total)> ListPageAsync(VideoQuery query, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(query);
var p = new SqlParameters();
var where = Filter(query, p);
var count = new SqlParameters();
var countWhere = Filter(query, count);
var sort = VideoSorts.All.FirstOrDefault(s => string.Equals(s, query.Sort, StringComparison.OrdinalIgnoreCase)) ?? VideoSorts.Newest;
var scope = "videos:" + sort;
var limit = Math.Clamp(query.Limit, 1, VideoQuery.MaxLimit);
long offset = 0;
string order;
switch (sort)
{
case VideoSorts.Title:
// By title, then newest: paged by position (a title is no key a cursor keeps well).
if (query.Cursor is not null && Cursor.Decode(scope, query.Cursor).Value is long skip) offset = skip;
order = "ORDER BY lower(coalesce(s.title, '')) ASC, r.created DESC, r.id DESC";
break;
default:
{
var (column, descending) = sort switch
{
VideoSorts.Oldest => ("r.created", false),
VideoSorts.Largest => ("r.bytes", true),
_ => ("r.created", true),
};
if (query.Cursor is not null)
{
var (value, id) = Cursor.Decode(scope, query.Cursor);
where.Add(Cursor.After(column, "r.id", descending, value, id, p.Add));
}
var direction = descending ? "DESC" : "ASC";
order = $"ORDER BY {column} {direction}, r.id {direction}";
break;
}
}
var columns = string.Join(", ", Columns.Split(", ").Select(c => "r." + c));
var sql = $"SELECT {columns} FROM renders r JOIN sequences s ON s.id = r.sequence_id{Where(where)} {order} LIMIT {p.Add(limit + 1)}"
+ (offset > 0 ? $" OFFSET {p.Add(offset)}" : string.Empty);
var countSql = $"SELECT count(*) FROM renders r JOIN sequences s ON s.id = r.sequence_id{Where(countWhere)}";
return _db.RunAsync(async session =>
{
var rows = await session.QueryListAsync(sql, p.ToArray(), Map, cancellationToken).ConfigureAwait(false);
var total = await session.ScalarAsync<long>(countSql, count.ToArray(), cancellationToken).ConfigureAwait(false);
string? next = null;
if (rows.Count > limit)
{
rows.RemoveAt(limit);
var last = rows[^1];
next = sort switch
{
VideoSorts.Title => Cursor.Encode(scope, offset + limit, last.Id),
VideoSorts.Largest => Cursor.Encode(scope, last.Bytes, last.Id),
_ => Cursor.Encode(scope, last.Created, last.Id),
};
}
return ((IReadOnlyList<Render>)rows, next, total);
}, cancellationToken);
}
/// <summary>Records the SHA-256 of a render hashed later than it was recorded (owner review 1, R9: renders of before migration 0010).</summary>
public Task<int> SetSha256Async(Guid id, string sha256, CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrEmpty(sha256);
return _db.ExecuteAsync("UPDATE renders SET sha256 = $2 WHERE id = $1", [id, sha256.ToLowerInvariant()], cancellationToken);
}
public Task<bool> DeleteAsync(Guid id, CancellationToken cancellationToken = default) =>
_db.InTransactionAsync(async session =>
{
@@ -93,6 +169,48 @@ public sealed class RenderRepository
if (_db.Sql.IsPostgres) await SequenceRepository.LockAsync(session, sequenceId, cancellationToken).ConfigureAwait(false);
}
/// <summary>The conditions of a videos query on <c>renders r JOIN sequences s</c>.</summary>
private static List<string> Filter(VideoQuery query, SqlParameters p)
{
var where = new List<string>();
if (query.SequenceId is { } sequence) where.Add($"r.sequence_id = {p.Add(sequence)}");
if (!string.IsNullOrWhiteSpace(query.Codec)) where.Add($"lower(r.codec) = {p.Add(query.Codec.Trim().ToLowerInvariant())}");
if (query.Year is { } year and > 0 and < 10000)
{
var from = new DateTimeOffset(year, 1, 1, 0, 0, 0, TimeSpan.Zero);
where.Add($"r.created >= {p.Add(from)} AND r.created < {p.Add(from.AddYears(1))}");
}
// A sequence's codec names end in "sequence" (pngsequence, tiff16sequence…). A still whose kind was lost (uploaded to
// a server of before phase 5) has such a codec with fps 0 and duration 0, as RenderKind.Of tells it apart.
const string ImageCodec = "lower(coalesce(r.codec, '')) LIKE '%sequence'";
const string KindlessStill = $"(r.kind IS NULL AND {ImageCodec} AND coalesce(r.fps, 0) <= 0 AND coalesce(r.duration_seconds, 0) <= 0)";
switch (query.Kind?.Trim().ToLowerInvariant())
{
case null or "":
break;
case RenderKind.Video:
where.Add($"(r.kind IS NULL AND NOT {ImageCodec})");
break;
case RenderKind.Sequence:
where.Add($"(r.kind IS NULL AND {ImageCodec} AND NOT {KindlessStill})");
break;
case RenderKind.Still:
where.Add($"(r.kind = {p.Add(RenderKind.Still)} OR {KindlessStill})");
break;
case var kind:
where.Add($"r.kind = {p.Add(kind)}");
break;
}
if (!string.IsNullOrWhiteSpace(query.Text))
{
var pattern = p.Add(SqlDialect.ContainsPattern(query.Text.Trim().ToLowerInvariant()));
where.Add($"(s.search_text LIKE {pattern} ESCAPE '\\' OR lower(r.preset_name) LIKE {pattern} ESCAPE '\\' OR lower(r.output_path) LIKE {pattern} ESCAPE '\\')");
}
return where;
}
private static string Where(List<string> conditions) => conditions.Count == 0 ? string.Empty : " WHERE " + string.Join(" AND ", conditions);
private static Render Map(DbRow r) => new()
{
Id = r.GetGuid(0),
@@ -110,5 +228,7 @@ public sealed class RenderRepository
ProducedBy = r.GetStringOrNull(12),
ProjectId = r.GetGuidOrNull(13),
ProjectVersionId = r.GetGuidOrNull(14),
Sha256 = r.GetStringOrNull(15),
Kind = r.GetStringOrNull(16),
};
}