diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-08-24 07:46:12 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-24 07:46:12 -0500 |
| commit | dbf92255737057a7603366684456f90166a88045 (patch) | |
| tree | 9b66ee432780a0ec603ac591738dfbd42d21987e /src | |
| parent | cd564c0df2fd55803a193efe3fa67f850426406f (diff) | |
| parent | 9a000eb5719711d116b3984836446187e15e4ef2 (diff) | |
| download | slskd-dbf92255737057a7603366684456f90166a88045.tar.gz | |
Merge pull request #167 from slskd/folder-contents
Use shared file cache when resolving directory contents
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application/Application.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Application/ISharedFileCache.cs | 7 | ||||
| -rw-r--r-- | src/slskd/Application/SharedFileCache.cs | 21 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs index 9b89be3b..c317f467 100644 --- a/src/slskd/Application/Application.cs +++ b/src/slskd/Application/Application.cs @@ -570,10 +570,8 @@ namespace slskd /// <returns>A Task resolving an instance of Soulseek.Directory containing the contents of the requested directory.</returns> private Task<Soulseek.Directory> DirectoryContentsResponseResolver(string username, IPEndPoint endpoint, int token, string directory) { - var result = new Soulseek.Directory(directory.Replace("/", @"\"), System.IO.Directory.GetFiles(directory) - .Select(f => new Soulseek.File(1, Path.GetFileName(f), new FileInfo(f).Length, Path.GetExtension(f)))); - - return Task.FromResult(result); + var dir = SharedFileCache.List(directory); + return Task.FromResult(dir); } /// <summary> diff --git a/src/slskd/Application/ISharedFileCache.cs b/src/slskd/Application/ISharedFileCache.cs index 4bc3f593..93b836f3 100644 --- a/src/slskd/Application/ISharedFileCache.cs +++ b/src/slskd/Application/ISharedFileCache.cs @@ -44,6 +44,13 @@ namespace slskd Task FillAsync(); /// <summary> + /// Returns the contents of the specified <paramref name="directory"/>. + /// </summary> + /// <param name="directory">The directory for which the contents are to be listed.</param> + /// <returns>The contents of the directory.</returns> + Directory List(string directory); + + /// <summary> /// Substitutes the mask in the specified <paramref name="filename"/> with the original path, if the mask is tracked /// by the cache. /// </summary> diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index 049d80fe..c2200daf 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -239,6 +239,27 @@ namespace slskd } /// <summary> + /// Returns the contents of the specified <paramref name="directory"/>. + /// </summary> + /// <param name="directory">The directory for which the contents are to be listed.</param> + /// <returns>The contents of the directory.</returns> + public Directory List(string directory) + { + var files = MaskedFiles.Where(f => f.Key.StartsWith(directory)).Select(kvp => + { + var f = kvp.Value; + return new File( + f.Code, + Path.GetFileName(f.Filename), + f.Size, + f.Extension, + f.Attributes); + }); + + return new Directory(directory, files); + } + + /// <summary> /// Substitutes the mask in the specified <paramref name="filename"/> with the original path, if the mask is tracked /// by the cache. /// </summary> |
