Use constants for settings keys

This commit is contained in:
Mark Monteiro 2020-02-28 17:57:38 +01:00
parent d95ccbacac
commit 3043b7323b
4 changed files with 19 additions and 5 deletions

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Emby.Server.Implementations.HttpServer;
using MediaBrowser.Providers.Music;
using static MediaBrowser.Controller.Extensions.ConfigurationExtensions; using static MediaBrowser.Controller.Extensions.ConfigurationExtensions;
namespace Emby.Server.Implementations namespace Emby.Server.Implementations
@ -13,8 +15,8 @@ namespace Emby.Server.Implementations
/// </summary> /// </summary>
public static Dictionary<string, string> DefaultConfiguration => new Dictionary<string, string> public static Dictionary<string, string> DefaultConfiguration => new Dictionary<string, string>
{ {
{ "HttpListenerHost:DefaultRedirectPath", "web/index.html" }, { HttpListenerHost.DefaultRedirectKey, "web/index.html" },
{ "MusicBrainz:BaseUrl", "https://www.musicbrainz.org" }, { MusicBrainzAlbumProvider.BaseUrlKey, "https://www.musicbrainz.org" },
{ FfmpegProbeSizeKey, "1G" }, { FfmpegProbeSizeKey, "1G" },
{ FfmpegAnalyzeDurationKey, "200M" } { FfmpegAnalyzeDurationKey, "200M" }
}; };

View File

@ -30,6 +30,12 @@ namespace Emby.Server.Implementations.HttpServer
{ {
public class HttpListenerHost : IHttpServer, IDisposable public class HttpListenerHost : IHttpServer, IDisposable
{ {
/// <summary>
/// The settings key for a setting that specifies the default redirect path
/// to use for requests where the URL base prefix is invalid or missing.
/// </summary>
public const string DefaultRedirectKey = "HttpListenerHost:DefaultRedirectPath";
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
@ -58,7 +64,7 @@ namespace Emby.Server.Implementations.HttpServer
_appHost = applicationHost; _appHost = applicationHost;
_logger = logger; _logger = logger;
_config = config; _config = config;
_defaultRedirectPath = configuration["HttpListenerHost:DefaultRedirectPath"]; _defaultRedirectPath = configuration[DefaultRedirectKey];
_baseUrlPrefix = _config.Configuration.BaseUrl; _baseUrlPrefix = _config.Configuration.BaseUrl;
_networkManager = networkManager; _networkManager = networkManager;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;

View File

@ -13,6 +13,7 @@ using System.Threading.Tasks;
using CommandLine; using CommandLine;
using Emby.Drawing; using Emby.Drawing;
using Emby.Server.Implementations; using Emby.Server.Implementations;
using Emby.Server.Implementations.HttpServer;
using Emby.Server.Implementations.IO; using Emby.Server.Implementations.IO;
using Emby.Server.Implementations.Networking; using Emby.Server.Implementations.Networking;
using Jellyfin.Drawing.Skia; using Jellyfin.Drawing.Skia;
@ -470,7 +471,7 @@ namespace Jellyfin.Server
var inMemoryDefaultConfig = ConfigurationOptions.DefaultConfiguration; var inMemoryDefaultConfig = ConfigurationOptions.DefaultConfiguration;
if (string.IsNullOrEmpty(appPaths.WebPath)) if (string.IsNullOrEmpty(appPaths.WebPath))
{ {
inMemoryDefaultConfig["HttpListenerHost:DefaultRedirectPath"] = "swagger/index.html"; inMemoryDefaultConfig[HttpListenerHost.DefaultRedirectKey] = "swagger/index.html";
} }
return new ConfigurationBuilder() return new ConfigurationBuilder()

View File

@ -22,6 +22,11 @@ namespace MediaBrowser.Providers.Music
{ {
public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>, IHasOrder public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>, IHasOrder
{ {
/// <summary>
/// The settings key for a setting that specifies the base URL to use for sending requests to MusicBrainz.
/// </summary>
public const string BaseUrlKey = "MusicBrainz:BaseUrl";
/// <summary> /// <summary>
/// The Jellyfin user-agent is unrestricted but source IP must not exceed /// The Jellyfin user-agent is unrestricted but source IP must not exceed
/// one request per second, therefore we rate limit to avoid throttling. /// one request per second, therefore we rate limit to avoid throttling.
@ -57,7 +62,7 @@ namespace MediaBrowser.Providers.Music
_appHost = appHost; _appHost = appHost;
_logger = logger; _logger = logger;
_musicBrainzBaseUrl = configuration["MusicBrainz:BaseUrl"]; _musicBrainzBaseUrl = configuration[BaseUrlKey];
// Use a stopwatch to ensure we don't exceed the MusicBrainz rate limit // Use a stopwatch to ensure we don't exceed the MusicBrainz rate limit
_stopWatchMusicBrainz.Start(); _stopWatchMusicBrainz.Start();