aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-05-03 17:53:30 -0500
committerGitHub <noreply@github.com>2025-05-03 17:53:30 -0500
commita87b58ae5d09a127f7d5eb5d1908a3f083dfe1f7 (patch)
tree6739f38224a4e5f649092fdd3cc6f3772b7d0270 /src/slskd
parent207a645006f75a0fb96f2a1b6a72017f94d42c80 (diff)
parent7b99d3339154972eed0f04beef5a91678e5a0efb (diff)
downloadslskd-a87b58ae5d09a127f7d5eb5d1908a3f083dfe1f7.tar.gz
Merge branch 'master' into migrations
Diffstat (limited to 'src/slskd')
-rw-r--r--src/slskd/Application.cs31
-rw-r--r--src/slskd/Core/Options.cs9
-rw-r--r--src/slskd/Users/API/Controllers/UsersController.cs8
-rw-r--r--src/slskd/slskd.csproj2
4 files changed, 46 insertions, 4 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index e5681442..2449e8e0 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -830,6 +830,12 @@ namespace slskd
var logger = Loggers.GetOrAdd(source, Log.ForContext("Context", "Soulseek").ForContext("SubContext", source));
+ if (args.IncludesException && OptionsAtStartup.Debug)
+ {
+ logger.Write(TranslateLogLevel(args.Level), exception: args.Exception, "{@Message}", args.Message);
+ return;
+ }
+
logger.Write(TranslateLogLevel(args.Level), "{@Message}", args.Message);
}
@@ -1662,13 +1668,32 @@ namespace slskd
/// <returns>A Task resolving the UserInfo instance.</returns>
private async Task<UserInfo> UserInfoResolver(string username, IPEndPoint endpoint)
{
+ byte[] pictureBytes = null;
+
+ if (!string.IsNullOrWhiteSpace(Options.Soulseek.Picture))
+ {
+ try
+ {
+ // note: the Picture setting is validated at startup to ensure it exists and that
+ // it is readable
+ pictureBytes = await System.IO.File.ReadAllBytesAsync(Options.Soulseek.Picture);
+ }
+ catch (Exception ex)
+ {
+ // this isn't a serious enough problem to prevent us from continuing, so we'll just
+ // log a warning and continue, omitting the picture
+ Log.Warning("Failed to read Soulseek picture {Picture}: {Message}", Options.Soulseek.Picture, ex.Message);
+ }
+ }
+
if (Users.IsBlacklisted(username, endpoint.Address))
{
return new UserInfo(
description: Options.Soulseek.Description,
uploadSlots: 0,
queueLength: int.MaxValue,
- hasFreeUploadSlot: false);
+ hasFreeUploadSlot: false,
+ picture: pictureBytes);
}
try
@@ -1688,11 +1713,13 @@ namespace slskd
// i want to know how many slots they have, which gives me an idea of how fast their
// queue moves, and the length of the queue *ahead of me*, meaning how long i'd have to
// wait until my first download starts.
+ // revisited 3 years later: why was it important to leave this comment??
var info = new UserInfo(
description: Options.Soulseek.Description,
uploadSlots: group.Slots,
queueLength: forecastedPosition,
- hasFreeUploadSlot: forecastedPosition == 0);
+ hasFreeUploadSlot: forecastedPosition == 0,
+ picture: pictureBytes);
return info;
}
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 870a1e83..1fed70f5 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1540,6 +1540,15 @@ namespace slskd
public string Description { get; init; } = "A slskd user. https://github.com/slskd/slskd";
/// <summary>
+ /// Gets the file path for the user's profile picture.
+ /// </summary>
+ [Argument(default, "slsk-picture")]
+ [EnvironmentVariable("SLSK_PICTURE")]
+ [Description("user picture for the Soulseek network")]
+ [FileExists(FileAccess.Read)]
+ public string Picture { get; init; } = null;
+
+ /// <summary>
/// Gets the local IP address on which to listen for incoming connections.
/// </summary>
[Argument(default, "slsk-listen-ip-address")]
diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs
index 01df31d1..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"/>.
@@ -152,7 +155,7 @@ namespace slskd.Users.API
/// <returns></returns>
[HttpPost("{username}/directory")]
[Authorize(Policy = AuthPolicy.Any)]
- [ProducesResponseType(typeof(Directory), 200)]
+ [ProducesResponseType(typeof(IEnumerable<Directory>), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Directory([FromRoute, Required] string username, [FromBody, Required] DirectoryContentsRequest request)
{
@@ -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/slskd/slskd.csproj b/src/slskd/slskd.csproj
index 2c836ce4..cfb39234 100644
--- a/src/slskd/slskd.csproj
+++ b/src/slskd/slskd.csproj
@@ -68,7 +68,7 @@
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="7.1.1" />
<PackageReference Include="Serilog.Sinks.Http" Version="8.0.0" />
- <PackageReference Include="Soulseek" Version="7.0.1" />
+ <PackageReference Include="Soulseek" Version="7.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>