The Free Software Media System - Server Backend & API
lazy load scripts
Luke Pulverentic8a38c139f2d
diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.csindex 1d792fbc16..5ef8b09871 100644--- a/MediaBrowser.Api/PackageService.cs+++ b/MediaBrowser.Api/PackageService.cs@@ -56,6 +56,8 @@ namespace MediaBrowser.Api[ApiMember(Name = "IsAdult", Description = "Optional. Filter by package that contain adult content.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")]public bool? IsAdult { get; set; }++ public bool? IsAppStoreEnabled { get; set; }}/// <summary>@@ -207,6 +209,11 @@ namespace MediaBrowser.Apipackages = packages.Where(p => p.adult == request.IsAdult.Value);}+ if (request.IsAppStoreEnabled.HasValue)+ {+ packages = packages.Where(p => p.enableInAppStore == request.IsAppStoreEnabled.Value);+ }+return ToOptimizedResult(packages.ToList());}diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.csindex 4bd78f1f55..2fbf65f3fd 100644--- a/MediaBrowser.Api/PluginService.cs+++ b/MediaBrowser.Api/PluginService.cs@@ -25,6 +25,7 @@ namespace MediaBrowser.Api[Authenticated]public class GetPlugins : IReturn<List<PluginInfo>>{+ public bool? IsAppStoreEnabled { get; set; }}/// <summary>@@ -181,6 +182,7 @@ namespace MediaBrowser.Apipublic async Task<object> Get(GetPlugins request){var result = _appHost.Plugins.OrderBy(p => p.Name).Select(p => p.GetPluginInfo()).ToList();+ var requireAppStoreEnabled = request.IsAppStoreEnabled.HasValue && request.IsAppStoreEnabled.Value;// Don't fail just on account of image url'stry@@ -197,10 +199,26 @@ namespace MediaBrowser.Apiplugin.ImageUrl = pkg.thumbImage;}}++ if (requireAppStoreEnabled)+ {+ result = result+ .Where(plugin =>+ {+ var pkg = packages.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i.guid) && new Guid(plugin.Id).Equals(new Guid(i.guid)));+ return pkg != null && pkg.enableInAppStore;++ })+ .ToList();+ }}catch{-+ // Play it safe here+ if (requireAppStoreEnabled)+ {+ result = new List<PluginInfo>();+ }}return ToOptimizedSerializedResultUsingCache(result);diff --git a/MediaBrowser.Model/Updates/PackageInfo.cs b/MediaBrowser.Model/Updates/PackageInfo.csindex 429144f36d..5945f87adb 100644--- a/MediaBrowser.Model/Updates/PackageInfo.cs+++ b/MediaBrowser.Model/Updates/PackageInfo.cs@@ -153,6 +153,12 @@ namespace MediaBrowser.Model.Updates/// <value>The versions.</value>public List<PackageVersionInfo> versions { get; set; }+ /// <summary>+ /// Gets or sets a value indicating whether [enable in application store].+ /// </summary>+ /// <value><c>true</c> if [enable in application store]; otherwise, <c>false</c>.</value>+ public bool enableInAppStore { get; set; }+/// <summary>/// Initializes a new instance of the <see cref="PackageInfo"/> class./// </summary>diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.csindex 6639494592..07d9ed4979 100644--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs@@ -295,6 +295,14 @@ namespace MediaBrowser.WebDashboard.Apivar mode = request.Mode;+ if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))+ {+ // Overwrite certain files with cordova specific versions+ var cordovaVersion = Path.Combine(path, "thirdparty", "cordova", "registrationservices.js");+ File.Copy(cordovaVersion, Path.Combine(path, "scripts", "registrationservices.js"), true);+ File.Delete(cordovaVersion);+ }+await DumpHtml(creator.DashboardUIPath, path, mode, culture, appVersion);await DumpJs(creator.DashboardUIPath, path, mode, culture, appVersion);diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.csindex f058b421d2..52f96e371e 100644--- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs+++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs@@ -38,17 +38,17 @@ namespace MediaBrowser.WebDashboard.Apistring appVersion,bool enableMinification){- var isHtml = IsHtml(path);-Stream resourceStream;if (path.Equals("scripts/all.js", StringComparison.OrdinalIgnoreCase)){resourceStream = await GetAllJavascript(mode, localizationCulture, appVersion, enableMinification).ConfigureAwait(false);+ enableMinification = false;}else if (path.Equals("css/all.css", StringComparison.OrdinalIgnoreCase)){resourceStream = await GetAllCss(enableMinification).ConfigureAwait(false);+ enableMinification = false;}else{@@ -59,7 +59,7 @@ namespace MediaBrowser.WebDashboard.Api{// Don't apply any caching for html pages// jQuery ajax doesn't seem to handle if-modified-since correctly- if (isHtml && path.IndexOf("cordovaindex.html", StringComparison.OrdinalIgnoreCase) == -1)+ if (IsHtml(path) && path.IndexOf("cordovaindex.html", StringComparison.OrdinalIgnoreCase) == -1){resourceStream = await ModifyHtml(resourceStream, mode, localizationCulture, enableMinification).ConfigureAwait(false);}@@ -115,6 +115,86 @@ namespace MediaBrowser.WebDashboard.Apireturn fullPath;}+ public async Task<Stream> ModifyCss(Stream sourceStream, bool enableMinification)+ {+ using (sourceStream)+ {+ string content;++ using (var memoryStream = new MemoryStream())+ {+ await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false);++ content = Encoding.UTF8.GetString(memoryStream.ToArray());++ if (enableMinification)+ {+ try+ {+ var result = new KristensenCssMinifier().Minify(content, false, Encoding.UTF8);++ if (result.Errors.Count > 0)+ {+ _logger.Error("Error minifying css: " + result.Errors[0].Message);+ }+ else+ {+ content = result.MinifiedContent;+ }+ }+ catch (Exception ex)+ {+ _logger.ErrorException("Error minifying css", ex);+ }+ }+ }++ var bytes = Encoding.UTF8.GetBytes(content);++ return new MemoryStream(bytes);+ }+ }++ public async Task<Stream> ModifyJs(Stream sourceStream, bool enableMinification)+ {+ using (sourceStream)+ {+ string content;++ using (var memoryStream = new MemoryStream())+ {+ await sourceStream.CopyToAsync(memoryStream).ConfigureAwait(false);++ content = Encoding.UTF8.GetString(memoryStream.ToArray());++ if (enableMinification)+ {+ try+ {+ var result = new CrockfordJsMinifier().Minify(content, false, Encoding.UTF8);++ if (result.Errors.Count > 0)+ {+ _logger.Error("Error minifying javascript: " + result.Errors[0].Message);+ }+ else+ {+ content = result.MinifiedContent;+ }+ }+ catch (Exception ex)+ {+ _logger.ErrorException("Error minifying javascript", ex);+ }+ }+ }++ var bytes = Encoding.UTF8.GetBytes(content);++ return new MemoryStream(bytes);+ }+ }+/// <summary>/// Modifies the HTML by adding common meta tags, css and js./// </summary>@@ -135,6 +215,11 @@ namespace MediaBrowser.WebDashboard.Apihtml = Encoding.UTF8.GetString(memoryStream.ToArray());+ if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))+ {+ html = ModifyForCordova(html);+ }+if (!string.IsNullOrWhiteSpace(localizationCulture)){var lang = localizationCulture.Split('-').FirstOrDefault();@@ -182,6 +267,22 @@ namespace MediaBrowser.WebDashboard.Api}}+ private string ModifyForCordova(string html)+ {+ // Strip everything between CORDOVA_EXCLUDE_START and CORDOVA_EXCLUDE_END+ html = ReplaceBetween(html, "CORDOVA_EXCLUDE_START", "CORDOVA_EXCLUDE_END", string.Empty);++ // Replace CORDOVA_REPLACE_SUPPORTER_SUBMIT_START+ html = ReplaceBetween(html, "CORDOVA_REPLACE_SUPPORTER_SUBMIT_START", "CORDOVA_REPLACE_SUPPORTER_SUBMIT_END", "<i class=\"fa fa-check\"></i><span>${ButtonDonate}</span>");++ return html;+ }++ private string ReplaceBetween(string html, string startToken, string endToken, string newHtml)+ {+ return html;+ }+private string GetLocalizationToken(string phrase){return "${" + phrase + "}";@@ -293,7 +394,14 @@ namespace MediaBrowser.WebDashboard.Apiawait AppendResource(memoryStream, "thirdparty/jquery.unveil-custom.js", newLineBytes).ConfigureAwait(false);- await AppendLocalization(memoryStream, culture).ConfigureAwait(false);+ var excludePhrases = new List<string>();++ if (string.Equals(mode, "cordova", StringComparison.OrdinalIgnoreCase))+ {+ excludePhrases.Add("paypal");+ }++ await AppendLocalization(memoryStream, culture, excludePhrases).ConfigureAwait(false);await memoryStream.WriteAsync(newLineBytes, 0, newLineBytes.Length).ConfigureAwait(false);if (!string.IsNullOrWhiteSpace(mode))@@ -424,13 +532,11 @@ namespace MediaBrowser.WebDashboard.Api"taskbutton.js","ratingdialog.js",- "aboutpage.js","alphapicker.js","addpluginpage.js","metadataadvanced.js","autoorganizetv.js","autoorganizelog.js",- "channels.js","channelslatest.js","channelitems.js","channelsettings.js",@@ -489,10 +595,6 @@ namespace MediaBrowser.WebDashboard.Api"moviepeople.js","moviestudios.js","movietrailers.js",- "musicalbums.js",- "musicalbumartists.js",- "musicartists.js",- "musicrecommended.js","mypreferencesdisplay.js","mypreferenceslanguages.js",@@ -538,9 +640,29 @@ namespace MediaBrowser.WebDashboard.Api};}- private async Task AppendLocalization(Stream stream, string culture)+ private async Task AppendLocalization(Stream stream, string culture, List<string> excludePhrases){- var js = "window.localizationGlossary=" + _jsonSerializer.SerializeToString(_localization.GetJavaScriptLocalizationDictionary(culture));+ var dictionary = _localization.GetJavaScriptLocalizationDictionary(culture);++ if (excludePhrases.Count > 0)+ {+ var removes = new List<string>();++ foreach (var pair in dictionary)+ {+ if (excludePhrases.Any(i => pair.Key.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1 || pair.Value.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))+ {+ removes.Add(pair.Key);+ }+ }++ foreach (var remove in removes)+ {+ dictionary.Remove(remove);+ }+ }++ var js = "window.localizationGlossary=" + _jsonSerializer.SerializeToString(dictionary);var bytes = Encoding.UTF8.GetBytes(js);await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csprojindex b45b3dc3a2..8d52f178fa 100644--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj@@ -156,6 +156,9 @@<Content Include="dashboard-ui\scripts\photos.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\scripts\registrationservices.js">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\scripts\reports.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>@@ -222,6 +225,9 @@<Content Include="dashboard-ui\thirdparty\cordova\imagestore.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\thirdparty\cordova\registrationservices.js">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\thirdparty\cordova\remotecontrols.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>