From fb51f1e6f012f0832e089b94a075b20089fed555 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 28 Feb 2014 00:22:36 -0500 Subject: [PATCH] refined app themes --- MediaBrowser.Api/AppThemeService.cs | 22 +++++++++---------- MediaBrowser.Api/Images/ImageService.cs | 9 ++++---- MediaBrowser.Model/Themes/AppTheme.cs | 4 ++-- .../HttpServer/HttpResultFactory.cs | 19 ++++++++++++---- .../Themes/AppThemeManager.cs | 21 +++++++++++------- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/MediaBrowser.Api/AppThemeService.cs b/MediaBrowser.Api/AppThemeService.cs index d1819cce41..54141b3e22 100644 --- a/MediaBrowser.Api/AppThemeService.cs +++ b/MediaBrowser.Api/AppThemeService.cs @@ -13,16 +13,16 @@ namespace MediaBrowser.Api [Api(Description = "Gets a list of available themes for an app")] public class GetAppThemes : IReturn> { - [ApiMember(Name = "ApplicationName", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] - public string ApplicationName { get; set; } + [ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string App { get; set; } } [Route("/Themes/Info", "GET")] [Api(Description = "Gets an app theme")] public class GetAppTheme : IReturn { - [ApiMember(Name = "ApplicationName", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] - public string ApplicationName { get; set; } + [ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string App { get; set; } [ApiMember(Name = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string Name { get; set; } @@ -32,11 +32,11 @@ namespace MediaBrowser.Api [Api(Description = "Gets an app theme")] public class GetAppThemeImage { - [ApiMember(Name = "ApplicationName", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] - public string ApplicationName { get; set; } + [ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string App { get; set; } - [ApiMember(Name = "ThemeName", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] - public string ThemeName { get; set; } + [ApiMember(Name = "Theme", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public string Theme { get; set; } [ApiMember(Name = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public string Name { get; set; } @@ -64,14 +64,14 @@ namespace MediaBrowser.Api public object Get(GetAppThemes request) { - var result = _themeManager.GetThemes(request.ApplicationName).ToList(); + var result = _themeManager.GetThemes(request.App).ToList(); return ToOptimizedResult(result); } public object Get(GetAppTheme request) { - var result = _themeManager.GetTheme(request.ApplicationName, request.Name); + var result = _themeManager.GetTheme(request.App, request.Name); return ToOptimizedResult(result); } @@ -83,7 +83,7 @@ namespace MediaBrowser.Api public object Get(GetAppThemeImage request) { - var info = _themeManager.GetImageImageInfo(request.ApplicationName, request.ThemeName, request.Name); + var info = _themeManager.GetImageImageInfo(request.App, request.Theme, request.Name); var cacheGuid = new Guid(info.CacheTag); diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index daa52f5a01..2cdaef1ed8 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -707,10 +707,11 @@ namespace MediaBrowser.Api.Images var currentItem = item; var currentRequest = request; - var responseHeaders = new Dictionary(); - - responseHeaders.Add("transferMode.dlna.org", "Interactive"); - responseHeaders.Add("realTimeInfo.dlna.org", "DLNA.ORG_TLAG=*"); + var responseHeaders = new Dictionary + { + {"transferMode.dlna.org", "Interactive"}, + {"realTimeInfo.dlna.org", "DLNA.ORG_TLAG=*"} + }; return ToCachedResult(cacheGuid, originalFileImageDateModified, cacheDuration, () => new ImageWriter { diff --git a/MediaBrowser.Model/Themes/AppTheme.cs b/MediaBrowser.Model/Themes/AppTheme.cs index a0532854dc..a814fec336 100644 --- a/MediaBrowser.Model/Themes/AppTheme.cs +++ b/MediaBrowser.Model/Themes/AppTheme.cs @@ -5,7 +5,7 @@ namespace MediaBrowser.Model.Themes { public class AppTheme { - public string ApplicationName { get; set; } + public string AppName { get; set; } public string Name { get; set; } @@ -23,7 +23,7 @@ namespace MediaBrowser.Model.Themes public class AppThemeInfo { - public string ApplicationName { get; set; } + public string AppName { get; set; } public string Name { get; set; } } diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 4c21d2eb7a..8455d9f581 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -238,8 +238,19 @@ namespace MediaBrowser.Server.Implementations.HttpServer return hasOptions; } - // Otherwise wrap into an HttpResult - var httpResult = new HttpResult(result, contentType ?? "text/html", HttpStatusCode.NotModified); + IHasOptions httpResult; + + var stream = result as Stream; + + if (stream != null) + { + httpResult = new StreamWriter(stream, contentType, _logger); + } + else + { + // Otherwise wrap into an HttpResult + httpResult = new HttpResult(result, contentType ?? "text/html", HttpStatusCode.NotModified); + } AddResponseHeaders(httpResult, responseHeaders); @@ -478,7 +489,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (!SupportsCompression) { responseHeaders["Content-Length"] = originalContentLength.ToString(UsCulture); - + if (isHeadRequest) { return GetHttpResult(new byte[] { }, contentType); @@ -495,7 +506,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer { return GetHttpResult(new byte[] { }, contentType); } - + return new CompressedResult(contents, requestedCompressionType, contentType); } diff --git a/MediaBrowser.Server.Implementations/Themes/AppThemeManager.cs b/MediaBrowser.Server.Implementations/Themes/AppThemeManager.cs index ca792bcd34..9845f38674 100644 --- a/MediaBrowser.Server.Implementations/Themes/AppThemeManager.cs +++ b/MediaBrowser.Server.Implementations/Themes/AppThemeManager.cs @@ -63,6 +63,11 @@ namespace MediaBrowser.Server.Implementations.Themes return Path.Combine(GetThemesPath(applicationName), name); } + private string GetImagesPath(string applicationName, string themeName) + { + return Path.Combine(GetThemePath(applicationName, themeName), "images"); + } + public IEnumerable GetThemes(string applicationName) { var path = GetThemesPath(applicationName); @@ -97,9 +102,11 @@ namespace MediaBrowser.Server.Implementations.Themes var themePath = GetThemePath(applicationName, name); var file = Path.Combine(themePath, "theme.json"); + var imagesPath = GetImagesPath(applicationName, name); + var theme = _json.DeserializeFromFile(file); - theme.Images = new DirectoryInfo(themePath) + theme.Images = new DirectoryInfo(imagesPath) .EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(i => _supportedImageExtensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase)) .Select(GetThemeImage) @@ -123,7 +130,7 @@ namespace MediaBrowser.Server.Implementations.Themes public void SaveTheme(AppTheme theme) { - var themePath = GetThemePath(theme.ApplicationName, theme.Name); + var themePath = GetThemePath(theme.AppName, theme.Name); var file = Path.Combine(themePath, "theme.json"); Directory.CreateDirectory(themePath); @@ -131,7 +138,7 @@ namespace MediaBrowser.Server.Implementations.Themes // Clone it so that we don't serialize all the images - they're always dynamic var clone = new AppTheme { - ApplicationName = theme.ApplicationName, + AppName = theme.AppName, Name = theme.Name, Options = theme.Options, Images = null @@ -142,12 +149,10 @@ namespace MediaBrowser.Server.Implementations.Themes public InternalThemeImage GetImageImageInfo(string applicationName, string themeName, string imageName) { - var themePath = GetThemePath(applicationName, themeName); - - var fullPath = Path.Combine(themePath, imageName); + var imagesPath = GetImagesPath(applicationName, themeName); - var file = new DirectoryInfo(themePath).EnumerateFiles("*", SearchOption.TopDirectoryOnly) - .First(i => string.Equals(i.FullName, fullPath, StringComparison.OrdinalIgnoreCase)); + var file = new DirectoryInfo(imagesPath).EnumerateFiles("*", SearchOption.TopDirectoryOnly) + .First(i => string.Equals(i.Name, imageName, StringComparison.OrdinalIgnoreCase)); var themeImage = GetThemeImage(file);