diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-03-18 15:49:10 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-03-18 15:49:10 -0500 |
| commit | ca97a7f48b1a1782a4fb38d9ee86c41a04fd58cc (patch) | |
| tree | 3ac0e6c89b4f6225af62ae93bec3a7a1b8635328 /src | |
| parent | cac0d9ea1826e226e04eab5bed22f8571c8bec7a (diff) | |
| download | slskd-ca97a7f48b1a1782a4fb38d9ee86c41a04fd58cc.tar.gz | |
gather metadata when processing shares
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Shares/SharedFileCache.cs | 48 |
1 files changed, 1 insertions, 47 deletions
diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index ad2468da..f13eaad4 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -249,7 +249,7 @@ namespace slskd.Shares try { var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly) - .Select(f => new File(1, f.ReplaceFirst(share.LocalPath, share.RemotePath), new FileInfo(f).Length, Path.GetExtension(f))) + .Select(f => f.ToSoulseekFile(share)) .ToDictionary(f => f.Filename, f => f); // merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully @@ -462,51 +462,5 @@ namespace slskd.Shares MaskedFiles = new Dictionary<string, File>(); State.SetValue(state => state with { Directories = 0, Files = 0 }); } - - private sealed class Share - { - public Share(string share) - { - Raw = share; - IsExcluded = share.StartsWith('-') || share.StartsWith('!'); - - if (IsExcluded) - { - share = share[1..]; - } - - // test to see whether an alias has been specified - var matches = Regex.Matches(share, @"^\[(.*)\](.*)$"); - - if (matches.Any()) - { - // split the alias from the path, and validate the alias - var groups = matches[0].Groups; - Alias = groups[1].Value; - LocalPath = groups[2].Value; - } - else - { - Alias = share.Split(new[] { '/', '\\' }).Last(); - LocalPath = share; - } - - var parent = System.IO.Directory.GetParent(LocalPath).FullName.TrimEnd('/', '\\'); - - Mask = Compute.MaskHash(parent); - - var maskedPath = LocalPath.ReplaceFirst(parent, Mask); - - var aliasedSegment = LocalPath[(parent.Length + 1)..]; - RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias); - } - - public string Alias { get; init; } - public bool IsExcluded { get; init; } - public string LocalPath { get; init; } - public string Mask { get; init; } - public string Raw { get; init; } - public string RemotePath { get; init; } - } } }
\ No newline at end of file |
