E2: API delle copie esterne, composizione e dimostrazione

Le copie esterne diventano usabili dall'interfaccia: ExportHub costruisce
l'unico ExportService del web (segna «interrotto» ciò che l'arresto ha
fermato e avvisa le pagine a lavoro finito), ExportApi espone cartelle,
scelta e controllo della cartella, «Copia in…» (piano e avvio), «Copia di
nuovo», avanzamento, lavori, ripresa, annullamento e resoconto.

Gli endpoint esistenti portano le copie: filtro copies= della Libreria,
segno «Copiato» / «Copiato in parte 1/3» sulle tessere, copie di ogni file
nel visualizzatore, riquadro «Copie esterne» e interruttore «Esporta questo
account» nella scheda. Una cartella di account o della libreria che
finirebbe dentro (o attorno a) una cartella delle copie è rifiutata; dopo
una ricostruzione le cartelle in conflitto vanno in pausa.

Composizione: in Docker le copie si scrivono solo sotto /esporta, e solo
con --esporta/FEBE_ESPORTA e un montaggio (riga di avvio e avviso se manca);
sul desktop qualsiasi cartella con la finestra del sistema e lo spazio
libero misurato anche sulle condivisioni di rete. La dimostrazione ha una
cartella generale, una propria, un account non esportato e copie vere in
ogni stato, scritte dal motore nella sua cartella temporanea.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 11:42:02 +01:00
1 parent a112c92893
commit 4a7925ad23
30 files changed
+2299 -32

No files matched your search

@@ -257,6 +257,21 @@ public sealed class ExportDestinations(ExportEnvironment env)
.ToList();
}
/// <summary>
/// After a rebuild of the database (WP1.10 of tappa E2): every destination in use that now overlaps a protected
/// folder is paused with the reason. Nothing is interactive there. Returns the conflicts.
/// </summary>
public async Task<IReadOnlyList<ExportFolderConflict>> RecheckAndPauseAsync(CancellationToken ct)
{
var conflicts = await RecheckAsync(null, ct).ConfigureAwait(false);
foreach (var conflict in conflicts)
{
await ExportPause.PauseAsync(_env, conflict.Destination, conflict.Problem.Message).ConfigureAwait(false);
}
return conflicts;
}
/// <summary>Whether a destination answers now, its pause, its copies and its free space.</summary>
/// <exception cref="KeyNotFoundException">No such destination.</exception>
public async Task<ExportDestinationStatus> StatusAsync(long id, CancellationToken ct)
+3
View File
@@ -110,5 +110,8 @@ public sealed record ExportProgress(
/// <summary>What <c>ExportService.StartAsync</c> did: one run per destination (D6), and the plan it followed.</summary>
public sealed record ExportStart(IReadOnlyList<ExportRun> Runs, ExportPlan Plan);
/// <summary>What «Riprova» of a paused destination did: the reason it is still paused (null: it answers), and the jobs resumed.</summary>
public sealed record ExportRetry(string? Problem, IReadOnlyList<ExportRun> Resumed);
/// <summary>The export job ended (however it ended): the runs it worked on, and whether copies may have changed.</summary>
public sealed record ExportJobFinished(IReadOnlyList<long> RunIds, bool CopiesChanged);
+5 -1
View File
@@ -65,6 +65,9 @@ public sealed record ExportRootOptions
/// <summary>The mount table.</summary>
public IExportMounts Mounts { get; init; } = new ProcMountInfo();
/// <summary>How the page names <see cref="Root"/> (the demo shows «/esporta» for its temporary folder); null: as it is.</summary>
public string? ShownAs { get; init; }
/// <summary>Windows (and development): any folder.</summary>
public static ExportRootOptions AnyFolder { get; } = new() { Declared = true };
@@ -202,7 +205,8 @@ public static class ExportRoots
if (o.Root is { } root && ExportPaths.IsSameOrInside(full, root))
{
var relative = Path.GetRelativePath(root, full);
return relative == "." ? LibraryLayout.ToStored(root) : LibraryLayout.ToStored(root).TrimEnd('/') + "/" + LibraryLayout.ToStored(relative);
var shown = o.ShownAs ?? LibraryLayout.ToStored(root);
return relative == "." ? shown : shown.TrimEnd('/') + "/" + LibraryLayout.ToStored(relative);
}
return full;
+35
View File
@@ -316,6 +316,41 @@ public sealed class ExportService : IAsyncDisposable
StartJob([], (progress, token) => CheckJobAsync(destination, progress, token));
}
/// <summary>
/// «Riprova» of a paused destination: checks it with its probe (WP1.3). Still not writable: it stays paused with the
/// new reason, returned. Writable: the pause goes and, when no other long work runs, its paused jobs resume (oldest
/// first); otherwise they wait for «Riprendi».
/// </summary>
/// <exception cref="KeyNotFoundException">No such destination.</exception>
/// <exception cref="InvalidOperationException">The destination was retired.</exception>
public async Task<ExportRetry> RetryDestinationAsync(long destinationId, CancellationToken ct = default)
{
var destination = await _env.Storage.Exports.GetDestinationAsync(destinationId, ct).ConfigureAwait(false)
?? throw new KeyNotFoundException($"Destinazione di esportazione {destinationId} non trovata.");
if (destination.IsRetired)
{
throw new InvalidOperationException("Questa cartella è stata tolta: non c'è niente da riprovare.");
}
if (await Copier.CheckDestinationAsync(destination, ct).ConfigureAwait(false) is { } problem)
{
await ExportPause.PauseAsync(_env, destination, problem).ConfigureAwait(false);
return new ExportRetry(problem, []);
}
await ExportPause.ClearAsync(_env, destination).ConfigureAwait(false);
var paused = (await _env.Storage.Exports.ListUnfinishedRunsAsync(ct).ConfigureAwait(false))
.Where(r => r.DestinationId == destinationId && r.State == ExportRunState.Paused)
.Select(r => r.Id)
.ToList();
if (paused.Count == 0 || IsBusy || _env.Gate?.Busy is not null)
{
return new ExportRetry(null, []);
}
return new ExportRetry(null, await ResumeAsync(paused, ct).ConfigureAwait(false));
}
/// <summary>The progress of the running job, or a snapshot of the newest job.</summary>
public async Task<ExportProgress> GetProgressAsync(CancellationToken ct = default)
{
+13
View File
@@ -216,6 +216,12 @@ public interface IExportStore
/// </summary>
Task<IReadOnlyDictionary<long, ExportMark>> GetEntryMarksAsync(IReadOnlyList<long> entryIds, CancellationToken ct = default);
/// <summary>
/// As <see cref="GetEntryMarksAsync"/>, with the numbers behind the mark (the «1/3» of «Copiato in parte»): the due
/// files of each entry and how many of them are copied. Entries without due files are absent.
/// </summary>
Task<IReadOnlyDictionary<long, ExportEntryCopies>> GetEntryCopyCountsAsync(IReadOnlyList<long> entryIds, CancellationToken ct = default);
/// <summary>The mark of single files («Tutte le foto»): Copied or None; files that are not due are absent.</summary>
Task<IReadOnlyDictionary<long, ExportMark>> GetFileMarksAsync(IReadOnlyList<long> mediaIds, CancellationToken ct = default);
@@ -245,6 +251,13 @@ public enum ExportMark
Copied,
}
/// <summary>The due files of an entry and how many are copied (decision D3 of tappa E2).</summary>
public sealed record ExportEntryCopies(int Due, int Copied)
{
/// <summary>«Non ancora copiato» (none), «Copiato in parte», «Copiato».</summary>
public ExportMark Mark => Copied <= 0 ? ExportMark.None : Copied >= Due ? ExportMark.Copied : ExportMark.Partly;
}
/// <summary>Counts of the due files of an account (decision D3 of tappa E2).</summary>
/// <param name="Due">Files that go to the account's effective destination.</param>
/// <param name="NotCopied">Due files «Copia in…» would copy: neither copied nor «Tolti o superati» (failed ones included).</param>