diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-03-26 12:44:43 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-26 12:44:43 -0500 |
| commit | 751845f25d660c57e5dd9c6e179d12c10df7ab33 (patch) | |
| tree | bebc32f1e78c7fe2e439fb5246adde10daaff86d /src | |
| parent | 49cc058ea14435718abf2e95e36b8ef6c12b27bf (diff) | |
| parent | a5b7e657d6fe38c416dc01461424f79aa452f197 (diff) | |
| download | slskd-751845f25d660c57e5dd9c6e179d12c10df7ab33.tar.gz | |
Merge branch 'master' into userinfo
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Shares/Domain/Share.cs | 75 | ||||
| -rw-r--r-- | src/slskd/Shares/SharedFileCache.cs | 56 | ||||
| -rw-r--r-- | src/slskd/Shares/SoulseekFileFactory.cs | 120 | ||||
| -rw-r--r-- | src/slskd/Startup.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Users/API/Controllers/UsersController.cs | 17 | ||||
| -rw-r--r-- | src/slskd/Users/Domain/Info.cs | 24 | ||||
| -rw-r--r-- | src/slskd/Users/Extensions.cs | 15 | ||||
| -rw-r--r-- | src/slskd/Users/IUserService.cs | 5 | ||||
| -rw-r--r-- | src/slskd/Users/UserDbContext.cs | 32 | ||||
| -rw-r--r-- | src/slskd/Users/UserService.cs | 39 | ||||
| -rw-r--r-- | src/slskd/slskd.csproj | 1 | ||||
| -rw-r--r-- | src/web/package-lock.json | 12 | ||||
| -rw-r--r-- | src/web/public/favicon.ico | bin | 1150 -> 15086 bytes | |||
| -rw-r--r-- | src/web/src/components/App.css | 4 | ||||
| -rw-r--r-- | src/web/src/components/Shared/FileList.js | 6 | ||||
| -rw-r--r-- | src/web/src/lib/util.js | 14 |
16 files changed, 257 insertions, 169 deletions
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 Binary files differindex 6c4ad2c2..c49cae35 100644 --- a/src/web/public/favicon.ico +++ b/src/web/public/favicon.ico 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 |
