feat: owner review 2 phase 5b: the server as a project home (#17)
CI / Build and test (push) Successful in 9m58s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 14m8s
CI / PostgreSQL 16 integration (push) Successful in 8m55s
CI / PostgreSQL 17 integration (push) Successful in 8m50s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m22s
CI / Build and test (push) Successful in 9m58s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 14m8s
CI / PostgreSQL 16 integration (push) Successful in 8m55s
CI / PostgreSQL 17 integration (push) Successful in 8m50s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m22s
A Chronos Server keeps its sequences' projects, as a PC's archive does: Main and named projects with versions under /api/v1/sequences/{id}/projects, the projects capability and the projectChanged event. The desktop opens a server's sequences in the workspace (proxies downloaded, hash-checked, resumable) with Save version, Sync, conflicts, History, Restore and the project actions against the server. Renders can be of a project version. The admin panel lists a sequence's projects and versions. 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 #17.
This commit is contained in:
1 parent
255e149087
commit
81c303f484
325 files changed
+11477
-516
No files matched your search
@@ -774,32 +774,54 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
var cached = new FileInfo(path) is { Exists: true, Length: > 0 };
|
||||
if (cached && (cachedKind == ProxyCache.Proxy || !offered.Contains(ProxyCache.Proxy))) return (name, cachedKind ?? ProxyCache.Thumb);
|
||||
var part = path + ".part";
|
||||
foreach (var kind in offered)
|
||||
// The cached file is as good as the server's thumbnail.
|
||||
var kind = await DownloadFirstAsync(remote, frameId, offered.TakeWhile(k => !(cached && k == ProxyCache.Thumb)), part, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (kind is not null)
|
||||
{
|
||||
File.Move(part, path, overwrite: true);
|
||||
return (name, kind);
|
||||
}
|
||||
return cached ? (name, ProxyCache.Thumb) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads the first of <paramref name="kinds"/> a frame has on the server (a 404 tries the next) into a fresh
|
||||
/// <paramref name="part"/> file, written through <paramref name="through"/> when given (a hash of what arrives, which
|
||||
/// leaves the file open) and flushed to the disk when <paramref name="durable"/>; the kind it got, or null when the server
|
||||
/// has none of them, no part file left then. The proxy cache and the workspace copy of a server project (owner review 2,
|
||||
/// R8) download alike.
|
||||
/// </summary>
|
||||
internal static async Task<string?> DownloadFirstAsync(ISyncRemote remote, Guid frameId, IEnumerable<string> kinds, string part, Func<Stream, Stream>? through,
|
||||
CancellationToken cancellationToken, bool durable = false)
|
||||
{
|
||||
foreach (var kind in kinds)
|
||||
{
|
||||
// The cached file is as good as the server's thumbnail.
|
||||
if (cached && kind == ProxyCache.Thumb) break;
|
||||
try
|
||||
{
|
||||
await using (var file = new FileStream(part, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
|
||||
await remote.DownloadFrameAsync(frameId, kind, file, cancellationToken).ConfigureAwait(false);
|
||||
File.Move(part, path, overwrite: true);
|
||||
return (name, kind);
|
||||
{
|
||||
await remote.DownloadFrameAsync(frameId, kind, through?.Invoke(file) ?? file, cancellationToken).ConfigureAwait(false);
|
||||
if (durable) file.Flush(flushToDisk: true);
|
||||
}
|
||||
return kind;
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.NotFound)
|
||||
{
|
||||
File.Delete(part);
|
||||
}
|
||||
}
|
||||
return cached ? (name, ProxyCache.Thumb) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A frame missing or damaged on the server: its manifest never asks for its proxy and a pass makes none of a missing
|
||||
/// one, so the thumbnail (or the lack of a file) that stands in for it does not keep the cache stale.
|
||||
/// </summary>
|
||||
private static bool NeverProxied(FrameDto frame) => ((FrameFlags)frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0;
|
||||
internal static bool NeverProxied(FrameDto frame) => ((FrameFlags)frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0;
|
||||
|
||||
private static string[] Kinds(ManifestFrame frame) => (frame.HasProxy, frame.HasThumb) switch
|
||||
/// <summary>The kinds of a frame's assets the server offers, the proxy before the thumbnail that stands in while it has none.</summary>
|
||||
internal static string[] Kinds(ManifestFrame frame) => (frame.HasProxy, frame.HasThumb) switch
|
||||
{
|
||||
(true, true) => [ProxyCache.Proxy, ProxyCache.Thumb],
|
||||
(true, false) => [ProxyCache.Proxy],
|
||||
@@ -867,3 +889,68 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
public ValueTask ReportAsync() => context.ReportAsync(done, total);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A write-only stream that hashes (SHA-256) what passes through it into <paramref name="inner"/>, which it leaves open: the
|
||||
/// hash of a download as it arrived, to check the file it was written to against (owner review 2, R8). It cannot seek,
|
||||
/// so a download through it always starts from the beginning.
|
||||
/// </summary>
|
||||
internal sealed class HashingStream(Stream inner) : Stream
|
||||
{
|
||||
private readonly System.Security.Cryptography.IncrementalHash _hash = System.Security.Cryptography.IncrementalHash.CreateHash(
|
||||
System.Security.Cryptography.HashAlgorithmName.SHA256);
|
||||
|
||||
private long _written;
|
||||
|
||||
/// <summary>The bytes written through.</summary>
|
||||
public long Written => _written;
|
||||
|
||||
/// <summary>The lower-case hex SHA-256 of what was written through (once; it resets the hash).</summary>
|
||||
public string Sha256() => Convert.ToHexStringLower(_hash.GetHashAndReset());
|
||||
|
||||
public override bool CanRead => false;
|
||||
public override bool CanSeek => false;
|
||||
public override bool CanWrite => true;
|
||||
public override long Length => throw new NotSupportedException();
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Flush() => inner.Flush();
|
||||
|
||||
public override Task FlushAsync(CancellationToken cancellationToken) => inner.FlushAsync(cancellationToken);
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
|
||||
public override void SetLength(long value) => throw new NotSupportedException();
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) => Write(buffer.AsSpan(offset, count));
|
||||
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
_hash.AppendData(buffer);
|
||||
_written += buffer.Length;
|
||||
inner.Write(buffer);
|
||||
}
|
||||
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) =>
|
||||
WriteAsync(buffer.AsMemory(offset, count), cancellationToken).AsTask();
|
||||
|
||||
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_hash.AppendData(buffer.Span);
|
||||
_written += buffer.Length;
|
||||
return inner.WriteAsync(buffer, cancellationToken);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) _hash.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user