fix(app): import gates, partial results and plan editing after review
- a card that leaves needs a new check; formatting re-lists the card and refuses one that changed since its check; files that are not photos are named in the format confirmation - an import never stays stuck in Running; Retry never resumes an older job - server imports list refused files and keep what was uploaded when stopped - the archive result matches each copy to its job's record and shows the job's own error per file - refreshing devices keeps typed titles and choices; titles lock while copying - three destination names, merge and split of sessions, camera profiles shared by the cards of a camera, photo counts and a new-card toast - disabled controls say why; keyboard focus follows the nickname field and Show plan (Esc closes it); label column fits longer languages - capture states for insertion, running, failed and a new card Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
27 files changed
+1286
-285
No files matched your search
@@ -1,4 +1,6 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Import;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
@@ -10,7 +12,9 @@ namespace Titano.App.Import;
|
||||
/// 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.
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public sealed class ServerImportSink(TitanoClient client, string stagingDirectory) : IImportSink
|
||||
{
|
||||
@@ -18,6 +22,9 @@ public sealed class ServerImportSink(TitanoClient client, string stagingDirector
|
||||
|
||||
public string StagingDirectory { get; } = stagingDirectory;
|
||||
|
||||
/// <summary>Every file committed or refused so far, by card path; pass it to <see cref="LocalImport.RunAsync"/>.</summary>
|
||||
public ImportSinkReport Report { get; } = new();
|
||||
|
||||
public async Task<IReadOnlyList<SinkCommit>> CommitAsync(PlannedSession session, IReadOnlyList<StagedFile> files, CancellationToken cancellationToken)
|
||||
{
|
||||
var results = new List<SinkCommit>(files.Count);
|
||||
@@ -28,16 +35,21 @@ public sealed class ServerImportSink(TitanoClient client, string stagingDirector
|
||||
var named = Path.Combine(folder, Path.GetFileName(file.Item.SourcePath));
|
||||
Directory.CreateDirectory(folder);
|
||||
File.Move(file.StagedPath, named);
|
||||
CompleteUploadResponse? committed = null;
|
||||
try
|
||||
{
|
||||
var committed = await client.UploadFileAsync(named, null, file.Item.CapturedAt, session.SessionKey, file.Sha256, null, cancellationToken)
|
||||
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 duplicate = committed is null || committed.Index < 0;
|
||||
results.Add(new SinkCommit(committed?.FrameId, file.Item.FileName, duplicate));
|
||||
if (committed is { Index: >= 0 } && session.Title is { Length: > 0 } title && _titled.Add(committed.SequenceId))
|
||||
await client.UpdateSequenceAsync(committed.SequenceId, new UpdateSequenceRequest(title, null, null, null, null, null), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
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 (TitanoApiException ex) when (IsRefusal(ex))
|
||||
{
|
||||
// The executor has no failed commit: the refusal travels in the report, which turns this result into a failure.
|
||||
Report.Rejected[file.Item.SourcePath] = ex.Error.Message;
|
||||
results.Add(new SinkCommit(null, file.Item.FileName, Duplicate: false));
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -45,7 +57,26 @@ public sealed class ServerImportSink(TitanoClient client, string stagingDirector
|
||||
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 (TitanoApiException 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(TitanoApiException ex) =>
|
||||
!ex.IsTransient && ex.Status is not (HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden) && (int)ex.Status is >= 400 and < 500;
|
||||
}
|
||||
Reference in new issue
Block a user