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.cs101
1 files changed, 76 insertions, 25 deletions
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs
index 4850b6fe05..6803ad3062 100644
--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs
+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs
@@ -1,23 +1,23 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
-using ServiceStack;
-using ServiceStack.Web;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
-using CommonIO;
-using WebMarkupMin.Core;
+using MediaBrowser.Common.Plugins;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.Plugins;
+using MediaBrowser.Model.Reflection;
+using MediaBrowser.Model.Services;
namespace MediaBrowser.WebDashboard.Api
{
@@ -79,7 +79,7 @@ namespace MediaBrowser.WebDashboard.Api
/// <summary>
/// Class DashboardService
/// </summary>
- public class DashboardService : IRestfulService, IHasResultFactory
+ public class DashboardService : IService, IHasResultFactory
{
/// <summary>
/// Gets or sets the logger.
@@ -112,6 +112,7 @@ namespace MediaBrowser.WebDashboard.Api
private readonly IFileSystem _fileSystem;
private readonly ILocalizationManager _localization;
private readonly IJsonSerializer _jsonSerializer;
+ private readonly IAssemblyInfo _assemblyInfo;
/// <summary>
/// Initializes a new instance of the <see cref="DashboardService" /> class.
@@ -119,13 +120,14 @@ namespace MediaBrowser.WebDashboard.Api
/// <param name="appHost">The app host.</param>
/// <param name="serverConfigurationManager">The server configuration manager.</param>
/// <param name="fileSystem">The file system.</param>
- public DashboardService(IServerApplicationHost appHost, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer)
+ public DashboardService(IServerApplicationHost appHost, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, IAssemblyInfo assemblyInfo)
{
_appHost = appHost;
_serverConfigurationManager = serverConfigurationManager;
_fileSystem = fileSystem;
_localization = localization;
_jsonSerializer = jsonSerializer;
+ _assemblyInfo = assemblyInfo;
}
/// <summary>
@@ -135,9 +137,32 @@ namespace MediaBrowser.WebDashboard.Api
/// <returns>System.Object.</returns>
public Task<object> Get(GetDashboardConfigurationPage request)
{
- var page = ServerEntryPoint.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase));
+ IPlugin plugin = null;
+ Stream stream = null;
- return ResultFactory.GetStaticResult(Request, page.Plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml("dummy.html", page.GetHtmlStream(), null, _appHost.ApplicationVersion.ToString(), null, false));
+ var page = ServerEntryPoint.Instance.PluginConfigurationPages.FirstOrDefault(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase));
+ if (page != null)
+ {
+ plugin = page.Plugin;
+ stream = page.GetHtmlStream();
+ }
+
+ if (plugin == null)
+ {
+ var altPage = GetPluginPages().FirstOrDefault(p => string.Equals(p.Item1.Name, request.Name, StringComparison.OrdinalIgnoreCase));
+ if (altPage != null)
+ {
+ plugin = altPage.Item2;
+ stream = _assemblyInfo.GetManifestResourceStream(plugin.GetType(), altPage.Item1.EmbeddedResourcePath);
+ }
+ }
+
+ if (plugin != null && stream != null)
+ {
+ return ResultFactory.GetStaticResult(Request, plugin.Version.ToString().GetMD5(), null, null, MimeTypes.GetMimeType("page.html"), () => GetPackageCreator().ModifyHtml("dummy.html", stream, null, _appHost.ApplicationVersion.ToString(), null, false));
+ }
+
+ throw new ResourceNotFoundException();
}
/// <summary>
@@ -165,7 +190,7 @@ namespace MediaBrowser.WebDashboard.Api
if (request.PageType.HasValue)
{
- pages = pages.Where(p => p.ConfigurationPageType == request.PageType.Value);
+ pages = pages.Where(p => p.ConfigurationPageType == request.PageType.Value).ToList();
}
// Don't allow a failing plugin to fail them all
@@ -185,9 +210,33 @@ namespace MediaBrowser.WebDashboard.Api
.Where(i => i != null)
.ToList();
+ configPages.AddRange(_appHost.Plugins.SelectMany(GetConfigPages));
+
return ResultFactory.GetOptimizedResult(Request, configPages);
}
+ private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages()
+ {
+ return _appHost.Plugins.SelectMany(GetPluginPages);
+ }
+
+ private IEnumerable<Tuple<PluginPageInfo, IPlugin>> GetPluginPages(IPlugin plugin)
+ {
+ var hasConfig = plugin as IHasWebPages;
+
+ if (hasConfig == null)
+ {
+ return new List<Tuple<PluginPageInfo, IPlugin>>();
+ }
+
+ return hasConfig.GetPages().Select(i => new Tuple<PluginPageInfo, IPlugin>(i, plugin));
+ }
+
+ private IEnumerable<ConfigurationPageInfo> GetConfigPages(IPlugin plugin)
+ {
+ return GetPluginPages(plugin).Select(i => new ConfigurationPageInfo(plugin, i.Item1));
+ }
+
public object Get(GetRobotsTxt request)
{
return Get(new GetDashboardResource
@@ -243,9 +292,7 @@ namespace MediaBrowser.WebDashboard.Api
cacheDuration = TimeSpan.FromDays(365);
}
- var assembly = GetType().Assembly.GetName();
-
- var cacheKey = (assembly.Version + (localizationCulture ?? string.Empty) + path).GetMD5();
+ var cacheKey = (_appHost.ApplicationVersion.ToString() + (localizationCulture ?? string.Empty) + path).GetMD5();
return await ResultFactory.GetStaticResult(Request, cacheKey, null, cacheDuration, contentType, () => GetResourceStream(path, localizationCulture)).ConfigureAwait(false);
}
@@ -339,11 +386,17 @@ namespace MediaBrowser.WebDashboard.Api
// Try to trim the output size a bit
var bowerPath = Path.Combine(path, "bower_components");
- GetDeployIgnoreExtensions().ForEach(i => DeleteFilesByExtension(bowerPath, i));
+ foreach (var ext in GetDeployIgnoreExtensions())
+ {
+ DeleteFilesByExtension(bowerPath, ext);
+ }
DeleteFilesByExtension(bowerPath, ".json", "strings\\");
- GetDeployIgnoreFilenames().ForEach(i => DeleteFilesByName(bowerPath, i.Item1, i.Item2));
+ foreach (var ignore in GetDeployIgnoreFilenames())
+ {
+ DeleteFilesByName(bowerPath, ignore.Item1, ignore.Item2);
+ }
DeleteFoldersByName(bowerPath, "demo");
DeleteFoldersByName(bowerPath, "test");
@@ -442,9 +495,9 @@ namespace MediaBrowser.WebDashboard.Api
private async Task DumpHtml(string source, string destination, string mode, string culture, string appVersion)
{
- foreach (var file in Directory.GetFiles(source, "*", SearchOption.TopDirectoryOnly))
+ foreach (var file in _fileSystem.GetFiles(source))
{
- var filename = Path.GetFileName(file);
+ var filename = file.Name;
await DumpFile(filename, Path.Combine(destination, filename), mode, culture, appVersion).ConfigureAwait(false);
}
@@ -454,7 +507,7 @@ namespace MediaBrowser.WebDashboard.Api
{
using (var stream = await GetPackageCreator().GetResource(resourceVirtualPath, mode, culture, appVersion, false).ConfigureAwait(false))
{
- using (var fs = _fileSystem.GetFileStream(destinationFilePath, FileMode.Create, FileAccess.Write, FileShare.Read))
+ using (var fs = _fileSystem.GetFileStream(destinationFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
{
stream.CopyTo(fs);
}
@@ -466,14 +519,12 @@ namespace MediaBrowser.WebDashboard.Api
_fileSystem.CreateDirectory(destination);
//Now Create all of the directories
- foreach (string dirPath in Directory.GetDirectories(source, "*",
- SearchOption.AllDirectories))
- _fileSystem.CreateDirectory(dirPath.Replace(source, destination));
+ foreach (var dirPath in _fileSystem.GetDirectories(source, true))
+ _fileSystem.CreateDirectory(dirPath.FullName.Replace(source, destination));
//Copy all the files & Replaces any files with the same name
- foreach (string newPath in Directory.GetFiles(source, "*.*",
- SearchOption.AllDirectories))
- _fileSystem.CopyFile(newPath, newPath.Replace(source, destination), true);
+ foreach (var newPath in _fileSystem.GetFiles(source, true))
+ _fileSystem.CopyFile(newPath.FullName, newPath.FullName.Replace(source, destination), true);
}
}