diff options
Diffstat (limited to 'MediaBrowser.WebDashboard/Api/DashboardService.cs')
| -rw-r--r-- | MediaBrowser.WebDashboard/Api/DashboardService.cs | 119 |
1 files changed, 81 insertions, 38 deletions
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 34ad32111..aec4632ae 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -17,7 +17,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using CommonIO; -using WebMarkupMin.Core.Minifiers; +using WebMarkupMin.Core; namespace MediaBrowser.WebDashboard.Api { @@ -58,6 +58,11 @@ namespace MediaBrowser.WebDashboard.Api { } + [Route("/web/staticfiles", "GET")] + public class GetCacheFiles + { + } + /// <summary> /// Class GetDashboardResource /// </summary> @@ -140,6 +145,37 @@ namespace MediaBrowser.WebDashboard.Api 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)); } + public object Get(GetCacheFiles request) + { + var allFiles = GetCacheFileList(); + + return ResultFactory.GetOptimizedResult(Request, _jsonSerializer.SerializeToString(allFiles)); + } + + private List<string> GetCacheFileList() + { + var creator = GetPackageCreator(); + var directory = creator.DashboardUIPath; + + var skipExtensions = GetDeployIgnoreExtensions(); + var skipNames = GetDeployIgnoreFilenames(); + + return + Directory.GetFiles(directory, "*", SearchOption.AllDirectories) + .Where(i => !skipExtensions.Contains(Path.GetExtension(i) ?? string.Empty, StringComparer.OrdinalIgnoreCase)) + .Where(i => !skipNames.Any(s => + { + if (s.Item2) + { + return string.Equals(s.Item1, Path.GetFileName(i), StringComparison.OrdinalIgnoreCase); + } + + return (Path.GetFileName(i) ?? string.Empty).IndexOf(s.Item1, StringComparison.OrdinalIgnoreCase) != -1; + })) + .Select(i => i.Replace(directory, string.Empty, StringComparison.OrdinalIgnoreCase).Replace("\\", "/").TrimStart('/') + "?v=" + _appHost.ApplicationVersion.ToString()) + .ToList(); + } + /// <summary> /// Gets the specified request. /// </summary> @@ -274,6 +310,43 @@ namespace MediaBrowser.WebDashboard.Api return new PackageCreator(_fileSystem, _localization, Logger, _serverConfigurationManager, _jsonSerializer); } + private List<string> GetDeployIgnoreExtensions() + { + var list = new List<string>(); + + list.Add(".log"); + list.Add(".txt"); + list.Add(".map"); + list.Add(".md"); + list.Add(".gz"); + list.Add(".bat"); + list.Add(".sh"); + + return list; + } + + private List<Tuple<string,bool>> GetDeployIgnoreFilenames() + { + var list = new List<Tuple<string, bool>>(); + + list.Add(new Tuple<string, bool>("copying", true)); + list.Add(new Tuple<string, bool>("license", true)); + list.Add(new Tuple<string, bool>("license-mit", true)); + list.Add(new Tuple<string, bool>("gitignore", false)); + list.Add(new Tuple<string, bool>("npmignore", false)); + list.Add(new Tuple<string, bool>("jshintrc", false)); + list.Add(new Tuple<string, bool>("gruntfile", false)); + list.Add(new Tuple<string, bool>("bowerrc", false)); + list.Add(new Tuple<string, bool>("jscsrc", false)); + list.Add(new Tuple<string, bool>("hero.svg", false)); + list.Add(new Tuple<string, bool>("travis.yml", false)); + list.Add(new Tuple<string, bool>("build.js", false)); + list.Add(new Tuple<string, bool>("editorconfig", false)); + list.Add(new Tuple<string, bool>("gitattributes", false)); + + return list; + } + public async Task<object> Get(GetDashboardPackage request) { var path = Path.Combine(_serverConfigurationManager.ApplicationPaths.ProgramDataPath, @@ -296,45 +369,19 @@ namespace MediaBrowser.WebDashboard.Api var appVersion = _appHost.ApplicationVersion.ToString(); - var mode = request.Mode; + File.WriteAllText(Path.Combine(path, "staticfiles"), _jsonSerializer.SerializeToString(GetCacheFileList())); - if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase)) - { - _fileSystem.DeleteFile(Path.Combine(path, "scripts", "registrationservices.js")); - } + var mode = request.Mode; // Try to trim the output size a bit var bowerPath = Path.Combine(path, "bower_components"); - if (!string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase)) - { - //var versionedBowerPath = Path.Combine(Path.GetDirectoryName(bowerPath), "bower_components" + _appHost.ApplicationVersion); - //Directory.Move(bowerPath, versionedBowerPath); - //bowerPath = versionedBowerPath; - } + GetDeployIgnoreExtensions().ForEach(i => DeleteFilesByExtension(bowerPath, i)); - DeleteFilesByExtension(bowerPath, ".log"); - DeleteFilesByExtension(bowerPath, ".txt"); - DeleteFilesByExtension(bowerPath, ".map"); - DeleteFilesByExtension(bowerPath, ".md"); DeleteFilesByExtension(bowerPath, ".json", "strings\\"); - DeleteFilesByExtension(bowerPath, ".gz"); - DeleteFilesByExtension(bowerPath, ".bat"); - DeleteFilesByExtension(bowerPath, ".sh"); - 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"); + + GetDeployIgnoreFilenames().ForEach(i => DeleteFilesByName(bowerPath, i.Item1, i.Item2)); + DeleteFoldersByName(bowerPath, "demo"); DeleteFoldersByName(bowerPath, "test"); DeleteFoldersByName(bowerPath, "guides"); @@ -349,8 +396,6 @@ namespace MediaBrowser.WebDashboard.Api } _fileSystem.DeleteDirectory(Path.Combine(bowerPath, "jquery", "src"), true); - //_fileSystem.DeleteDirectory(Path.Combine(bowerPath, "fingerprintjs2", "flash"), true); - //_fileSystem.DeleteDirectory(Path.Combine(bowerPath, "fingerprintjs2", "specs"), true); DeleteCryptoFiles(Path.Combine(bowerPath, "cryptojslib", "components")); @@ -359,13 +404,11 @@ namespace MediaBrowser.WebDashboard.Api //DeleteFoldersByName(Path.Combine(bowerPath, "Sortable"), "meteor"); //DeleteFoldersByName(Path.Combine(bowerPath, "Sortable"), "st"); //DeleteFoldersByName(Path.Combine(bowerPath, "Swiper"), "src"); - + if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase)) { // 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.DeleteFile(Path.Combine(path, "thirdparty", "jquerymobile-1.4.5", "jquery.mobile-1.4.5.min.map")); } else { |
