From 2ae3d78e9bc56de3dde214d647ee9d0ec5008194 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 31 Jan 2021 22:34:29 -0600 Subject: remove remaining legacy options --- src/slskd/Controllers/TransfersController.cs | 7 +++--- src/slskd/Startup.cs | 37 +++++++++------------------- 2 files changed, 16 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/slskd/Controllers/TransfersController.cs b/src/slskd/Controllers/TransfersController.cs index d4fa3f79..505e84e5 100644 --- a/src/slskd/Controllers/TransfersController.cs +++ b/src/slskd/Controllers/TransfersController.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using slskd.DTO; using slskd.Trackers; + using Microsoft.Extensions.Options; /// /// Transfers @@ -26,12 +27,12 @@ /// /// Initializes a new instance of the class. /// - /// + /// /// /// - public TransfersController(IConfiguration configuration, ISoulseekClient client, ITransferTracker tracker) + public TransfersController(IOptionsSnapshot options, ISoulseekClient client, ITransferTracker tracker) { - OutputDirectory = configuration.GetValue("OUTPUT_DIR"); + OutputDirectory = options.Value.Directories.Downloads; Client = client; Tracker = tracker; } diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index 3479926b..31542f1a 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -36,13 +36,7 @@ { private readonly int MaxReconnectAttempts = 3; private int CurrentReconnectAttempts = 0; - - internal static string OutputDirectory { get; set; } - internal static string SharedDirectory { get; set; } - internal static long SharedCacheTTL { get; set; } - internal static DiagnosticLevel DiagnosticLevel { get; set; } - internal static int RoomMessageLimit { get; set; } - internal static string XmlDocFile { get; set; } + private static readonly string XmlDocFile = Path.Combine(AppContext.BaseDirectory, typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml"); private SoulseekClient Client { get; set; } private ISharedFileCache SharedFileCache { get; set; } @@ -60,14 +54,14 @@ o.BindNonPublicProperties = true; }); - OutputDirectory = Configuration.GetValue("OUTPUT_DIR"); - SharedDirectory = Configuration.GetValue("SHARED_DIR"); - SharedCacheTTL = Configuration.GetValue("SHARED_CACHE_TTL", 3600000); // 1 hour - DiagnosticLevel = Configuration.GetValue("DIAGNOSTIC", DiagnosticLevel.Info); - RoomMessageLimit = Configuration.GetValue("ROOM_MESSAGE_LIMIT", 250); - XmlDocFile = Configuration.GetValue("XML_DOC_FILE", Path.Combine(AppContext.BaseDirectory, typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml")); - - SharedFileCache = new SharedFileCache(SharedDirectory, SharedCacheTTL); + SharedFileCache = new SharedFileCache(Options.Directories.Shared, 3600000); + + UrlBase = Options.Web.UrlBase; + UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase; + + ContentPath = Path.GetFullPath(Options.Web.ContentPath); + + JwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Options.Web.Jwt.Key)); } private IConfiguration Configuration { get; } @@ -81,13 +75,6 @@ services.AddOptions() .Bind(Configuration.GetSection("slskd"), o => { o.BindNonPublicProperties = true; }); - UrlBase = Options.Web.UrlBase; - UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase; - - ContentPath = Path.GetFullPath(Options.Web.ContentPath); - - JwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Options.Web.Jwt.Key)); - services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); services.AddSingleton(JwtSigningKey); @@ -164,7 +151,7 @@ services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(_ => new RoomTracker(messageLimit: RoomMessageLimit)); + services.AddSingleton(_ => new RoomTracker(messageLimit: 250)); } public void Configure( @@ -296,7 +283,7 @@ userEndPointCache: new UserEndPointCache(), distributedChildLimit: Options.Soulseek.DistributedNetwork.ChildLimit, enableDistributedNetwork: !Options.Soulseek.DistributedNetwork.Disabled, - minimumDiagnosticLevel: DiagnosticLevel, + minimumDiagnosticLevel: Options.Soulseek.DiagnosticLevel, autoAcknowledgePrivateMessages: false, acceptPrivateRoomInvitations: true, serverConnectionOptions: connectionOptions, @@ -465,7 +452,7 @@ private Task BrowseResponseResolver(string username, IPEndPoint endpoint) { var directories = System.IO.Directory - .GetDirectories(SharedDirectory, "*", SearchOption.AllDirectories) + .GetDirectories(Options.Directories.Shared, "*", SearchOption.AllDirectories) .Select(dir => new Soulseek.Directory(dir, System.IO.Directory.GetFiles(dir) .Select(f => new Soulseek.File(1, Path.GetFileName(f), new FileInfo(f).Length, Path.GetExtension(f))))); -- cgit v1.2.3