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

+129
View File
@@ -0,0 +1,129 @@
using Febe.Core.Abstractions;
using Febe.Core.Export;
using Febe.Core.Storage;
using Febe.Web.Demo;
using Febe.Web.Import;
using Febe.Web.Library;
using Microsoft.AspNetCore.Http;
namespace Febe.Web.Export;
/// <summary>
/// The copies to external folders of the web host (spec §4.10, tappa E2): one <see cref="ExportService"/> over the
/// library of the web host, built at the first use and never rebuilt (the library layout is read at every use, so a
/// new library folder on Windows needs nothing here). At the first use the jobs left running by the last stop become
/// «interrotto» (<see cref="Recovered"/>). When a job ends, the open pages refresh tiles and filter through the
/// <c>libreria</c> event.
/// </summary>
public sealed class ExportHub : IAsyncDisposable
{
private readonly SemaphoreSlim _gate = new(1, 1);
private readonly IFebeStorage _storage;
private readonly FebeLibrary _library;
private readonly IClock _clock;
private readonly IMediaFileResolver _files;
private readonly FebeWebOptions _options;
private readonly LongWorkGate _longWork;
private readonly IEngineSessionState _session;
private readonly IExportDisk _disk;
private readonly LibraryChanges _changes;
private readonly ImportHub _import;
private ExportService? _service;
public ExportHub(
IFebeStorage storage,
FebeLibrary library,
IClock clock,
IMediaFileResolver files,
ExportRootOptions root,
FebeWebOptions options,
LongWorkGate longWork,
IEngineSessionState session,
IExportDisk disk,
LibraryChanges changes,
ImportHub import)
{
_storage = storage ?? throw new ArgumentNullException(nameof(storage));
_library = library ?? throw new ArgumentNullException(nameof(library));
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
_files = files ?? throw new ArgumentNullException(nameof(files));
Root = root ?? throw new ArgumentNullException(nameof(root));
_options = options ?? throw new ArgumentNullException(nameof(options));
_longWork = longWork ?? throw new ArgumentNullException(nameof(longWork));
_session = session ?? throw new ArgumentNullException(nameof(session));
_disk = disk ?? throw new ArgumentNullException(nameof(disk));
_changes = changes ?? throw new ArgumentNullException(nameof(changes));
_import = import ?? throw new ArgumentNullException(nameof(import));
}
/// <summary>Where destinations may be chosen (Docker: <c>/esporta</c>), as the composition registered it.</summary>
public ExportRootOptions Root { get; }
/// <summary>Jobs that the first use found running and made «interrotto» (the last stop interrupted them).</summary>
public int Recovered { get; private set; }
/// <summary>
/// The root as a request sees it: in the demo the desktop look shows any folder (with the native picker of the
/// demo shell), the Docker look the subfolders of the demo's <c>/esporta</c>. Elsewhere, <see cref="Root"/>.
/// </summary>
public ExportRootOptions RootFor(HttpContext? context) =>
_options.Demo && DemoRequest.Edition(context) != FebeEdition.Docker ? ExportRootOptions.AnyFolder : Root;
/// <summary>The service, built at the first use (with the recovery of interrupted jobs).</summary>
public async Task<ExportService> GetAsync(CancellationToken ct = default)
{
if (_service is { } ready)
{
return ready;
}
await _gate.WaitAsync(ct).ConfigureAwait(false);
try
{
if (_service is null)
{
var service = new ExportService(new ExportEnvironment
{
Storage = _storage,
Layout = () => _library.Layout,
DataFolder = _library.Data.Root,
Clock = _clock,
ImportRoot = _import.SourceRoot,
Root = Root,
ResolveSource = (account, media) => _files.Resolve(account, media),
Disk = _disk,
Session = _session,
Gate = _longWork,
});
service.JobFinished += OnJobFinished;
Recovered = await service.RecoverAsync(ct).ConfigureAwait(false);
_service = service;
}
return _service;
}
finally
{
_gate.Release();
}
}
public async ValueTask DisposeAsync()
{
if (_service is { } service)
{
service.JobFinished -= OnJobFinished;
await service.DisposeAsync().ConfigureAwait(false);
}
_gate.Dispose();
}
private void OnJobFinished(object? sender, ExportJobFinished finished)
{
if (finished.CopiesChanged)
{
_changes.Publish(new LibraryChange(_clock.Now, null, "export"));
}
}
}