aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-03-26 12:44:43 -0500
committerGitHub <noreply@github.com>2022-03-26 12:44:43 -0500
commit751845f25d660c57e5dd9c6e179d12c10df7ab33 (patch)
treebebc32f1e78c7fe2e439fb5246adde10daaff86d
parent49cc058ea14435718abf2e95e36b8ef6c12b27bf (diff)
parenta5b7e657d6fe38c416dc01461424f79aa452f197 (diff)
downloadslskd-751845f25d660c57e5dd9c6e179d12c10df7ab33.tar.gz
Merge branch 'master' into userinfo
-rw-r--r--etc/icon.svg59
-rw-r--r--src/slskd/Shares/Domain/Share.cs75
-rw-r--r--src/slskd/Shares/SharedFileCache.cs56
-rw-r--r--src/slskd/Shares/SoulseekFileFactory.cs120
-rw-r--r--src/slskd/Startup.cs6
-rw-r--r--src/slskd/Users/API/Controllers/UsersController.cs17
-rw-r--r--src/slskd/Users/Domain/Info.cs24
-rw-r--r--src/slskd/Users/Extensions.cs15
-rw-r--r--src/slskd/Users/IUserService.cs5
-rw-r--r--src/slskd/Users/UserDbContext.cs32
-rw-r--r--src/slskd/Users/UserService.cs39
-rw-r--r--src/slskd/slskd.csproj1
-rw-r--r--src/web/package-lock.json12
-rw-r--r--src/web/public/favicon.icobin1150 -> 15086 bytes
-rw-r--r--src/web/src/components/App.css4
-rw-r--r--src/web/src/components/Shared/FileList.js6
-rw-r--r--src/web/src/lib/util.js14
-rw-r--r--tests/slskd.Tests.Unit/Users/UserServiceTests.cs2
18 files changed, 273 insertions, 214 deletions
diff --git a/etc/icon.svg b/etc/icon.svg
index 870458c2..36e2d202 100644
--- a/etc/icon.svg
+++ b/etc/icon.svg
@@ -1,46 +1,19 @@
-<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 26.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 490 490" style="enable-background:new 0 0 490 490;" xml:space="preserve">
-<path d="M463.957,58.244c-24.452-14.914-57.488-22.795-95.543-22.795c-58.296,0-122.525,18.382-180.205,50.358l-0.404-0.152
- c0,0-0.058,0.306-0.089,0.452c-17.46,9.707-34.378,20.547-50.269,32.648C43.843,190.022,17.629,274.582,39.745,319.782
- C15.536,361.144,0.622,403.904,0,454.552c46.543-88.696,74.478-160.58,226.143-281.592
- c-43.334,9.287-118.233,53.333-168.607,120.173c-4.753-39.1,26.141-102.236,94.954-154.624c8.713-6.635,17.774-12.836,27.022-18.72
- c-7.226,22.454-4.923,16.869-19.916,48.353c22.171-20.984,36.769-33.933,58.658-69.896c28.42-13.96,57.981-24.394,87.291-30.7
- c-4.85,16.078-14.081,43.326-26.578,64.868c0,0,31.718-6.799,57.932-5.263c-14.323,15.803-27.209,32.898-40.278,50.375
- c-17.897,23.926-36.398,48.668-60.09,71.697c-2.852,2.773-5.577,5.287-8.342,7.881c-36.406-3.485-60.453,10.128-82.982,34.175
- c17.768-8.284,41.637-15.106,56.599-11c-27.573,22.487-70.995,52.128-106.674,49.688c-6.766,10.297-7.194,10.613-14.631,23.052
- c57.875,14.406,130.567-44.4,173.343-85.996c25.083-24.394,44.19-49.929,62.661-74.615c38.038-50.851,70.889-94.758,143.759-111.467
- L490,74.127L463.957,58.244z"/>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
-<g>
-</g>
+<style type="text/css">
+ .st0{fill:url(#SVGID_1_);}
+</style>
+<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="0" y1="245.0005" x2="490" y2="245.0005">
+ <stop offset="0" style="stop-color:#00C6FF"/>
+ <stop offset="1" style="stop-color:#0072FF"/>
+</linearGradient>
+<path class="st0" d="M464,58.2c-24.5-14.9-57.5-22.8-95.5-22.8c-58.3,0-122.5,18.4-180.2,50.4l-0.4-0.2c0,0-0.1,0.3-0.1,0.5
+ c-17.5,9.7-34.4,20.5-50.3,32.6C43.8,190,17.6,274.6,39.7,319.8C15.5,361.1,0.6,403.9,0,454.6C46.5,365.9,74.5,294,226.1,173
+ c-43.3,9.3-118.2,53.3-168.6,120.2c-4.8-39.1,26.1-102.2,95-154.6c8.7-6.6,17.8-12.8,27-18.7c-7.2,22.5-4.9,16.9-19.9,48.4
+ c22.2-21,36.8-33.9,58.7-69.9c28.4-14,58-24.4,87.3-30.7c-4.9,16.1-14.1,43.3-26.6,64.9c0,0,31.7-6.8,57.9-5.3
+ c-14.3,15.8-27.2,32.9-40.3,50.4c-17.9,23.9-36.4,48.7-60.1,71.7c-2.9,2.8-5.6,5.3-8.3,7.9c-36.4-3.5-60.5,10.1-83,34.2
+ c17.8-8.3,41.6-15.1,56.6-11c-27.6,22.5-71,52.1-106.7,49.7c-6.8,10.3-7.2,10.6-14.6,23.1c57.9,14.4,130.6-44.4,173.3-86
+ c25.1-24.4,44.2-49.9,62.7-74.6c38-50.9,70.9-94.8,143.8-111.5l29.7-6.8L464,58.2z"/>
</svg>
diff --git a/src/slskd/Shares/Domain/Share.cs b/src/slskd/Shares/Domain/Share.cs
new file mode 100644
index 00000000..890c8565
--- /dev/null
+++ b/src/slskd/Shares/Domain/Share.cs
@@ -0,0 +1,75 @@
+// <copyright file="Share.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+namespace slskd.Shares
+{
+ using System.Linq;
+ using System.Text.RegularExpressions;
+
+ /// <summary>
+ /// A file share.
+ /// </summary>
+ public sealed class Share
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Share"/> class.
+ /// </summary>
+ /// <param name="share"></param>
+ public Share(string share)
+ {
+ Raw = share;
+ IsExcluded = share.StartsWith('-') || share.StartsWith('!');
+
+ if (IsExcluded)
+ {
+ share = share[1..];
+ }
+
+ // test to see whether an alias has been specified
+ var matches = Regex.Matches(share, @"^\[(.*)\](.*)$");
+
+ if (matches.Any())
+ {
+ // split the alias from the path, and validate the alias
+ var groups = matches[0].Groups;
+ Alias = groups[1].Value;
+ LocalPath = groups[2].Value;
+ }
+ else
+ {
+ Alias = share.Split(new[] { '/', '\\' }).Last();
+ LocalPath = share;
+ }
+
+ var parent = System.IO.Directory.GetParent(LocalPath).FullName.TrimEnd('/', '\\');
+
+ Mask = Compute.MaskHash(parent);
+
+ var maskedPath = LocalPath.ReplaceFirst(parent, Mask);
+
+ var aliasedSegment = LocalPath[(parent.Length + 1)..];
+ RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias);
+ }
+
+ public string Alias { get; init; }
+ public bool IsExcluded { get; init; }
+ public string LocalPath { get; init; }
+ public string Mask { get; init; }
+ public string Raw { get; init; }
+ public string RemotePath { get; init; }
+ }
+}
diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs
index ad2468da..02068e2a 100644
--- a/src/slskd/Shares/SharedFileCache.cs
+++ b/src/slskd/Shares/SharedFileCache.cs
@@ -86,10 +86,13 @@ namespace slskd.Shares
/// Initializes a new instance of the <see cref="SharedFileCache"/> class.
/// </summary>
/// <param name="optionsMonitor"></param>
+ /// <param name="soulseekFileFactory"></param>
public SharedFileCache(
- IOptionsMonitor<Options> optionsMonitor)
+ IOptionsMonitor<Options> optionsMonitor,
+ ISoulseekFileFactory soulseekFileFactory = null)
{
OptionsMonitor = optionsMonitor;
+ SoulseekFileFactory = soulseekFileFactory ?? new SoulseekFileFactory();
}
/// <summary>
@@ -105,6 +108,7 @@ namespace slskd.Shares
private List<Share> Shares { get; set; }
private SqliteConnection SQLite { get; set; }
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1);
+ private ISoulseekFileFactory SoulseekFileFactory { get; }
/// <summary>
/// Returns the contents of the cache.
@@ -249,8 +253,8 @@ namespace slskd.Shares
try
{
var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly)
- .Select(f => new File(1, f.ReplaceFirst(share.LocalPath, share.RemotePath), new FileInfo(f).Length, Path.GetExtension(f)))
- .ToDictionary(f => f.Filename, f => f);
+ .Select(filename => SoulseekFileFactory.Create(filename, maskedFilename: filename.ReplaceFirst(share.LocalPath, share.RemotePath)))
+ .ToDictionary(file => file.Filename, file => file);
// merge the new dictionary with the rest this will overwrite any duplicate keys, but keys are the fully
// qualified name the only time this *should* cause problems is if one of the shares is a subdirectory of another.
@@ -462,51 +466,5 @@ namespace slskd.Shares
MaskedFiles = new Dictionary<string, File>();
State.SetValue(state => state with { Directories = 0, Files = 0 });
}
-
- private sealed class Share
- {
- public Share(string share)
- {
- Raw = share;
- IsExcluded = share.StartsWith('-') || share.StartsWith('!');
-
- if (IsExcluded)
- {
- share = share[1..];
- }
-
- // test to see whether an alias has been specified
- var matches = Regex.Matches(share, @"^\[(.*)\](.*)$");
-
- if (matches.Any())
- {
- // split the alias from the path, and validate the alias
- var groups = matches[0].Groups;
- Alias = groups[1].Value;
- LocalPath = groups[2].Value;
- }
- else
- {
- Alias = share.Split(new[] { '/', '\\' }).Last();
- LocalPath = share;
- }
-
- var parent = System.IO.Directory.GetParent(LocalPath).FullName.TrimEnd('/', '\\');
-
- Mask = Compute.MaskHash(parent);
-
- var maskedPath = LocalPath.ReplaceFirst(parent, Mask);
-
- var aliasedSegment = LocalPath[(parent.Length + 1)..];
- RemotePath = maskedPath.ReplaceFirst(aliasedSegment, Alias);
- }
-
- public string Alias { get; init; }
- public bool IsExcluded { get; init; }
- public string LocalPath { get; init; }
- public string Mask { get; init; }
- public string Raw { get; init; }
- public string RemotePath { get; init; }
- }
}
} \ No newline at end of file
diff --git a/src/slskd/Shares/SoulseekFileFactory.cs b/src/slskd/Shares/SoulseekFileFactory.cs
new file mode 100644
index 00000000..ccc3e6b0
--- /dev/null
+++ b/src/slskd/Shares/SoulseekFileFactory.cs
@@ -0,0 +1,120 @@
+// <copyright file="SoulseekFileFactory.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+using System.IO;
+
+namespace slskd.Shares
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Serilog;
+ using Soulseek;
+
+ /// <summary>
+ /// Creates instances of <see cref="Soulseek.File"/>.
+ /// </summary>
+ public interface ISoulseekFileFactory
+ {
+ /// <summary>
+ /// Creates an instance of <see cref="Soulseek.File"/> from the given path.
+ /// </summary>
+ /// <param name="filename">The fully qualified path to the file.</param>
+ /// <param name="maskedFilename">The masked filename.</param>
+ /// <returns>The created instance.</returns>
+ File Create(string filename, string maskedFilename);
+ }
+
+ /// <summary>
+ /// Creates instances of <see cref="Soulseek.File"/>.
+ /// </summary>
+ public class SoulseekFileFactory : ISoulseekFileFactory
+ {
+ private static readonly string[] AudioExtensions = { "aa", "aax", "aac", "aiff", "ape", "dsf", "flac", "m4a", "m4b", "m4p", "mp3", "mpc", "mpp", "ogg", "oga", "wav", "wma", "wv", "webm" };
+ private static readonly string[] VideoExtensions = { "mkv", "ogv", "avi", "wmv", "asf", "mp4", "m4p", "m4v", "mpg", "mpe", "mpv", "mpg", "m2v" };
+ private static readonly HashSet<string> SupportedExtensions = AudioExtensions.Concat(VideoExtensions).ToHashSet();
+
+ private ILogger Log { get; } = Serilog.Log.ForContext<SharedFileCache>();
+
+ /// <summary>
+ /// Creates an instance of <see cref="Soulseek.File"/> from the given path.
+ /// </summary>
+ /// <param name="filename">The fully qualified path to the file.</param>
+ /// <param name="maskedFilename">The masked filename.</param>
+ /// <returns>The created instance.</returns>
+ public File Create(string filename, string maskedFilename)
+ {
+ var code = 1;
+ var size = new FileInfo(filename).Length;
+ var extension = Path.GetExtension(filename)[1..].ToLowerInvariant();
+ List<FileAttribute> attributeList = default;
+
+ if (SupportedExtensions.Contains(extension))
+ {
+ attributeList = new List<FileAttribute>();
+ TagLib.File file = default;
+
+ try
+ {
+ file = TagLib.File.Create(filename, TagLib.ReadStyle.Average | TagLib.ReadStyle.PictureLazy);
+
+ // try to mimick the behavior of existing clients by providing attributes selectively and in a specific order,
+ // depending on whether files use a lossless or lossy codec. lossless files should have BitsPerSample, while lossy
+ // will not. this may not be the best way to determine this.
+ bool isLossless = file.Properties.BitsPerSample > 0;
+
+ if (!isLossless)
+ {
+ // per Nicotine+ docs, Soulseek NS, Nicotine+, Museek+, SoulSeeX all send bit rate, length, then VBR
+ attributeList.Add(new FileAttribute(FileAttributeType.BitRate, file.Properties.AudioBitrate));
+ attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds));
+ attributeList.Add(new FileAttribute(FileAttributeType.VariableBitRate, IsVBR(file) ? 1 : 0));
+ }
+ else
+ {
+ // SoulseekQt 2015-6-12 and later provides the length, sample rate and bit depth for lossless files
+ // bitrate can be deduced from this information
+ attributeList.Add(new FileAttribute(FileAttributeType.Length, (int)file.Properties.Duration.TotalSeconds));
+ attributeList.Add(new FileAttribute(FileAttributeType.SampleRate, file.Properties.AudioSampleRate));
+ attributeList.Add(new FileAttribute(FileAttributeType.BitDepth, file.Properties.BitsPerSample));
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Warning("Failed to read metadata from file '{Filename}'; the file is an unsupported format or may be corrupt ({ExceptionType})", filename, ex.GetType().Name);
+ }
+ finally
+ {
+ file?.Dispose();
+ }
+ }
+
+ return new File(code, maskedFilename, size, extension, attributeList);
+ }
+
+ private bool IsVBR(TagLib.File file)
+ {
+ static bool HasVBRIHeader(TagLib.Mpeg.AudioHeader header) => header.VBRIHeader.Present && header.VBRIHeader.TotalSize > 0;
+ static bool HasXingHeader(TagLib.Mpeg.AudioHeader header) => header.XingHeader.Present && header.XingHeader.TotalSize > 0;
+
+ return file.Properties.Codecs.Any(c =>
+ (c is TagLib.Mpeg.AudioHeader h && (HasVBRIHeader(h) || HasXingHeader(h)))
+ || c is TagLib.Aac.AudioHeader
+ || c is TagLib.Ogg.Codec);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index b1af2482..29f9717f 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -224,11 +224,6 @@ namespace slskd
options.UseSqlite($"Data Source={Path.Combine(Program.AppDirectory, "data", "search.db")}");
});
- services.AddDbContextFactory<UserDbContext>(options =>
- {
- options.UseSqlite($"Data Source={Path.Combine(Program.AppDirectory, "data", "users.db")}");
- });
-
services.AddHttpClient();
// add a partially configured instance of SoulseekClient. the Application instance will
@@ -403,7 +398,6 @@ namespace slskd
try
{
using var search = GetFactory<SearchDbContext>().CreateDbContext();
- using var peer = GetFactory<UserDbContext>().CreateDbContext();
}
catch (Exception ex)
{
diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs
index e7eb5256..2439785e 100644
--- a/src/slskd/Users/API/Controllers/UsersController.cs
+++ b/src/slskd/Users/API/Controllers/UsersController.cs
@@ -40,17 +40,17 @@ namespace slskd.Users.API
/// </summary>
/// <param name="soulseekClient"></param>
/// <param name="browseTracker"></param>
- /// <param name="peerService"></param>
- public UsersController(ISoulseekClient soulseekClient, IBrowseTracker browseTracker, IUserService peerService)
+ /// <param name="userService"></param>
+ public UsersController(ISoulseekClient soulseekClient, IBrowseTracker browseTracker, IUserService userService)
{
Client = soulseekClient;
BrowseTracker = browseTracker;
- Peers = peerService;
+ Users = userService;
}
private IBrowseTracker BrowseTracker { get; }
private ISoulseekClient Client { get; }
- private IUserService Peers { get; }
+ private IUserService Users { get; }
/// <summary>
/// Retrieves the address of the specified <paramref name="username"/>.
@@ -66,7 +66,7 @@ namespace slskd.Users.API
{
try
{
- var endpoint = await Peers.GetIPEndPointAsync(username);
+ var endpoint = await Users.GetIPEndPointAsync(username);
return Ok(endpoint);
}
catch (UserOfflineException ex)
@@ -127,17 +127,16 @@ namespace slskd.Users.API
/// Retrieves information about the specified <paramref name="username"/>.
/// </summary>
/// <param name="username">The username of the user.</param>
- /// <param name="bypassCache">Bypasses the internal cache and requests the latest information from the peer.</param>
/// <returns></returns>
[HttpGet("{username}/info")]
[Authorize]
[ProducesResponseType(typeof(Info), 200)]
[ProducesResponseType(404)]
- public async Task<IActionResult> Info([FromRoute, Required] string username, [FromQuery]bool bypassCache = false)
+ public async Task<IActionResult> Info([FromRoute, Required] string username)
{
try
{
- var response = await Peers.GetInfoAsync(username, bypassCache);
+ var response = await Users.GetInfoAsync(username);
return Ok(response);
}
catch (UserOfflineException ex)
@@ -159,7 +158,7 @@ namespace slskd.Users.API
{
try
{
- var response = await Peers.GetStatusAsync(username);
+ var response = await Users.GetStatusAsync(username);
return Ok(response);
}
catch (UserOfflineException ex)
diff --git a/src/slskd/Users/Domain/Info.cs b/src/slskd/Users/Domain/Info.cs
index aaf19942..e3969f17 100644
--- a/src/slskd/Users/Domain/Info.cs
+++ b/src/slskd/Users/Domain/Info.cs
@@ -17,35 +17,13 @@
namespace slskd.Users
{
- using System;
- using System.ComponentModel.DataAnnotations;
- using Soulseek;
-
- public class Info
+ public record Info
{
- [Key]
- public string Username { get; init; }
public string Description { get; init; }
public bool HasFreeUploadSlot { get; init; }
public bool HasPicture { get; init; }
public byte[] Picture { get; init; }
public int QueueLength { get; init; }
public int UploadSlots { get; init; }
- public DateTime UpdatedAt { get; init; }
-
- public static Info FromSoulseekUserInfo(string username, UserInfo info)
- {
- return new Info()
- {
- Username = username,
- Description = info.Description,
- HasFreeUploadSlot = info.HasFreeUploadSlot,
- HasPicture = info.HasPicture,
- Picture = info.Picture,
- QueueLength = info.QueueLength,
- UploadSlots = info.UploadSlots,
- UpdatedAt = DateTime.UtcNow,
- };
- }
}
}
diff --git a/src/slskd/Users/Extensions.cs b/src/slskd/Users/Extensions.cs
index 846fd125..d2189a20 100644
--- a/src/slskd/Users/Extensions.cs
+++ b/src/slskd/Users/Extensions.cs
@@ -47,5 +47,20 @@ namespace slskd.Users
IsPrivileged = s.IsPrivileged,
Presence = s.Presence,
};
+
+ /// <summary>
+ /// Converts <see cref="Soulseek.UserInfo"/> to <see cref="Info"/>.
+ /// </summary>
+ /// <param name="i">The UserInfo instance to convert.</param>
+ /// <returns>The converted instance.</returns>
+ public static Info ToInfo(this UserInfo i) => new()
+ {
+ Description = i.Description,
+ HasFreeUploadSlot = i.HasFreeUploadSlot,
+ HasPicture = i.HasPicture,
+ Picture = i.Picture,
+ QueueLength = i.QueueLength,
+ UploadSlots = i.UploadSlots,
+ };
}
}
diff --git a/src/slskd/Users/IUserService.cs b/src/slskd/Users/IUserService.cs
index e78b1b1c..88090f9f 100644
--- a/src/slskd/Users/IUserService.cs
+++ b/src/slskd/Users/IUserService.cs
@@ -47,9 +47,8 @@ namespace slskd.Users
/// Retrieves peer <see cref="Info"/>.
/// </summary>
/// <param name="username">The username of the peer.</param>
- /// <param name="bypassCache">A value indicating whether the local cache should be bypassed.</param>
- /// <returns>The cached or retrieved info.</returns>
- Task<Info> GetInfoAsync(string username, bool bypassCache = false);
+ /// <returns>The retrieved info.</returns>
+ Task<Info> GetInfoAsync(string username);
/// <summary>
/// Retrieves a peer's IP endpoint, including their IP address and listen port.
diff --git a/src/slskd/Users/UserDbContext.cs b/src/slskd/Users/UserDbContext.cs
deleted file mode 100644
index 4d0fd08c..00000000
--- a/src/slskd/Users/UserDbContext.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// <copyright file="UserDbContext.cs" company="slskd Team">
-// Copyright (c) slskd Team. All rights reserved.
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published
-// by the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see https://www.gnu.org/licenses/.
-// </copyright>
-
-namespace slskd.Users
-{
- using Microsoft.EntityFrameworkCore;
-
- public class UserDbContext : DbContext
- {
- public UserDbContext(DbContextOptions<UserDbContext> options)
- : base(options)
- {
- Database.EnsureCreated();
- }
-
- public DbSet<Info> Info { get; set; }
- }
-}
diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs
index f081d8b1..aa2ae234 100644
--- a/src/slskd/Users/UserService.cs
+++ b/src/slskd/Users/UserService.cs
@@ -19,13 +19,11 @@ using Microsoft.Extensions.Options;
namespace slskd.Users
{
- using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
- using Microsoft.EntityFrameworkCore;
using Serilog;
using Soulseek;
@@ -34,27 +32,21 @@ namespace slskd.Users
/// </summary>
public class UserService : IUserService
{
- private const int CacheTTLSeconds = 300;
-
/// <summary>
/// Initializes a new instance of the <see cref="UserService"/> class.
/// </summary>
/// <param name="soulseekClient"></param>
/// <param name="stateMutator"></param>
- /// <param name="contextFactory">The database context to use.</param>
/// <param name="optionsMonitor"></param>
public UserService(
ISoulseekClient soulseekClient,
IStateMutator<State> stateMutator,
- IDbContextFactory<UserDbContext> contextFactory,
IOptionsMonitor<Options> optionsMonitor)
{
Client = soulseekClient;
StateMutator = stateMutator;
- ContextFactory = contextFactory;
-
OptionsMonitor = optionsMonitor;
OptionsMonitor.OnChange(options => Configure(options));
@@ -87,7 +79,6 @@ namespace slskd.Users
public IReadOnlyList<string> WatchedUsernames => WatchedUsernamesDictionary.Keys.ToList().AsReadOnly();
private ISoulseekClient Client { get; }
- private IDbContextFactory<UserDbContext> ContextFactory { get; }
private string LastOptionsHash { get; set; }
private ILogger Log { get; set; } = Serilog.Log.ForContext<UserService>();
private IOptionsMonitor<Options> OptionsMonitor { get; }
@@ -130,35 +121,11 @@ namespace slskd.Users
/// Retrieves peer <see cref="Info"/>.
/// </summary>
/// <param name="username">The username of the peer.</param>
- /// <param name="bypassCache">A value indicating whether the local cache should be bypassed.</param>
- /// <returns>The cached or retrieved info.</returns>
- public async Task<Info> GetInfoAsync(string username, bool bypassCache = false)
+ /// <returns>The retrieved info.</returns>
+ public async Task<Info> GetInfoAsync(string username)
{
- using var context = ContextFactory.CreateDbContext();
-
- var info = await context.Info.AsNoTracking().FirstOrDefaultAsync(peer => peer.Username == username);
- var peerExists = info != default;
-
- if (!bypassCache && peerExists && info.UpdatedAt < DateTime.UtcNow.AddSeconds(CacheTTLSeconds))
- {
- return info;
- }
-
var soulseekUserInfo = await Client.GetUserInfoAsync(username);
- info = Info.FromSoulseekUserInfo(username, soulseekUserInfo);
-
- if (peerExists)
- {
- context.Update(info);
- }
- else
- {
- context.Add(info);
- }
-
- await context.SaveChangesAsync();
-
- return info;
+ return soulseekUserInfo.ToInfo();
}
/// <summary>
diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj
index 70c689b8..e2c34310 100644
--- a/src/slskd/slskd.csproj
+++ b/src/slskd/slskd.csproj
@@ -76,6 +76,7 @@
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.1" />
+ <PackageReference Include="TagLibSharp" Version="2.2.0" />
<PackageReference Include="Utility.CommandLine.Arguments" Version="6.0.0" />
<PackageReference Include="Utility.EnvironmentVariables" Version="1.0.5" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
diff --git a/src/web/package-lock.json b/src/web/package-lock.json
index fc5fb063..4dac4452 100644
--- a/src/web/package-lock.json
+++ b/src/web/package-lock.json
@@ -12956,9 +12956,9 @@
}
},
"node_modules/node-forge": {
- "version": "1.2.1",
- "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz",
- "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==",
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.0.tgz",
+ "integrity": "sha512-08ARB91bUi6zNKzVmaj3QO7cr397uiDT2nJ63cHjyNtCTWIgvS47j3eT0WfzUwS9+6Z5YshRaoasFkXCKrIYbA==",
"dev": true,
"engines": {
"node": ">= 6.13.0"
@@ -29165,9 +29165,9 @@
}
},
"node-forge": {
- "version": "1.2.1",
- "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.2.1.tgz",
- "integrity": "sha512-Fcvtbb+zBcZXbTTVwqGA5W+MKBj56UjVRevvchv5XrcyXbmNdesfZL37nlcWOfpgHhgmxApw3tQbTr4CqNmX4w==",
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.0.tgz",
+ "integrity": "sha512-08ARB91bUi6zNKzVmaj3QO7cr397uiDT2nJ63cHjyNtCTWIgvS47j3eT0WfzUwS9+6Z5YshRaoasFkXCKrIYbA==",
"dev": true
},
"node-int64": {
diff --git a/src/web/public/favicon.ico b/src/web/public/favicon.ico
index 6c4ad2c2..c49cae35 100644
--- a/src/web/public/favicon.ico
+++ b/src/web/public/favicon.ico
Binary files differ
diff --git a/src/web/src/components/App.css b/src/web/src/components/App.css
index 720d5f5e..6244cdf8 100644
--- a/src/web/src/components/App.css
+++ b/src/web/src/components/App.css
@@ -68,8 +68,8 @@ body {
width: 100px;
}
-.filelist-bitrate {
- width: 70px;
+.filelist-attributes {
+ width: 115px;
}
.filelist-length{
diff --git a/src/web/src/components/Shared/FileList.js b/src/web/src/components/Shared/FileList.js
index e470563f..f38e602d 100644
--- a/src/web/src/components/Shared/FileList.js
+++ b/src/web/src/components/Shared/FileList.js
@@ -1,6 +1,6 @@
import React from 'react';
-import { formatSeconds, formatBytes, getFileName } from '../../lib/util';
+import { formatSeconds, formatBytes, getFileName, formatAttributes } from '../../lib/util';
import {
Header,
@@ -44,7 +44,7 @@ const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, o
</Table.HeaderCell>
<Table.HeaderCell className='filelist-filename'>File</Table.HeaderCell>
<Table.HeaderCell className='filelist-size'>Size</Table.HeaderCell>
- <Table.HeaderCell className='filelist-bitrate'>Bitrate</Table.HeaderCell>
+ <Table.HeaderCell className='filelist-attributes'>Attributes</Table.HeaderCell>
<Table.HeaderCell className='filelist-length'>Length</Table.HeaderCell>
</Table.Row>
</Table.Header>
@@ -61,7 +61,7 @@ const FileList = ({ directoryName, files, locked, onSelectionChange, disabled, o
</Table.Cell>
<Table.Cell className='filelist-filename'>{locked ? <Icon name='lock'/> : ''}{getFileName(f.filename)}</Table.Cell>
<Table.Cell className='filelist-size'>{formatBytes(f.size)}</Table.Cell>
- <Table.Cell className='filelist-bitrate'>{f.bitRate}</Table.Cell>
+ <Table.Cell className='filelist-attributes'>{formatAttributes(f)}</Table.Cell>
<Table.Cell className='filelist-length'>{formatSeconds(f.length)}</Table.Cell>
</Table.Row>
)}
diff --git a/src/web/src/lib/util.js b/src/web/src/lib/util.js
index 86bd6977..32c55090 100644
--- a/src/web/src/lib/util.js
+++ b/src/web/src/lib/util.js
@@ -34,6 +34,20 @@ export const getDirectoryName = (fullPath) => {
return path;
}
+export const formatAttributes = ({ bitRate, isVariableBitRate, bitDepth, sampleRate }) => {
+ const isLossless = !!sampleRate && !!bitDepth;
+
+ if (isLossless) {
+ return `${bitDepth}/${sampleRate/1000}kHz`;
+ }
+
+ if (isVariableBitRate) {
+ return `${bitRate}kbps, VBR`
+ }
+
+ return bitRate ? `${bitRate}kbps` : ''
+}
+
/* https://www.npmjs.com/package/js-file-download
*
* Copyright 2017 Kenneth Jiang
diff --git a/tests/slskd.Tests.Unit/Users/UserServiceTests.cs b/tests/slskd.Tests.Unit/Users/UserServiceTests.cs
index 8e8f6106..16b1c5fe 100644
--- a/tests/slskd.Tests.Unit/Users/UserServiceTests.cs
+++ b/tests/slskd.Tests.Unit/Users/UserServiceTests.cs
@@ -126,7 +126,6 @@
var service = new UserService(
mocks.SoulseekClient.Object,
mocks.StateMutator.Object,
- mocks.ContextFactory.Object,
mocks.OptionsMonitor);
return (service, mocks);
@@ -141,7 +140,6 @@
public Mock<ISoulseekClient> SoulseekClient { get; } = new Mock<ISoulseekClient>();
public Mock<IStateMutator<State>> StateMutator { get; } = new Mock<IStateMutator<State>>();
- public Mock<IDbContextFactory<UserDbContext>> ContextFactory { get; } = new Mock<IDbContextFactory<UserDbContext>>();
public TestOptionsMonitor<Options> OptionsMonitor { get; init; }
}
}