aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-04-13 15:28:23 -0500
committerGitHub <noreply@github.com>2025-04-13 15:28:23 -0500
commit7b99d3339154972eed0f04beef5a91678e5a0efb (patch)
tree917bccf09a38579025eaafa709819d5a524ff299
parentf63238c38087bcc26fd9b47c3300e4bc4b55d0f9 (diff)
parent951b65d273fd4dcfe1508aabf2b5b4e833ecc0fa (diff)
downloadslskd-7b99d3339154972eed0f04beef5a91678e5a0efb.tar.gz
Merge pull request #1328 from slskd/bugfix
Fix cryptic message if a remote client doesn't return any files when directory contents are requested
-rw-r--r--src/slskd/Users/API/Controllers/UsersController.cs6
-rw-r--r--src/web/src/components/Search/Response.jsx54
2 files changed, 39 insertions, 21 deletions
diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs
index da581ab8..821baa9b 100644
--- a/src/slskd/Users/API/Controllers/UsersController.cs
+++ b/src/slskd/Users/API/Controllers/UsersController.cs
@@ -26,6 +26,8 @@ namespace slskd.Users.API
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+ using Serilog;
+
using Soulseek;
/// <summary>
@@ -57,6 +59,7 @@ namespace slskd.Users.API
private ISoulseekClient Client { get; }
private IUserService Users { get; }
private IOptionsSnapshot<Options> OptionsSnapshot { get; }
+ private ILogger Log { get; set; } = Serilog.Log.ForContext<UsersController>();
/// <summary>
/// Retrieves the address of the specified <paramref name="username"/>.
@@ -169,6 +172,9 @@ namespace slskd.Users.API
try
{
var result = await Client.GetDirectoryContentsAsync(username, request.Directory);
+
+ Log.Debug("{Endpoint} response from {User} for directory '{Directory}': {@Response}", nameof(Directory), username, request.Directory, result);
+
return Ok(result);
}
catch (UserOfflineException ex)
diff --git a/src/web/src/components/Search/Response.jsx b/src/web/src/components/Search/Response.jsx
index f665c816..0d94ee8c 100644
--- a/src/web/src/components/Search/Response.jsx
+++ b/src/web/src/components/Search/Response.jsx
@@ -83,30 +83,42 @@ class Response extends Component {
const oldTree = { ...this.state.tree };
const oldFiles = oldTree[directory];
- // some clients might send more than one directory in the response,
- // if the requested directory contains subdirectories. the root directory
- // is always first, and for now we'll only display the contents of that.
- const allDirectories = await getDirectoryContents({
- directory,
- username,
- });
+ try {
+ // some clients might send more than one directory in the response,
+ // if the requested directory contains subdirectories. the root directory
+ // is always first, and for now we'll only display the contents of that.
+ const allDirectories = await getDirectoryContents({
+ directory,
+ username,
+ });
+ const theRootDirectory = allDirectories?.[0];
- const theRootDirectory = allDirectories?.[0];
- const { files, name } = theRootDirectory;
+ // some clients might send an empty response for some reason
+ if (!theRootDirectory) {
+ throw new Error('No directories were included in the response');
+ }
- // the api returns file names only, so we need to prepend the directory
- // to make it look like a search result. we also need to preserve
- // any file selections, so check the old files and assign accordingly
- const fixedFiles = files.map((file) => ({
- ...file,
- filename: `${directory}\\${file.filename}`,
- selected:
- oldFiles.find((f) => f.filename === `${directory}\\${file.filename}`)
- ?.selected ?? false,
- }));
+ const { files, name } = theRootDirectory;
+
+ // the api returns file names only, so we need to prepend the directory
+ // to make it look like a search result. we also need to preserve
+ // any file selections, so check the old files and assign accordingly
+ const fixedFiles = files.map((file) => ({
+ ...file,
+ filename: `${directory}\\${file.filename}`,
+ selected:
+ oldFiles.find(
+ (f) => f.filename === `${directory}\\${file.filename}`,
+ )?.selected ?? false,
+ }));
- oldTree[name] = fixedFiles;
- this.setState({ tree: { ...oldTree } });
+ oldTree[name] = fixedFiles;
+ this.setState({ tree: { ...oldTree } });
+ } catch (error) {
+ throw new Error(`Failed to process directory response: ${error}`, {
+ cause: error,
+ });
+ }
} catch (error) {
console.error(error);
toast.error(error?.response?.data ?? error?.message ?? error);