diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-04-07 12:33:22 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-04-07 12:33:22 -0500 |
| commit | 21da11dfae33529d2672da06a8fa52b5343b5239 (patch) | |
| tree | 3de39aea286ccb9cc350307817b30e3981f3bbf6 /src/slskd/Users | |
| parent | 831e9ce49abbcc64a7b75c6fb2c90ad20b233e00 (diff) | |
| download | slskd-21da11dfae33529d2672da06a8fa52b5343b5239.tar.gz | |
simplify fetch of picture bytes
Diffstat (limited to 'src/slskd/Users')
| -rw-r--r-- | src/slskd/Users/IUserService.cs | 7 | ||||
| -rw-r--r-- | src/slskd/Users/UserService.cs | 49 |
2 files changed, 1 insertions, 55 deletions
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> |
