From 4bccaafb57abbc75858896374d42819f1c73fb20 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 24 Mar 2020 16:27:54 +0100 Subject: Use 'Length' instead of 'Any()' for an array --- MediaBrowser.WebDashboard/Api/DashboardService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.WebDashboard/Api/DashboardService.cs') diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index a71d685fb..1ca035f7b 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -140,7 +140,7 @@ namespace MediaBrowser.WebDashboard.Api if (appConfig.HostWebClient()) { string webContentPath = DashboardUIPath; - if (!Directory.Exists(webContentPath) || !Directory.GetFiles(webContentPath).Any()) + if (!Directory.Exists(webContentPath) || Directory.GetFiles(webContentPath).Length == 0) { throw new InvalidOperationException( "The server is expected to host the web client, but the provided content directory is either " + -- cgit v1.2.3 From ca85bef7c57108977d0f9813940f1ca942902d30 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Wed, 25 Mar 2020 18:52:14 +0100 Subject: Move check for web client directory to application startup in Program.cs --- Jellyfin.Server/Program.cs | 16 +++++++++++++ MediaBrowser.WebDashboard/Api/DashboardService.cs | 29 +++++++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.WebDashboard/Api/DashboardService.cs') diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index d9ca14136..2939d3378 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -20,6 +20,7 @@ using Jellyfin.Drawing.Skia; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Extensions; +using MediaBrowser.WebDashboard.Api; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -185,8 +186,23 @@ namespace Jellyfin.Server new ManagedFileSystem(_loggerFactory.CreateLogger(), appPaths), GetImageEncoder(appPaths), new NetworkManager(_loggerFactory.CreateLogger())); + try { + // If hosting the web client, validate the client content path + if (startupConfig.HostWebClient()) + { + string webContentPath = DashboardService.GetDashboardUIPath(startupConfig, appHost.ServerConfigurationManager); + if (!Directory.Exists(webContentPath) || Directory.GetFiles(webContentPath).Length == 0) + { + throw new InvalidOperationException( + "The server is expected to host the web client, but the provided content directory is either " + + $"invalid or empty: {webContentPath}. If you do not want to host the web client with the " + + "server, you may set the '--nowebclient' command line flag, or set" + + $"'{MediaBrowser.Controller.Extensions.ConfigurationExtensions.HostWebClientKey}=false' in your config settings."); + } + } + ServiceCollection serviceCollection = new ServiceCollection(); await appHost.InitAsync(serviceCollection, startupConfig).ConfigureAwait(false); diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 1ca035f7b..938ab513b 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -161,22 +161,27 @@ namespace MediaBrowser.WebDashboard.Api /// Gets the path of the directory containing the static web interface content, or null if the server is not /// hosting the web client. /// - public string DashboardUIPath + public string DashboardUIPath => GetDashboardUIPath(_appConfig, _serverConfigurationManager); + + /// + /// Gets the path of the directory containing the static web interface content. + /// + /// The app configuration. + /// The server configuration manager. + /// The directory path, or null if the server is not hosting the web client. + public static string GetDashboardUIPath(IConfiguration appConfig, IServerConfigurationManager serverConfigManager) { - get + if (!appConfig.HostWebClient()) { - if (!_appConfig.HostWebClient()) - { - return null; - } - - if (!string.IsNullOrEmpty(_serverConfigurationManager.Configuration.DashboardSourcePath)) - { - return _serverConfigurationManager.Configuration.DashboardSourcePath; - } + return null; + } - return _serverConfigurationManager.ApplicationPaths.WebPath; + if (!string.IsNullOrEmpty(serverConfigManager.Configuration.DashboardSourcePath)) + { + return serverConfigManager.Configuration.DashboardSourcePath; } + + return serverConfigManager.ApplicationPaths.WebPath; } [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "request", Justification = "Required for ServiceStack")] -- cgit v1.2.3 From 861bad1edaec10fa03d2f7cf12bb8b7b6ae1802c Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Wed, 1 Apr 2020 13:26:47 +0200 Subject: Apply suggestions from code review --- .../Extensions/ConfigurationExtensions.cs | 2 +- MediaBrowser.WebDashboard/Api/DashboardService.cs | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'MediaBrowser.WebDashboard/Api/DashboardService.cs') diff --git a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs index c95149984..c0043c0ef 100644 --- a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs +++ b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Controller.Extensions public const string PlaylistsAllowDuplicatesKey = "playlists:allowDuplicates"; /// - /// Gets a value indicating whether the application should not host static web content from the . + /// Gets a value indicating whether the application should host static web content from the . /// /// The configuration to retrieve the value from. /// The parsed config value. diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 938ab513b..133a35527 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -135,20 +135,6 @@ namespace MediaBrowser.WebDashboard.Api _serverConfigurationManager = serverConfigurationManager; _fileSystem = fileSystem; _resultFactory = resultFactory; - - // If hosting the web client, validate the client content path - if (appConfig.HostWebClient()) - { - string webContentPath = DashboardUIPath; - if (!Directory.Exists(webContentPath) || Directory.GetFiles(webContentPath).Length == 0) - { - throw new InvalidOperationException( - "The server is expected to host the web client, but the provided content directory is either " + - $"invalid or empty: {webContentPath}. If you do not want to host the web client with the " + - "server, you may set the '--nowebclient' command line flag, or set" + - $"'{Controller.Extensions.ConfigurationExtensions.HostWebClientKey}=false' in your config settings."); - } - } } /// -- cgit v1.2.3