feat(core): archive layout, sidecars, leases and thumbnail packs
archive.json and sequence.json with source-generated JSON, forward-compatible reading (unknown fields kept, unknown enum names tolerated) and atomic writes; lease files with expiry and stale takeover; thumbs.pack with index, crash-safe append and random access; folder scanning, in-place adoption, reconcile, verify, index snapshot, rename planning and thumbnail/proxy rendering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
24 files changed
+2556
No files matched your search
@@ -0,0 +1,86 @@
|
||||
using Titano.Core.Metadata;
|
||||
using Titano.Core.Model;
|
||||
|
||||
namespace Titano.Core.Archiving;
|
||||
|
||||
/// <summary>Edits of the frame list of a <see cref="SequenceManifest"/>; frames stay in capture order with gap-free indexes.</summary>
|
||||
public static class SequenceFrames
|
||||
{
|
||||
/// <summary>Capture time (unknown last), then file name.</summary>
|
||||
public static readonly IComparer<SidecarFrame> CaptureOrder = Comparer<SidecarFrame>.Create((a, b) =>
|
||||
{
|
||||
var byTime = (a.CapturedAt ?? DateTime.MaxValue).CompareTo(b.CapturedAt ?? DateTime.MaxValue);
|
||||
return byTime != 0 ? byTime : string.CompareOrdinal(a.File, b.File);
|
||||
});
|
||||
|
||||
/// <summary>A frame record from light metadata.</summary>
|
||||
/// <param name="file">Path relative to the sequence folder.</param>
|
||||
/// <param name="fallbackCapture">Used when the file records no capture time of its own (only a file-system date).</param>
|
||||
public static SidecarFrame FromMetadata(Guid id, string file, string? original, long size, string? sha256, FrameMetadata metadata,
|
||||
DateTime? fallbackCapture = null)
|
||||
{
|
||||
var useFallback = fallbackCapture is not null && metadata.TimestampSource is TimestampSource.FileSystem or TimestampSource.Unknown;
|
||||
return new SidecarFrame
|
||||
{
|
||||
Id = id,
|
||||
File = file,
|
||||
Original = original,
|
||||
Size = size,
|
||||
Sha256 = sha256?.ToLowerInvariant(),
|
||||
CapturedAt = useFallback ? DateTime.SpecifyKind(fallbackCapture!.Value, DateTimeKind.Unspecified) : metadata.CapturedAt,
|
||||
UtcOffset = useFallback ? null : metadata.UtcOffsetMinutes,
|
||||
TimeSource = useFallback ? TimestampSource.Unknown : metadata.TimestampSource,
|
||||
Exposure = metadata.ExposureTime,
|
||||
FNumber = metadata.FNumber,
|
||||
Iso = metadata.Iso,
|
||||
Focal = metadata.FocalLength,
|
||||
Bias = metadata.ExposureBias,
|
||||
Wb = metadata.WhiteBalanceMode,
|
||||
Orientation = metadata.Orientation,
|
||||
W = metadata.Width,
|
||||
H = metadata.Height,
|
||||
Format = metadata.Format,
|
||||
PreviewOffset = metadata.LargestPreview?.Offset,
|
||||
PreviewLength = metadata.LargestPreview?.Length,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges <paramref name="added"/> into the frame list by capture time (existing frames keep their relative order),
|
||||
/// renumbers indexes and bumps the frames version.
|
||||
/// </summary>
|
||||
public static SequenceManifest Insert(SequenceManifest manifest, IReadOnlyList<SidecarFrame> added)
|
||||
{
|
||||
if (added.Count == 0) return manifest;
|
||||
var incoming = added.Order(CaptureOrder).ToList();
|
||||
var merged = new List<SidecarFrame>(manifest.Frames.Count + incoming.Count);
|
||||
var next = 0;
|
||||
foreach (var frame in manifest.Frames)
|
||||
{
|
||||
while (next < incoming.Count && CaptureOrder.Compare(incoming[next], frame) < 0) merged.Add(incoming[next++]);
|
||||
merged.Add(frame);
|
||||
}
|
||||
while (next < incoming.Count) merged.Add(incoming[next++]);
|
||||
return WithFrames(manifest, merged);
|
||||
}
|
||||
|
||||
/// <summary>Replaces the frame list (indexes renumbered) and bumps the frames version.</summary>
|
||||
public static SequenceManifest WithFrames(SequenceManifest manifest, IReadOnlyList<SidecarFrame> frames)
|
||||
{
|
||||
var renumbered = new SidecarFrame[frames.Count];
|
||||
for (var i = 0; i < frames.Count; i++) renumbered[i] = frames[i].I == i ? frames[i] : frames[i] with { I = i };
|
||||
return manifest with
|
||||
{
|
||||
Frames = renumbered,
|
||||
Versions = manifest.Versions with { Frames = manifest.Versions.Frames + 1 },
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Applies per-frame changes by id (flags, hashes); frames not in <paramref name="changes"/> are kept.</summary>
|
||||
public static SequenceManifest Update(SequenceManifest manifest, IReadOnlyDictionary<Guid, Func<SidecarFrame, SidecarFrame>> changes)
|
||||
{
|
||||
var frames = manifest.Frames.Select(f => changes.TryGetValue(f.Id, out var change) ? change(f) : f).ToList();
|
||||
return manifest with { Frames = frames, UpdatedAt = DateTimeOffset.UtcNow };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user