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.cs137
1 files changed, 93 insertions, 44 deletions
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs
index 030dc7f33..d24a4a3de 100644
--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs
+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs
@@ -203,7 +203,7 @@ namespace MediaBrowser.WebDashboard.Api
if (!_serverConfigurationManager.Configuration.IsStartupWizardCompleted && path.IndexOf("wizard", StringComparison.OrdinalIgnoreCase) == -1 && GetPackageCreator().IsCoreHtml(path))
{
// But don't redirect if an html import is being requested.
- if (path.IndexOf("vulcanize", StringComparison.OrdinalIgnoreCase) == -1 && path.IndexOf("bower_components", StringComparison.OrdinalIgnoreCase) == -1)
+ if (path.IndexOf("bower_components", StringComparison.OrdinalIgnoreCase) == -1)
{
Request.Response.Redirect("wizardstart.html");
return null;
@@ -303,59 +303,109 @@ namespace MediaBrowser.WebDashboard.Api
var mode = request.Mode;
+ // Try to trim the output size a bit
+ var bowerPath = Path.Combine(path, "bower_components");
+ DeleteFilesByExtension(bowerPath, ".log");
+ DeleteFilesByExtension(bowerPath, ".txt");
+ DeleteFilesByExtension(bowerPath, ".map");
+ DeleteFilesByExtension(bowerPath, ".md");
+ DeleteFilesByExtension(bowerPath, ".json");
+ DeleteFilesByExtension(bowerPath, ".gz");
+ DeleteFilesByName(bowerPath, "copying", true);
+ DeleteFilesByName(bowerPath, "license", true);
+ DeleteFilesByName(bowerPath, "license-mit", true);
+ DeleteFilesByName(bowerPath, "gitignore");
+ DeleteFilesByName(bowerPath, "npmignore");
+ DeleteFilesByName(bowerPath, "jshintrc");
+ DeleteFilesByName(bowerPath, "gruntfile");
+ DeleteFilesByName(bowerPath, "bowerrc");
+ DeleteFilesByName(bowerPath, "jscsrc");
+ DeleteFilesByName(bowerPath, "hero.svg");
+ DeleteFilesByName(bowerPath, "travis.yml");
+ DeleteFilesByName(bowerPath, "build.js");
+ DeleteFilesByName(bowerPath, "editorconfig");
+ DeleteFilesByName(bowerPath, "gitattributes");
+ DeleteFoldersByName(bowerPath, "demo");
+ DeleteFoldersByName(bowerPath, "test");
+ DeleteFoldersByName(bowerPath, "guides");
+ DeleteFoldersByName(bowerPath, "grunt");
+
+ DeleteFoldersByName(Path.Combine(bowerPath, "jquery"), "src");
+ DeleteFoldersByName(Path.Combine(bowerPath, "jstree"), "src");
+ DeleteFoldersByName(Path.Combine(bowerPath, "Sortable"), "meteor");
+ DeleteFoldersByName(Path.Combine(bowerPath, "Sortable"), "st");
+ DeleteFoldersByName(Path.Combine(bowerPath, "swipebox"), "lib");
+ DeleteFoldersByName(Path.Combine(bowerPath, "swipebox"), "scss");
+
if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))
{
- // Overwrite certain files with cordova specific versions
- var cordovaVersion = Path.Combine(path, "cordova", "registrationservices.js");
- _fileSystem.CopyFile(cordovaVersion, Path.Combine(path, "scripts", "registrationservices.js"), true);
- _fileSystem.DeleteFile(cordovaVersion);
-
// Delete things that are unneeded in an attempt to keep the output as trim as possible
_fileSystem.DeleteDirectory(Path.Combine(path, "css", "images", "tour"), true);
- _fileSystem.DeleteDirectory(Path.Combine(path, "apiclient", "alt"), true);
_fileSystem.DeleteFile(Path.Combine(path, "thirdparty", "jquerymobile-1.4.5", "jquery.mobile-1.4.5.min.map"));
+ }
+ else
+ {
+ MinifyCssDirectory(path);
+ MinifyJsDirectory(path);
+ }
- _fileSystem.DeleteDirectory(Path.Combine(path, "bower_components"), true);
- _fileSystem.DeleteDirectory(Path.Combine(path, "thirdparty", "viblast"), true);
+ await DumpHtml(creator.DashboardUIPath, path, mode, culture, appVersion);
- // But we do need this
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "webcomponentsjs", "webcomponents-lite.js"), Path.Combine(path, "bower_components", "webcomponentsjs", "webcomponents-lite.js"));
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "webcomponentsjs", "webcomponents-lite.min.js"), Path.Combine(path, "bower_components", "webcomponentsjs", "webcomponents-lite.min.js"));
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "velocity", "velocity.min.js"), Path.Combine(path, "bower_components", "velocity", "velocity.min.js"));
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "requirejs", "require.js"), Path.Combine(path, "bower_components", "requirejs", "require.js"));
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "fastclick", "lib", "fastclick.js"), Path.Combine(path, "bower_components", "fastclick", "lib", "fastclick.js"));
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "jquery", "dist", "jquery.min.js"), Path.Combine(path, "bower_components", "jquery", "dist", "jquery.min.js"));
+ await DumpFile("css/all.css", Path.Combine(path, "css", "all.css"), mode, culture, appVersion).ConfigureAwait(false);
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "jstree", "dist", "jstree.min.js"), Path.Combine(path, "bower_components", "jstree", "dist", "jstree.min.js"));
-
- CopyDirectory(Path.Combine(creator.DashboardUIPath, "bower_components", "swipebox", "src", "css"), Path.Combine(path, "bower_components", "swipebox", "src", "css"));
- CopyDirectory(Path.Combine(creator.DashboardUIPath, "bower_components", "swipebox", "src", "js"), Path.Combine(path, "bower_components", "swipebox", "src", "js"));
- CopyDirectory(Path.Combine(creator.DashboardUIPath, "bower_components", "swipebox", "src", "img"), Path.Combine(path, "bower_components", "swipebox", "src", "img"));
+ return "";
+ }
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "hammerjs", "hammer.min.js"), Path.Combine(path, "bower_components", "hammerjs", "hammer.min.js"));
+ private void DeleteFilesByExtension(string path, string extension)
+ {
+ var files = _fileSystem.GetFiles(path, true)
+ .Where(i => string.Equals(i.Extension, extension, StringComparison.OrdinalIgnoreCase))
+ .ToList();
- CopyFile(Path.Combine(creator.DashboardUIPath, "bower_components", "Sortable", "Sortable.min.js"), Path.Combine(path, "bower_components", "Sortable", "Sortable.min.js"));
+ foreach (var file in files)
+ {
+ _fileSystem.DeleteFile(file.FullName);
}
-
- MinifyCssDirectory(Path.Combine(path, "css"));
- MinifyJsDirectory(Path.Combine(path, "scripts"));
- MinifyJsDirectory(Path.Combine(path, "apiclient"));
- MinifyJsDirectory(Path.Combine(path, "voice"));
+ }
- await DumpHtml(creator.DashboardUIPath, path, mode, culture, appVersion);
- await DumpJs(creator.DashboardUIPath, path, mode, culture, appVersion);
+ private void DeleteFilesByName(string path, string name, bool exact = false)
+ {
+ var files = _fileSystem.GetFiles(path, true)
+ .Where(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase) || (!exact && i.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) != -1))
+ .ToList();
- await DumpFile("scripts/all.js", Path.Combine(path, "scripts", "all.js"), mode, culture, appVersion).ConfigureAwait(false);
- await DumpFile("css/all.css", Path.Combine(path, "css", "all.css"), mode, culture, appVersion).ConfigureAwait(false);
+ foreach (var file in files)
+ {
+ _fileSystem.DeleteFile(file.FullName);
+ }
+ }
- return "";
+ private void DeleteFoldersByName(string path, string name)
+ {
+ var directories = _fileSystem.GetDirectories(path, true)
+ .Where(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase))
+ .ToList();
+
+ foreach (var directory in directories)
+ {
+ _fileSystem.DeleteDirectory(directory.FullName, true);
+ }
}
private void MinifyCssDirectory(string path)
{
foreach (var file in Directory.GetFiles(path, "*.css", SearchOption.AllDirectories))
{
+ if (file.IndexOf(".min.", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ continue;
+ }
+ if (file.IndexOf("bower_", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ continue;
+ }
+
try
{
var text = _fileSystem.ReadAllText(file, Encoding.UTF8);
@@ -383,6 +433,15 @@ namespace MediaBrowser.WebDashboard.Api
{
foreach (var file in Directory.GetFiles(path, "*.js", SearchOption.AllDirectories))
{
+ if (file.IndexOf(".min.", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ continue;
+ }
+ if (file.IndexOf("bower_", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ continue;
+ }
+
try
{
var text = _fileSystem.ReadAllText(file, Encoding.UTF8);
@@ -408,7 +467,7 @@ 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, "*.html", SearchOption.TopDirectoryOnly))
+ foreach (var file in Directory.GetFiles(source, "*", SearchOption.TopDirectoryOnly))
{
var filename = Path.GetFileName(file);
@@ -428,16 +487,6 @@ namespace MediaBrowser.WebDashboard.Api
}
}
- private async Task DumpJs(string source, string mode, string destination, string culture, string appVersion)
- {
- foreach (var file in Directory.GetFiles(source, "*.js", SearchOption.TopDirectoryOnly))
- {
- var filename = Path.GetFileName(file);
-
- await DumpFile("scripts/" + filename, Path.Combine(destination, "scripts", filename), mode, culture, appVersion).ConfigureAwait(false);
- }
- }
-
private async Task DumpFile(string resourceVirtualPath, string destinationFilePath, string mode, string culture, string appVersion)
{
using (var stream = await GetPackageCreator().GetResource(resourceVirtualPath, mode, culture, appVersion, true).ConfigureAwait(false))