feat(app): import and archive manager logic (plans, card pool, card gate, server sink, tree, charts, reports)
Plain classes behind the Import and Archive screens: plan totals, session rows and the Show plan listing; duplicate and title choices without a new scan; folder and server destinations with the protocol client's chunked, hash-verified uploads; the after-import gate that allows deleting or formatting a card only after a verified archive import and a dry run; the archive tree, chart aggregation, mass rename/retag and maintenance reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
22 files changed
+2258
No files matched your search
@@ -0,0 +1,93 @@
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.App.Jobs;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.App.Archiving;
|
||||
|
||||
/// <summary>A group of identical photos: the copies and where they are; the first one counts as the original.</summary>
|
||||
public sealed record DuplicateRow(string Title, string Detail, IReadOnlyList<string> Places, Guid SequenceId);
|
||||
|
||||
/// <summary>What an orphan line is about, which decides its fix.</summary>
|
||||
public enum OrphanKind
|
||||
{
|
||||
/// <summary>Photos in a sequence folder that its sidecar does not list: fix = index them.</summary>
|
||||
UnlistedFiles,
|
||||
|
||||
/// <summary>Frames whose file is gone: fix = reconcile (flags them missing in sidecar and index).</summary>
|
||||
MissingFiles,
|
||||
|
||||
/// <summary>An index row whose folder has no sidecar any more: fix = remove the row (after confirmation).</summary>
|
||||
MissingSequence,
|
||||
|
||||
/// <summary>A folder with photos the index does not know yet: fix = scan.</summary>
|
||||
NewFolder,
|
||||
}
|
||||
|
||||
/// <summary>One line of the orphans report and the target of its fix.</summary>
|
||||
public sealed record OrphanRow(OrphanKind Kind, string Title, string Detail, Guid? SequenceId);
|
||||
|
||||
/// <summary>A line of "Recent maintenance": date, operation and outcome.</summary>
|
||||
public sealed record MaintenanceRow(Guid JobId, string DateText, string Text, string StateText, JobState State);
|
||||
|
||||
/// <summary>
|
||||
/// The Maintenance view's reports (BRIEF §12.5): duplicates across sequences, orphans with their safe fixes, and the
|
||||
/// recent archive jobs. Nothing here deletes a file; the only removal is of index rows whose sidecar is gone.
|
||||
/// </summary>
|
||||
public static class MaintenanceReports
|
||||
{
|
||||
/// <summary>Kinds of jobs listed under "Recent maintenance".</summary>
|
||||
public static readonly IReadOnlyList<JobKind> MaintenanceKinds = [JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.Maintenance];
|
||||
|
||||
public static IReadOnlyList<DuplicateRow> Duplicates(IReadOnlyList<DuplicateGroup> groups, IReadOnlyList<SequenceLocation> locations)
|
||||
{
|
||||
var titles = locations.ToDictionary(l => l.Id, l => l.Title ?? l.Folder[(l.Folder.LastIndexOf('/') + 1)..]);
|
||||
return
|
||||
[
|
||||
.. groups.Where(g => g.Frames.Count > 1).Select(g =>
|
||||
{
|
||||
var first = g.Frames[0];
|
||||
var name = first.RelativePath[(first.RelativePath.LastIndexOf('/') + 1)..];
|
||||
var places = g.Frames.Select(f => Loc.L("Archive.Duplicates.Place", titles.GetValueOrDefault(f.SequenceId, f.RelativePath), f.RelativePath)).ToList();
|
||||
return new DuplicateRow(name, Loc.Plural("Archive.Duplicates.Copies", g.Frames.Count), places, first.SequenceId);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public static IReadOnlyList<OrphanRow> Orphans(OrphanReport report, IReadOnlyList<SequenceLocation> locations)
|
||||
{
|
||||
var byFolder = locations.ToDictionary(l => l.Folder, StringComparer.Ordinal);
|
||||
var rows = new List<OrphanRow>();
|
||||
foreach (var s in report.Sequences)
|
||||
{
|
||||
byFolder.TryGetValue(s.Folder, out var location);
|
||||
var title = location?.Title ?? s.Folder;
|
||||
if (s.UnindexedFiles.Count > 0)
|
||||
rows.Add(new OrphanRow(OrphanKind.UnlistedFiles, title, Loc.Plural("Archive.Orphans.Unlisted", s.UnindexedFiles.Count), location?.Id));
|
||||
if (s.MissingFiles.Count > 0)
|
||||
rows.Add(new OrphanRow(OrphanKind.MissingFiles, title, Loc.Plural("Archive.Orphans.Missing", s.MissingFiles.Count), location?.Id));
|
||||
}
|
||||
foreach (var missing in report.MissingSequences)
|
||||
rows.Add(new OrphanRow(OrphanKind.MissingSequence, missing.Title ?? missing.Folder, Loc.L("Archive.Orphans.NoSidecar", missing.Folder), missing.Id));
|
||||
foreach (var folder in report.UnindexedFolders)
|
||||
rows.Add(new OrphanRow(OrphanKind.NewFolder, folder.Length == 0 ? "/" : folder, Loc.L("Archive.Orphans.NewFolder"), null));
|
||||
return rows;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<MaintenanceRow> Recent(IEnumerable<Job> jobs, int count) =>
|
||||
[
|
||||
.. jobs.OrderByDescending(j => j.Finished ?? j.Started ?? j.Created).Take(count).Select(j =>
|
||||
{
|
||||
var when = j.Finished ?? j.Started ?? j.Created;
|
||||
var text = string.IsNullOrWhiteSpace(j.TargetLabel) ? JobText.Kind(j.Kind) : Loc.L("Archive.Recent.Line", JobText.Kind(j.Kind), j.TargetLabel);
|
||||
var state = j.State switch
|
||||
{
|
||||
JobState.Running when j.ProgressTotal > 0 => Formatting.Percent(j.ProgressDone / (double)j.ProgressTotal),
|
||||
_ => Loc.L("Jobs.State." + j.State),
|
||||
};
|
||||
return new MaintenanceRow(j.Id, Formatting.Date(when), text, state, j.State);
|
||||
}),
|
||||
];
|
||||
}
|
||||
Reference in new issue
Block a user