diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-04-07 15:13:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-07 15:13:44 -0500 |
| commit | f0ab25a376280c5b92c9b58686be8fbd074e8ad9 (patch) | |
| tree | 19d003e8cb382399d6b2d8ed62e3042b7e980dd4 /src | |
| parent | eec6e0f098effcb9bfda297a441ca7ffd8d33934 (diff) | |
| parent | 166373e80e740f8de5867a823551461d75c57bec (diff) | |
| download | slskd-f0ab25a376280c5b92c9b58686be8fbd074e8ad9.tar.gz | |
Merge pull request #1321 from slskd/profile-pic
Add the ability to set a profile picture
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Application.cs | 25 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 9 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index e5681442..9179987e 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -1662,13 +1662,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 +1707,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 266d04aa..cc662444 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1532,6 +1532,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")] |
