feat: owner review 2 phase 1: :latest, Unraid array space, Settings with About, whole-folder import (#9)
CI / Build and test (push) Successful in 5m11s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 8m57s
CI / PostgreSQL 16 integration (push) Successful in 3m10s
CI / PostgreSQL 17 integration (push) Successful in 3m30s
CI / Docker image (push) Successful in 49s
Release / Server image (push) Successful in 1m4s
CI / Build and test (push) Successful in 5m11s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 8m57s
CI / PostgreSQL 16 integration (push) Successful in 3m10s
CI / PostgreSQL 17 integration (push) Successful in 3m30s
CI / Docker image (push) Successful in 49s
Release / Server image (push) Successful in 1m4s
- :latest follows the highest stable release, or the highest pre-release while none is stable (Chronos.Tools release-channels); bad tags are refused before anything is built. - Unraid: CHRONOS_SPACE_PATH and the template's Array view show the array's free space; the write volume (cache) is shown apart; completions check the archive volume (507). - Settings is a gear, docked at the foot of the admin sidebar; About is the last part of Settings on the desktop and the panel. - Import > Folder > Whole folder: one sequence per format (desktop only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #9.
This commit is contained in:
1 parent
5acdf146c7
commit
1f089888e8
320 files changed
+3030
-927
No files matched your search
@@ -14,6 +14,19 @@ public enum DuplicatePolicy
|
||||
ImportAgain,
|
||||
}
|
||||
|
||||
/// <summary>How the planner turns the photos of a source into sequences (BRIEF §12.4, §13).</summary>
|
||||
public enum ImportGrouping
|
||||
{
|
||||
/// <summary>One session per camera body and file format, split where the pause between two photos exceeds the gap.</summary>
|
||||
Sessions,
|
||||
|
||||
/// <summary>
|
||||
/// The whole source (a folder picked on this PC) is one sequence per file format: camera bodies and pauses are
|
||||
/// ignored. RAW+JPEG of the same shots stays two sequences, so no frame is ever doubled.
|
||||
/// </summary>
|
||||
WholeFolder,
|
||||
}
|
||||
|
||||
/// <summary>Card import settings (BRIEF §12.4, §13); the defaults are the brief's.</summary>
|
||||
public sealed record ImportOptions
|
||||
{
|
||||
@@ -25,6 +38,9 @@ public sealed record ImportOptions
|
||||
public bool VerifyCopies { get; init; } = true;
|
||||
public DuplicatePolicy Duplicates { get; init; } = DuplicatePolicy.Skip;
|
||||
|
||||
/// <summary>Sessions, or the whole source as one sequence per format (the session gap and minimum then do not apply).</summary>
|
||||
public ImportGrouping Grouping { get; init; } = ImportGrouping.Sessions;
|
||||
|
||||
/// <summary>Card paths where the user split a session (a new session starts at that photo).</summary>
|
||||
public IReadOnlySet<string> SplitBefore { get; init; } = new HashSet<string>();
|
||||
|
||||
@@ -65,7 +81,10 @@ public sealed record PlannedItem
|
||||
public string? Sha256 { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>A session of the plan: one camera body and file format, one sequence in the archive.</summary>
|
||||
/// <summary>
|
||||
/// A session of the plan: one camera body and file format (a whole folder: one file format), one sequence in the
|
||||
/// archive. Its camera is the one of its first photo.
|
||||
/// </summary>
|
||||
public sealed record PlannedSession
|
||||
{
|
||||
/// <summary>1-based, in order of start time across the import.</summary>
|
||||
@@ -78,6 +97,10 @@ public sealed record PlannedSession
|
||||
public string? CameraMake { get; init; }
|
||||
public string? CameraModel { get; init; }
|
||||
public string? CameraSerial { get; init; }
|
||||
|
||||
/// <summary>Camera bodies among its photos: 1 for a session, possibly more for a whole folder.</summary>
|
||||
public int Cameras { get; init; } = 1;
|
||||
|
||||
public ImageFileFormat Format { get; init; }
|
||||
public DateTime Start { get; init; }
|
||||
public DateTime End { get; init; }
|
||||
@@ -86,6 +109,13 @@ public sealed record PlannedSession
|
||||
public required string Folder { get; init; }
|
||||
|
||||
public string? Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The title when the user types none: the source folder's name for a whole folder; null names the sequence
|
||||
/// after its destination folder.
|
||||
/// </summary>
|
||||
public string? DefaultTitle { get; init; }
|
||||
|
||||
public IReadOnlyList<PlannedItem> Items { get; init; } = [];
|
||||
}
|
||||
|
||||
@@ -99,6 +129,10 @@ public sealed record ImportPlan
|
||||
public required string SourceRoot { get; init; }
|
||||
public required string DestinationRoot { get; init; }
|
||||
public DateTimeOffset Created { get; init; }
|
||||
|
||||
/// <summary>How the photos were grouped into <see cref="Sessions"/>.</summary>
|
||||
public ImportGrouping Grouping { get; init; }
|
||||
|
||||
public IReadOnlyList<PlannedSession> Sessions { get; init; } = [];
|
||||
public IReadOnlyList<ImportProblem> Problems { get; init; } = [];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Naming;
|
||||
|
||||
namespace Chronos.Core.Import;
|
||||
@@ -33,16 +34,29 @@ public static class ImportPlanner
|
||||
{
|
||||
var folderTemplate = PathTemplate.Parse(options.FolderTemplate);
|
||||
var fileTemplate = PathTemplate.Parse(options.FileTemplate);
|
||||
var wholeFolder = options.Grouping == ImportGrouping.WholeFolder;
|
||||
var folderName = wholeFolder ? FolderName(sourceRoot) : null;
|
||||
var drafts = new List<(string Key, List<CardPhoto> Photos)>();
|
||||
foreach (var body in photos.GroupBy(BodyKey, StringComparer.Ordinal))
|
||||
// A whole folder groups by file format alone, never by camera body: RAW+JPEG of the same shots must stay two
|
||||
// sequences, or each frame would appear twice in one.
|
||||
Func<CardPhoto, string> groupKey = wholeFolder ? FormatKey : BodyKey;
|
||||
foreach (var group in photos.GroupBy(groupKey, StringComparer.Ordinal))
|
||||
{
|
||||
var ordered = body.OrderBy(p => p.CaptureTime).ThenBy(p => p.File.RelativePath, StringComparer.Ordinal).ToList();
|
||||
var ranges = SessionSplitter.Split(ordered.ConvertAll(p => p.CaptureTime), options.SessionGap, options.MinimumSessionFrames,
|
||||
i => options.SplitBefore.Contains(ordered[i].File.RelativePath) ? true : options.MergeAt.Contains(ordered[i].File.RelativePath) ? false : null);
|
||||
foreach (var range in ranges)
|
||||
var ordered = group.OrderBy(p => p.CaptureTime).ThenBy(p => p.File.RelativePath, StringComparer.Ordinal).ToList();
|
||||
var times = ordered.ConvertAll(p => p.CaptureTime);
|
||||
bool? UserBreak(int i) =>
|
||||
options.SplitBefore.Contains(ordered[i].File.RelativePath) ? true : options.MergeAt.Contains(ordered[i].File.RelativePath) ? false : null;
|
||||
// Only the user's splits break a whole folder: no pause starts a session and no group is too small to stand.
|
||||
var ranges = wholeFolder
|
||||
? SessionSplitter.Split(times, TimeSpan.MaxValue, 1, UserBreak)
|
||||
: SessionSplitter.Split(times, options.SessionGap, options.MinimumSessionFrames, UserBreak);
|
||||
for (var r = 0; r < ranges.Count; r++)
|
||||
{
|
||||
var members = ordered.GetRange(range.Start, range.Count);
|
||||
drafts.Add((SessionKey(body.Key, members[0].CaptureTime), members));
|
||||
var members = ordered.GetRange(ranges[r].Start, ranges[r].Count);
|
||||
var key = wholeFolder
|
||||
? FolderKey(sourceRoot, members[0].Metadata.Format, r == 0 ? null : members[0].CaptureTime)
|
||||
: SessionKey(group.Key, members[0].CaptureTime);
|
||||
drafts.Add((key, members));
|
||||
}
|
||||
}
|
||||
drafts.Sort((a, b) => a.Photos[0].CaptureTime.CompareTo(b.Photos[0].CaptureTime) is var c and not 0 ? c : string.CompareOrdinal(a.Key, b.Key));
|
||||
@@ -53,7 +67,7 @@ public static class ImportPlanner
|
||||
{
|
||||
var (key, members) = drafts[s];
|
||||
var first = members[0];
|
||||
options.Titles.TryGetValue(key, out var title);
|
||||
var title = options.Titles.GetValueOrDefault(key) ?? folderName;
|
||||
var context = Context(first, first.CaptureTime, s + 1, 1, title);
|
||||
var folder = await lookup.FindSessionFolderAsync(key, cancellationToken).ConfigureAwait(false)
|
||||
?? UniqueFolder(folderTemplate.ExpandFolder(context), claimedFolders, lookup);
|
||||
@@ -74,11 +88,13 @@ public static class ImportPlanner
|
||||
CameraMake = first.Metadata.Make,
|
||||
CameraModel = first.Metadata.Model,
|
||||
CameraSerial = first.Metadata.BodySerial,
|
||||
Cameras = CountCameras(members),
|
||||
Format = first.Metadata.Format,
|
||||
Start = first.CaptureTime,
|
||||
End = members[^1].CaptureTime,
|
||||
Folder = folder,
|
||||
Title = title,
|
||||
DefaultTitle = folderName,
|
||||
Items = items,
|
||||
});
|
||||
}
|
||||
@@ -88,6 +104,7 @@ public static class ImportPlanner
|
||||
SourceRoot = Path.GetFullPath(sourceRoot),
|
||||
DestinationRoot = Path.GetFullPath(destinationRoot),
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
Grouping = options.Grouping,
|
||||
Sessions = sessions,
|
||||
Problems = problems,
|
||||
AvailableBytes = FreeSpace(destinationRoot),
|
||||
@@ -139,12 +156,41 @@ public static class ImportPlanner
|
||||
};
|
||||
|
||||
/// <summary>Camera body and file format: RAW+JPEG shooting yields two sequences instead of doubled frames.</summary>
|
||||
private static string BodyKey(CardPhoto p) => $"{p.Metadata.Make}|{p.Metadata.Model}|{p.Metadata.BodySerial}|{p.Metadata.Format}";
|
||||
private static string BodyKey(CardPhoto p) => $"{CameraKey(p)}|{p.Metadata.Format}";
|
||||
|
||||
private static string CameraKey(CardPhoto p) => $"{p.Metadata.Make}|{p.Metadata.Model}|{p.Metadata.BodySerial}";
|
||||
|
||||
/// <summary>Camera bodies that took the photos; a photo without a camera in its metadata is no body of its own.</summary>
|
||||
private static int CountCameras(List<CardPhoto> photos) =>
|
||||
System.Math.Max(1, photos.Where(p => p.Metadata.Model is not null).Select(CameraKey).Distinct(StringComparer.Ordinal).Count());
|
||||
|
||||
/// <summary>File format alone (a whole folder): RAW+JPEG still yields two sequences instead of doubled frames.</summary>
|
||||
private static string FormatKey(CardPhoto p) => p.Metadata.Format.ToString();
|
||||
|
||||
private static string SessionKey(string bodyKey, DateTime start) =>
|
||||
"card-" + Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(bodyKey)))[..8] + "-"
|
||||
+ start.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// The key of a whole folder's sequence: the same folder of this PC and the same format always give the same key,
|
||||
/// so an interrupted import resumes into its sequence and a later import of the folder adds to it. A part the user
|
||||
/// split off also carries the time of its first photo.
|
||||
/// </summary>
|
||||
internal static string FolderKey(string sourceRoot, ImageFileFormat format, DateTime? splitAt = null)
|
||||
{
|
||||
var path = Path.TrimEndingDirectorySeparator(Path.GetFullPath(sourceRoot));
|
||||
// Windows compares paths without case: D:\Trip and d:\trip are one folder.
|
||||
if (OperatingSystem.IsWindows()) path = path.ToUpperInvariant();
|
||||
// The same path on another PC is another folder: a server files every client's uploads by these keys.
|
||||
var identity = $"{Environment.MachineName.ToUpperInvariant()}|{path}|{format}";
|
||||
var key = "folder-" + Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(identity)))[..16];
|
||||
return splitAt is { } start ? key + "-" + start.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture) : key;
|
||||
}
|
||||
|
||||
/// <summary>The picked folder's own name, the default title of a whole folder; null for a drive root.</summary>
|
||||
private static string? FolderName(string sourceRoot) =>
|
||||
Path.GetFileName(Path.TrimEndingDirectorySeparator(Path.GetFullPath(sourceRoot))) is { Length: > 0 } name ? name : null;
|
||||
|
||||
private static string UniqueFolder(string folder, HashSet<string> claimed, IImportLookup lookup)
|
||||
{
|
||||
if (folder.Length == 0) folder = "Import";
|
||||
|
||||
Reference in new issue
Block a user