< Summary

Information
Class: Anichron.Worker.Ingestion.LivePhotoLinkResult
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/LivePhotoLinker.cs
Tag: 228_36821334185
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 54
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/LivePhotoLinker.cs

#LineLine coverage
 1using Anichron.Core.Domain;
 2using System.IO.Abstractions;
 3
 4namespace Anichron.Worker.Ingestion;
 5
 246internal sealed record LivePhotoLinkResult(
 247    IReadOnlyList<IngestionItem> Items,
 248    IReadOnlySet<string> ClaimedPaths);
 9
 10internal interface ILivePhotoLinker
 11{
 12    LivePhotoLinkResult Link(IEnumerable<string> filesInDirectory, string rootPath);
 13}
 14
 15internal sealed class LivePhotoLinker(IFileSystem fileSystem) : ILivePhotoLinker
 16{
 17    public LivePhotoLinkResult Link(IEnumerable<string> filesInDirectory, string rootPath)
 18    {
 19        var heicFiles = new List<string>();
 20        var movFilesByBaseName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 21
 22        foreach (var path in filesInDirectory)
 23        {
 24            var ext = fileSystem.Path.GetExtension(path);
 25            if (ext.Equals(MediaFileExtensions.Heic, StringComparison.OrdinalIgnoreCase))
 26                heicFiles.Add(path);
 27            else if (ext.Equals(MediaFileExtensions.Mov, StringComparison.OrdinalIgnoreCase))
 28                movFilesByBaseName[fileSystem.Path.GetFileNameWithoutExtension(path)] = path;
 29        }
 30
 31        var items = new List<IngestionItem>(heicFiles.Count);
 32        var claimedPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
 33
 34        foreach (var heicPath in heicFiles)
 35        {
 36            claimedPaths.Add(heicPath);
 37            var baseName = fileSystem.Path.GetFileNameWithoutExtension(heicPath);
 38            var heicRelativePath = fileSystem.Path.GetRelativePath(rootPath, heicPath);
 39
 40            if (movFilesByBaseName.TryGetValue(baseName, out var movPath))
 41            {
 42                var movRelativePath = fileSystem.Path.GetRelativePath(rootPath, movPath);
 43                items.Add(new LivePhotoPairItem(heicPath, heicRelativePath, movPath, movRelativePath));
 44                claimedPaths.Add(movPath);
 45            }
 46            else
 47            {
 48                items.Add(new SingleFileItem(heicPath, heicRelativePath, MediaType.Image));
 49            }
 50        }
 51
 52        return new LivePhotoLinkResult(items, claimedPaths);
 53    }
 54}