aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Application.cs15
-rw-r--r--src/slskd/Users/IUserService.cs7
-rw-r--r--src/slskd/Users/UserService.cs49
3 files changed, 13 insertions, 58 deletions
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 1e71652c..4ed9d092 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -1662,7 +1662,16 @@ namespace slskd
/// <returns>A Task resolving the UserInfo instance.</returns>
private async Task<UserInfo> UserInfoResolver(string username, IPEndPoint endpoint)
{
- var profilePicture = Users.GetProfilePicture(Options.Soulseek.Picture);
+ byte[] pictureBytes = null;
+
+ try
+ {
+ pictureBytes = await System.IO.File.ReadAllBytesAsync(Options.Soulseek.Picture);
+ }
+ catch (Exception ex)
+ {
+ Log.Warning("Failed to read Soulseek picture {Picture}: {Message}", Options.Soulseek.Picture, ex.Message);
+ }
if (Users.IsBlacklisted(username, endpoint.Address))
{
@@ -1671,7 +1680,7 @@ namespace slskd
uploadSlots: 0,
queueLength: int.MaxValue,
hasFreeUploadSlot: false,
- picture: profilePicture);
+ picture: pictureBytes);
}
try
@@ -1697,7 +1706,7 @@ namespace slskd
uploadSlots: group.Slots,
queueLength: forecastedPosition,
hasFreeUploadSlot: forecastedPosition == 0,
- picture: profilePicture);
+ picture: pictureBytes);
return info;
}
diff --git a/src/slskd/Users/IUserService.cs b/src/slskd/Users/IUserService.cs
index e84d7461..75afd442 100644
--- a/src/slskd/Users/IUserService.cs
+++ b/src/slskd/Users/IUserService.cs
@@ -152,12 +152,5 @@ namespace slskd.Users
/// <param name="username">The username of the peer.</param>
/// <returns>The operation context.</returns>
Task WatchAsync(string username);
-
- /// <summary>
- /// Gets the profile picture as a byte array if it exists.
- /// </summary>
- /// <param name="profilePicture">The profile picture path to resolve.</param>
- /// <returns>The profile picture as a byte array if it exists and can be read, null otherwise.</returns>
- byte[] GetProfilePicture(string profilePicture);
}
} \ No newline at end of file
diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs
index d634704a..55b02134 100644
--- a/src/slskd/Users/UserService.cs
+++ b/src/slskd/Users/UserService.cs
@@ -68,22 +68,16 @@ namespace slskd.Users
/// </remarks>
public class UserService : IUserService
{
- private readonly FileService fileService;
-
/// <summary>
/// Initializes a new instance of the <see cref="UserService"/> class.
/// </summary>
/// <param name="soulseekClient"></param>
/// <param name="optionsMonitor"></param>
- /// <param name="fileService"></param>
public UserService(
ISoulseekClient soulseekClient,
- IOptionsMonitor<Options> optionsMonitor,
- FileService fileService)
+ IOptionsMonitor<Options> optionsMonitor)
{
Client = soulseekClient;
- this.fileService = fileService;
-
OptionsMonitor = optionsMonitor;
OptionsMonitor.OnChange(options => Configure(options));
@@ -155,47 +149,6 @@ namespace slskd.Users
private ConcurrentDictionary<string, bool> WatchedUsernamesDictionary { get; set; } = new ConcurrentDictionary<string, bool>();
/// <summary>
- /// Gets the profile picture as a byte array if it exists.
- /// </summary>
- /// <param name="profilePicture">The profile picture path to resolve.</param>
- /// <returns>The profile picture as a byte array if it exists and can be read, null otherwise.</returns>
- public byte[] GetProfilePicture(string profilePicture)
- {
- if (string.IsNullOrWhiteSpace(profilePicture))
- {
- Log.Warning("Profile picture path is not set");
- return null;
- }
-
- try
- {
- // Ensure the path is relative to the app directory for security
- var fullPath = Path.GetFullPath(
- Path.Combine(AppContext.BaseDirectory, profilePicture));
-
- var fileInfo = fileService.ResolveFileInfo(fullPath);
- if (!fileInfo.Exists)
- {
- Log.Warning("Profile picture '{Path}' not found", profilePicture);
- return null;
- }
-
- // Read the file into a byte array
- return System.IO.File.ReadAllBytes(fileInfo.FullName);
- }
- catch (UnauthorizedException ex)
- {
- Log.Warning(ex, "Access to profile picture '{Path}' was denied", profilePicture);
- return null;
- }
- catch (IOException ex)
- {
- Log.Warning(ex, "Failed to read profile picture '{Path}'", profilePicture);
- return null;
- }
- }
-
- /// <summary>
/// Gets the name of the group for the specified <paramref name="username"/>.
/// </summary>
/// <remarks>The group name is fetched from cached data, and lookups should always be fast.</remarks>