aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-06-30 09:43:11 -0500
committerJP Dillingham <jp@dillingham.me>2023-06-30 09:43:11 -0500
commit26786311ffc3a01bdd15158fe0c03bb58d8391ec (patch)
treec5fa098f5282c4379bf7a43038a30b7ca26bf94d /src
parent5bc462d774633c40dd9ae5efd35cfca2cf71f0ef (diff)
downloadslskd-26786311ffc3a01bdd15158fe0c03bb58d8391ec.tar.gz
include subdirectories in directory body, return only one
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Files/API/FilesController.cs8
-rw-r--r--src/slskd/Files/FileService.cs20
-rw-r--r--src/slskd/Files/IFileService.cs2
-rw-r--r--src/slskd/Files/Types/FilesystemDirectory.cs1
4 files changed, 19 insertions, 12 deletions
diff --git a/src/slskd/Files/API/FilesController.cs b/src/slskd/Files/API/FilesController.cs
index 08895639..f4b3ce87 100644
--- a/src/slskd/Files/API/FilesController.cs
+++ b/src/slskd/Files/API/FilesController.cs
@@ -50,7 +50,7 @@ namespace slskd.Files.API
[HttpGet("downloads/directories")]
[Authorize(Policy = AuthPolicy.Any)]
- [ProducesResponseType(typeof(IEnumerable<FilesystemDirectory>), 200)]
+ [ProducesResponseType(typeof(FilesystemDirectory), 200)]
public async Task<IActionResult> GetDownloadContentsAsync([FromQuery] bool recursive = false)
{
try
@@ -77,7 +77,7 @@ namespace slskd.Files.API
[HttpGet("downloads/directories/{base64SubdirectoryName}")]
[Authorize(Policy = AuthPolicy.Any)]
- [ProducesResponseType(typeof(IEnumerable<FilesystemDirectory>), 200)]
+ [ProducesResponseType(typeof(FilesystemDirectory), 200)]
public async Task<IActionResult> GetDownloadSubdirectoryContentsAsync([FromRoute] string base64SubdirectoryName, [FromQuery] bool recursive = false)
{
var decodedDir = base64SubdirectoryName.FromBase64();
@@ -167,7 +167,7 @@ namespace slskd.Files.API
[HttpGet("incomplete/directories")]
[Authorize(Policy = AuthPolicy.Any)]
- [ProducesResponseType(typeof(IEnumerable<FilesystemDirectory>), 200)]
+ [ProducesResponseType(typeof(FilesystemDirectory), 200)]
public async Task<IActionResult> GetIncompleteContentsAsync([FromQuery] bool recursive = false)
{
try
@@ -194,7 +194,7 @@ namespace slskd.Files.API
[HttpGet("incomplete/directories/{base64SubdirectoryName}")]
[Authorize(Policy = AuthPolicy.Any)]
- [ProducesResponseType(typeof(IEnumerable<FilesystemDirectory>), 200)]
+ [ProducesResponseType(typeof(FilesystemDirectory), 200)]
public async Task<IActionResult> GetIncompleteSubdirectoryContentsAsync([FromRoute, Required] string base64SubdirectoryName, [FromQuery] bool recursive = false)
{
var decodedDir = base64SubdirectoryName.FromBase64();
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index f37c861b..1dfcb715 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -146,7 +146,7 @@ namespace slskd.Files
/// <returns>The list of found contents.</returns>
/// <exception cref="NotFoundException">Thrown if the specified directory does not exist.</exception>
/// <exception cref="ForbiddenException">Thrown if the specified directory is restricted.</exception>
- public async Task<IEnumerable<FilesystemDirectory>> ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null)
+ public async Task<FilesystemDirectory> ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null)
{
if (!AllowedDirectories.Any(d => rootDirectory == d))
{
@@ -168,20 +168,26 @@ namespace slskd.Files
var files = contents
.OfType<FileInfo>()
- .Select(f => FilesystemFile.FromFileInfo(f));
+ .Select(f => FilesystemFile.FromFileInfo(f) with
+ {
+ FullName = f.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'),
+ });
var dirs = contents
.OfType<DirectoryInfo>()
- .Prepend(dir)
.Select(d => FilesystemDirectory.FromDirectoryInfo(d) with
{
FullName = d.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'),
- Files = files
- .Where(f => Path.GetDirectoryName(f.FullName) == d.FullName)
- .Select(f => f with { FullName = f.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/') }),
});
- return dirs;
+ var response = FilesystemDirectory.FromDirectoryInfo(dir) with
+ {
+ FullName = dir.FullName.ReplaceFirst(rootDirectory, string.Empty).TrimStart('\\', '/'),
+ Files = files,
+ Directories = dirs,
+ };
+
+ return response;
});
}
}
diff --git a/src/slskd/Files/IFileService.cs b/src/slskd/Files/IFileService.cs
index 8e3ddcb7..2d4d66f5 100644
--- a/src/slskd/Files/IFileService.cs
+++ b/src/slskd/Files/IFileService.cs
@@ -65,6 +65,6 @@ namespace slskd.Files
/// <returns>The list of found contents.</returns>
/// <exception cref="NotFoundException">Thrown if the specified directory does not exist.</exception>
/// <exception cref="ForbiddenException">Thrown if the specified root directory is restricted.</exception>
- Task<IEnumerable<FilesystemDirectory>> ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null);
+ Task<FilesystemDirectory> ListContentsAsync(string rootDirectory, string parentDirectory = null, EnumerationOptions enumerationOptions = null);
}
} \ No newline at end of file
diff --git a/src/slskd/Files/Types/FilesystemDirectory.cs b/src/slskd/Files/Types/FilesystemDirectory.cs
index 4183c724..9e573906 100644
--- a/src/slskd/Files/Types/FilesystemDirectory.cs
+++ b/src/slskd/Files/Types/FilesystemDirectory.cs
@@ -29,6 +29,7 @@ namespace slskd.Files
public DateTime CreatedAt { get; init; }
public DateTime ModifiedAt { get; init; }
public IEnumerable<FilesystemFile> Files { get; init; }
+ public IEnumerable<FilesystemDirectory> Directories { get; init; }
public static FilesystemDirectory FromDirectoryInfo(DirectoryInfo i)
{