refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. 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 #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,252 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
|
||||
namespace Chronos.App.Import;
|
||||
|
||||
/// <summary>
|
||||
/// Import destination "Server" (BRIEF §12.4, §14.4): each verified copy staged on this PC is uploaded with the
|
||||
/// protocol's resumable chunks and the hash computed while copying; the server checks that hash before it commits the
|
||||
/// frame, and only then does the photo count as imported. Photos of one plan session share its session key, so the
|
||||
/// server files them in one sequence — the same one when an interrupted import is started again. A typed session
|
||||
/// title is set on that sequence once. A file the server refuses (a hash mismatch, a format it rejects) is listed in
|
||||
/// <see cref="Report"/> and the import goes on (BRIEF §13: errors per file); a failed connection, sign-in or server
|
||||
/// stops it. A file the server already held counts as a duplicate: the server answers so only for a copy that is not
|
||||
/// flagged missing or damaged, and a server import never deletes anything from the card.
|
||||
/// </summary>
|
||||
public sealed class ServerImportSink(ChronosClient client, string stagingDirectory) : IImportSink
|
||||
{
|
||||
private readonly HashSet<Guid> _titled = [];
|
||||
|
||||
public string StagingDirectory { get; } = stagingDirectory;
|
||||
|
||||
/// <summary>The copies wait in this PC's cache folder until they are uploaded: the server's space is its quota.</summary>
|
||||
public bool StagesOnThisPc => true;
|
||||
|
||||
/// <summary>Every file committed or refused so far, by card path; pass it to <see cref="LocalImport.RunAsync"/>.</summary>
|
||||
public ImportSinkReport Report { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Runs a confirmed plan into the server through this sink (<see cref="LocalImport.RunAsync"/>) and tells the server's
|
||||
/// other clients about it as <paramref name="card"/> (BRIEF §14.3 <c>cardEvent</c>): started, its progress, and
|
||||
/// finished, also when it stopped early.
|
||||
/// </summary>
|
||||
public async Task<ImportOutcome> RunAsync(ImportPlan plan, string card, bool verify, IProgress<ImportProgress>? progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var events = new CardImportReporter(client, plan.Id, card, plan.FileCount);
|
||||
events.Started();
|
||||
ImportOutcome? outcome = null;
|
||||
try
|
||||
{
|
||||
outcome = await LocalImport.RunAsync(plan, this, card, verify, events.Forward(progress), cancellationToken, Report).ConfigureAwait(false);
|
||||
return outcome;
|
||||
}
|
||||
finally
|
||||
{
|
||||
await events.FinishedAsync(outcome).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<SinkCommit>> CommitAsync(PlannedSession session, IReadOnlyList<StagedFile> files, CancellationToken cancellationToken)
|
||||
{
|
||||
var results = new List<SinkCommit>(files.Count);
|
||||
foreach (var file in files)
|
||||
{
|
||||
// The server records the uploaded file name as the original name: upload the card's name, not the staging name.
|
||||
var folder = Path.Combine(StagingDirectory, Path.GetFileNameWithoutExtension(file.StagedPath));
|
||||
var named = Path.Combine(folder, Path.GetFileName(file.Item.SourcePath));
|
||||
Directory.CreateDirectory(folder);
|
||||
File.Move(file.StagedPath, named);
|
||||
CompleteUploadResponse? committed = null;
|
||||
try
|
||||
{
|
||||
committed = await client.UploadFileAsync(named, null, file.Item.CapturedAt, session.SessionKey, file.Sha256, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
// An upload the server already held reports no position in a sequence.
|
||||
var result = new SinkCommit(committed?.FrameId, file.Item.FileName, committed is null || committed.Index < 0);
|
||||
Report.Committed[file.Item.SourcePath] = result;
|
||||
results.Add(result);
|
||||
}
|
||||
catch (ChronosApiException ex) when (IsRefusal(ex))
|
||||
{
|
||||
// The executor has no failed commit: the refusal travels in the report, which turns this result into a failure. The
|
||||
// server words its refusal in the client's language; one without words reads as the catalog's sentence.
|
||||
Report.Rejected[file.Item.SourcePath] = ErrorText.ForServer(ex);
|
||||
results.Add(new SinkCommit(null, file.Item.FileName, Duplicate: false));
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Our own staged copy; the original stays on the card.
|
||||
File.Delete(named);
|
||||
Directory.Delete(folder);
|
||||
}
|
||||
if (committed is { Index: >= 0 } && session.Title is { Length: > 0 } title && _titled.Add(committed.SequenceId))
|
||||
await SetTitleAsync(committed.SequenceId, title, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>A refused title leaves the photos imported under the sequence's own name.</summary>
|
||||
private async Task SetTitleAsync(Guid sequenceId, string title, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
await client.UpdateSequenceAsync(sequenceId, new UpdateSequenceRequest(title, null, null, null, null, null), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (ChronosApiException ex) when (IsRefusal(ex))
|
||||
{
|
||||
Log.Warning("import", $"The server refused the title of sequence {sequenceId}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The server refused this file; other files may still go through (unlike a busy server or a lost sign-in).</summary>
|
||||
private static bool IsRefusal(ChronosApiException ex) =>
|
||||
!ex.IsTransient && ex.Status is not (HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) && (int)ex.Status is >= 400 and < 500;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The reports of one card import into the server (BRIEF §14.3 <c>cardEvent</c>, §14.4), sent one at a time and in order:
|
||||
/// progress at most once a second, and a progress report still waiting is replaced by the next report, so a slow or
|
||||
/// unreachable server never piles them up. A report that fails is logged and the import goes on; a server without the
|
||||
/// endpoint (404) gets no more reports. Once the import is over its end gets two seconds to reach the server, then
|
||||
/// whatever is still on its way is given up.
|
||||
/// </summary>
|
||||
/// <param name="total">Photos of the plan, skipped ones included (like <see cref="ImportProgress.ItemsTotal"/>).</param>
|
||||
public sealed class CardImportReporter(ChronosClient client, Guid importId, string card, int total, TimeProvider? time = null)
|
||||
{
|
||||
private static readonly TimeSpan ProgressInterval = TimeSpan.FromSeconds(1);
|
||||
private static readonly TimeSpan SendTimeout = TimeSpan.FromSeconds(10);
|
||||
private static readonly TimeSpan FinishWait = TimeSpan.FromSeconds(2);
|
||||
|
||||
private readonly TimeProvider _time = time ?? TimeProvider.System;
|
||||
private readonly CancellationTokenSource _stop = new();
|
||||
private readonly Lock _gate = new();
|
||||
private readonly List<CardImportReport> _queue = [];
|
||||
private Task _sending = Task.CompletedTask;
|
||||
private bool _draining;
|
||||
private bool _finished;
|
||||
private bool _unsupported;
|
||||
private long? _lastProgress;
|
||||
private ImportProgress? _latest;
|
||||
|
||||
public void Started() => Post(CardImportStates.Started, 0, 0);
|
||||
|
||||
/// <summary>Progress that reaches <paramref name="inner"/> (the screen's own) and these reports.</summary>
|
||||
public IProgress<ImportProgress> Forward(IProgress<ImportProgress>? inner) => new Forwarding(this, inner);
|
||||
|
||||
public void Report(ImportProgress progress)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_latest = progress;
|
||||
var now = _time.GetTimestamp();
|
||||
if (_lastProgress is { } last && _time.GetElapsedTime(last, now) < ProgressInterval) return;
|
||||
_lastProgress = now;
|
||||
}
|
||||
Post(CardImportStates.Progress, progress.ItemsDone, progress.Failed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the end: every photo handled when the import gave an <paramref name="outcome"/>, else as far as its progress
|
||||
/// got. Waits at most two seconds for the reports still queued, then stops sending: an import that was cancelled or
|
||||
/// lost its server ends at once instead of waiting for a server that does not answer.
|
||||
/// </summary>
|
||||
public async Task FinishedAsync(ImportOutcome? outcome)
|
||||
{
|
||||
int done, failed;
|
||||
Task sending;
|
||||
lock (_gate)
|
||||
{
|
||||
done = outcome is null ? _latest?.ItemsDone ?? 0 : total;
|
||||
failed = outcome?.Failures.Count ?? _latest?.Failed ?? 0;
|
||||
}
|
||||
Post(CardImportStates.Finished, done, failed);
|
||||
lock (_gate) sending = _sending;
|
||||
try
|
||||
{
|
||||
await sending.WaitAsync(FinishWait, _time).ConfigureAwait(false);
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Log.Info("import", $"The last reports of the import from {card} were given up: the server did not take them in time");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Nothing is sent once the import is over: its client goes next.
|
||||
await _stop.CancelAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void Post(string state, int done, int failed)
|
||||
{
|
||||
var report = new CardImportReport(importId, card, state, Math.Clamp(done, 0, total), total, Math.Clamp(failed, 0, total));
|
||||
lock (_gate)
|
||||
{
|
||||
if (_finished || _unsupported) return;
|
||||
_finished = state == CardImportStates.Finished;
|
||||
if (_queue.Count > 0 && _queue[^1].State == CardImportStates.Progress) _queue[^1] = report;
|
||||
else _queue.Add(report);
|
||||
if (_draining) return;
|
||||
_draining = true;
|
||||
_sending = Task.Run(DrainAsync);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DrainAsync()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
CardImportReport report;
|
||||
lock (_gate)
|
||||
{
|
||||
if (_queue.Count == 0 || _unsupported || _stop.IsCancellationRequested)
|
||||
{
|
||||
_queue.Clear();
|
||||
_draining = false;
|
||||
return;
|
||||
}
|
||||
report = _queue[0];
|
||||
_queue.RemoveAt(0);
|
||||
}
|
||||
await SendAsync(report).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SendAsync(CardImportReport report)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(_stop.Token);
|
||||
timeout.CancelAfter(SendTimeout);
|
||||
await client.ReportCardAsync(report, timeout.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException) when (_stop.IsCancellationRequested)
|
||||
{
|
||||
// The import is over and did not wait for this one.
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status is HttpStatusCode.NotFound or HttpStatusCode.MethodNotAllowed)
|
||||
{
|
||||
// A server from before card events.
|
||||
lock (_gate) _unsupported = true;
|
||||
Log.Info("import", $"The server takes no card reports ({ex.Error.Code})");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// The reports only inform the other clients: nothing about them may stop or fail the import.
|
||||
Log.Warning("import", $"The {report.State} report of the import from {card} did not reach the server", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Forwarding(CardImportReporter reporter, IProgress<ImportProgress>? inner) : IProgress<ImportProgress>
|
||||
{
|
||||
public void Report(ImportProgress value)
|
||||
{
|
||||
inner?.Report(value);
|
||||
reporter.Report(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user