Two parallel files: hash, resumable upload through a transport, then verified or already-on-server. Failed items retry after 30 s up to 3 times on top of the client's transient retries; an unreachable server requeues without spending a retry. A new-sequence batch creates its sequence once. "Delete after upload" removes only files the server confirmed and that still match the hashed size and write time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using Titano.Protocol.Client;
|
|
|
|
namespace Titano.Uploader.Uploads;
|
|
|
|
/// <summary>How the server answered a successful upload.</summary>
|
|
public enum UploadOutcome
|
|
{
|
|
/// <summary>Committed after the server checked the SHA-256 (<c>CompleteUploadResponse</c>).</summary>
|
|
Verified,
|
|
|
|
/// <summary>The server already held this SHA-256 (<c>AlreadyExists</c>).</summary>
|
|
AlreadyOnServer,
|
|
}
|
|
|
|
/// <summary>What the upload needs from the server connection.</summary>
|
|
public interface IUploadTransport
|
|
{
|
|
/// <summary>True while signed in and reachable; the engine waits otherwise.</summary>
|
|
bool IsReady { get; }
|
|
|
|
/// <summary>Raised (on the UI thread) when <see cref="IsReady"/> changes.</summary>
|
|
event EventHandler? ReadyChanged;
|
|
|
|
/// <summary>
|
|
/// Sends one file whose hash is known. Throws <see cref="ServerUnavailableException"/> when the server cannot be
|
|
/// used right now (offline, signed out, certificate changed); other failures concern this file only.
|
|
/// </summary>
|
|
Task<(UploadOutcome Outcome, Guid? FrameId)> UploadAsync(UploadItem item, Guid? sequenceId, string sha256, IProgress<UploadProgress> progress, CancellationToken ct);
|
|
|
|
/// <summary>Creates a sequence for a "new sequence" batch.</summary>
|
|
Task<Guid> CreateSequenceAsync(string? title, CancellationToken ct);
|
|
}
|
|
|
|
/// <summary>Why the server cannot be used.</summary>
|
|
public enum ServerProblem
|
|
{
|
|
Unreachable,
|
|
SignedOut,
|
|
CertificateChanged,
|
|
}
|
|
|
|
/// <summary>The server cannot take uploads right now; the item goes back in line without spending a retry.</summary>
|
|
public sealed class ServerUnavailableException(ServerProblem problem, Exception? inner = null)
|
|
: Exception("Server unavailable: " + problem, inner)
|
|
{
|
|
public ServerProblem Problem { get; } = problem;
|
|
}
|