aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.WebDashboard/Api/DashboardService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.WebDashboard/Api/DashboardService.cs')
-rw-r--r--MediaBrowser.WebDashboard/Api/DashboardService.cs38
1 files changed, 35 insertions, 3 deletions
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs
index 99d8d044f..3e47ce682 100644
--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs
+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs
@@ -12,12 +12,14 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Services;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.WebDashboard.Api
@@ -102,6 +104,7 @@ namespace MediaBrowser.WebDashboard.Api
/// <value>The HTTP result factory.</value>
private readonly IHttpResultFactory _resultFactory;
private readonly IServerApplicationHost _appHost;
+ private readonly IConfiguration _appConfig;
private readonly IServerConfigurationManager _serverConfigurationManager;
private readonly IFileSystem _fileSystem;
private readonly IResourceFileManager _resourceFileManager;
@@ -111,6 +114,7 @@ namespace MediaBrowser.WebDashboard.Api
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="appHost">The application host.</param>
+ /// <param name="appConfig">The application configuration.</param>
/// <param name="resourceFileManager">The resource file manager.</param>
/// <param name="serverConfigurationManager">The server configuration manager.</param>
/// <param name="fileSystem">The file system.</param>
@@ -118,6 +122,7 @@ namespace MediaBrowser.WebDashboard.Api
public DashboardService(
ILogger<DashboardService> logger,
IServerApplicationHost appHost,
+ IConfiguration appConfig,
IResourceFileManager resourceFileManager,
IServerConfigurationManager serverConfigurationManager,
IFileSystem fileSystem,
@@ -125,10 +130,22 @@ namespace MediaBrowser.WebDashboard.Api
{
_logger = logger;
_appHost = appHost;
+ _appConfig = appConfig;
_resourceFileManager = resourceFileManager;
_serverConfigurationManager = serverConfigurationManager;
_fileSystem = fileSystem;
_resultFactory = resultFactory;
+
+ // Validate web content path
+ string webContentPath = DashboardUIPath;
+ bool webContentPathValid = appConfig.NoWebContent() || (Directory.Exists(webContentPath) && Directory.GetFiles(webContentPath).Any());
+ if (!webContentPathValid)
+ {
+ throw new InvalidOperationException(
+ "The server is expected to host web content, but the provided content directory is either " +
+ $"invalid or empty: {webContentPath}. If you do not want to host web content with the server, " +
+ $"you may set the '{Controller.Extensions.ConfigurationExtensions.NoWebContentKey}' flag.");
+ }
}
/// <summary>
@@ -138,13 +155,18 @@ namespace MediaBrowser.WebDashboard.Api
public IRequest Request { get; set; }
/// <summary>
- /// Gets the path for the web interface.
+ /// Gets the path of the directory containing the static web interface content, or null if the server is not
+ /// hosting the static web content.
/// </summary>
- /// <value>The path for the web interface.</value>
public string DashboardUIPath
{
get
{
+ if (_appConfig.NoWebContent())
+ {
+ return null;
+ }
+
if (!string.IsNullOrEmpty(_serverConfigurationManager.Configuration.DashboardSourcePath))
{
return _serverConfigurationManager.Configuration.DashboardSourcePath;
@@ -209,7 +231,7 @@ namespace MediaBrowser.WebDashboard.Api
return _resultFactory.GetStaticResult(Request, plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => Task.FromResult(stream));
}
- return _resultFactory.GetStaticResult(Request, plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator(DashboardUIPath).ModifyHtml("dummy.html", stream, null, _appHost.ApplicationVersionString, null));
+ return _resultFactory.GetStaticResult(Request, plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => PackageCreator.ModifyHtml(false, stream, null, _appHost.ApplicationVersionString, null));
}
throw new ResourceNotFoundException();
@@ -307,6 +329,11 @@ namespace MediaBrowser.WebDashboard.Api
/// <returns>System.Object.</returns>
public async Task<object> Get(GetDashboardResource request)
{
+ if (_appConfig.NoWebContent() || DashboardUIPath == null)
+ {
+ throw new ResourceNotFoundException();
+ }
+
var path = request.ResourceName;
var contentType = MimeTypes.GetMimeType(path);
@@ -378,6 +405,11 @@ namespace MediaBrowser.WebDashboard.Api
public async Task<object> Get(GetDashboardPackage request)
{
+ if (_appConfig.NoWebContent() || DashboardUIPath == null)
+ {
+ throw new ResourceNotFoundException();
+ }
+
var mode = request.Mode;
var inputPath = string.IsNullOrWhiteSpace(mode) ?