From a50738e88d3e91bf1c2be02cc0cda89768387990 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 22 Jun 2020 07:37:29 -0600 Subject: [PATCH 1/4] move BrandingService.cs to Jellyfin.Api --- .../Controllers/BrandingController.cs | 62 +++++++++++++++++++ .../Properties/launchSettings.json | 3 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 Jellyfin.Api/Controllers/BrandingController.cs diff --git a/Jellyfin.Api/Controllers/BrandingController.cs b/Jellyfin.Api/Controllers/BrandingController.cs new file mode 100644 index 0000000000..d580fedffd --- /dev/null +++ b/Jellyfin.Api/Controllers/BrandingController.cs @@ -0,0 +1,62 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Model.Branding; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Controllers +{ + /// + /// Branding controller. + /// + public class BrandingController : BaseJellyfinApiController + { + private readonly IServerConfigurationManager _serverConfigurationManager; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + public BrandingController(IServerConfigurationManager serverConfigurationManager) + { + _serverConfigurationManager = serverConfigurationManager; + } + + /// + /// Gets branding configuration. + /// + /// Branding configuration returned. + /// An containing the branding configuration. + [HttpGet("Configuration")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult GetBrandingOptions() + { + return _serverConfigurationManager.GetConfiguration("branding"); + } + + /// + /// Gets branding css. + /// + /// Branding css returned. + /// No branding css configured. + /// + /// An containing the branding css if exist, + /// or a if the css is not configured. + /// + [HttpGet("Css")] + [HttpGet("Css.css")] + [Produces("text/css")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult GetBrandingCss() + { + var options = _serverConfigurationManager.GetConfiguration("branding"); + if (string.IsNullOrEmpty(options.CustomCss)) + { + return NoContent(); + } + + return options.CustomCss; + } + } +} diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index b6e2bcf976..a716387091 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -4,7 +4,8 @@ "commandName": "Project", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "commandLineArgs": "--webdir C:\\Users\\Cody\\Code\\Jellyfin\\tmp\\jf-web-wizard\\dist" }, "Jellyfin.Server (nowebclient)": { "commandName": "Project", From 263d925e4fb5faa56f33120f2b09f6254c3ddc92 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Mon, 22 Jun 2020 07:46:47 -0600 Subject: [PATCH 2/4] Update launchSettings.json --- Jellyfin.Server/Properties/launchSettings.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jellyfin.Server/Properties/launchSettings.json b/Jellyfin.Server/Properties/launchSettings.json index a716387091..b6e2bcf976 100644 --- a/Jellyfin.Server/Properties/launchSettings.json +++ b/Jellyfin.Server/Properties/launchSettings.json @@ -4,8 +4,7 @@ "commandName": "Project", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "commandLineArgs": "--webdir C:\\Users\\Cody\\Code\\Jellyfin\\tmp\\jf-web-wizard\\dist" + } }, "Jellyfin.Server (nowebclient)": { "commandName": "Project", From 0fa316c9e4c1156b1ed4a37b4ade204aa4f8a392 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 22 Jun 2020 07:47:13 -0600 Subject: [PATCH 3/4] move BrandingService.cs to Jellyfin.Api --- MediaBrowser.Api/BrandingService.cs | 44 ----------------------------- 1 file changed, 44 deletions(-) delete mode 100644 MediaBrowser.Api/BrandingService.cs diff --git a/MediaBrowser.Api/BrandingService.cs b/MediaBrowser.Api/BrandingService.cs deleted file mode 100644 index f4724e7745..0000000000 --- a/MediaBrowser.Api/BrandingService.cs +++ /dev/null @@ -1,44 +0,0 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Branding; -using MediaBrowser.Model.Services; -using Microsoft.Extensions.Logging; - -namespace MediaBrowser.Api -{ - [Route("/Branding/Configuration", "GET", Summary = "Gets branding configuration")] - public class GetBrandingOptions : IReturn - { - } - - [Route("/Branding/Css", "GET", Summary = "Gets custom css")] - [Route("/Branding/Css.css", "GET", Summary = "Gets custom css")] - public class GetBrandingCss - { - } - - public class BrandingService : BaseApiService - { - public BrandingService( - ILogger logger, - IServerConfigurationManager serverConfigurationManager, - IHttpResultFactory httpResultFactory) - : base(logger, serverConfigurationManager, httpResultFactory) - { - } - - public object Get(GetBrandingOptions request) - { - return ServerConfigurationManager.GetConfiguration("branding"); - } - - public object Get(GetBrandingCss request) - { - var result = ServerConfigurationManager.GetConfiguration("branding"); - - // When null this throws a 405 error under Mono OSX, so default to empty string - return ResultFactory.GetResult(Request, result.CustomCss ?? string.Empty, "text/css"); - } - } -} From 1d7d480efe52589557bdc6371731fad6d15ee1f6 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 22 Jun 2020 08:14:07 -0600 Subject: [PATCH 4/4] fix tests --- .../Controllers/BrandingController.cs | 7 +---- MediaBrowser.Api/TestService.cs | 26 +++++++++++++++++++ tests/Jellyfin.Api.Tests/GetPathValueTests.cs | 4 +-- .../BrandingServiceTests.cs | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 MediaBrowser.Api/TestService.cs diff --git a/Jellyfin.Api/Controllers/BrandingController.cs b/Jellyfin.Api/Controllers/BrandingController.cs index d580fedffd..67790c0e4a 100644 --- a/Jellyfin.Api/Controllers/BrandingController.cs +++ b/Jellyfin.Api/Controllers/BrandingController.cs @@ -51,12 +51,7 @@ namespace Jellyfin.Api.Controllers public ActionResult GetBrandingCss() { var options = _serverConfigurationManager.GetConfiguration("branding"); - if (string.IsNullOrEmpty(options.CustomCss)) - { - return NoContent(); - } - - return options.CustomCss; + return options.CustomCss ?? string.Empty; } } } diff --git a/MediaBrowser.Api/TestService.cs b/MediaBrowser.Api/TestService.cs new file mode 100644 index 0000000000..6c999e08d1 --- /dev/null +++ b/MediaBrowser.Api/TestService.cs @@ -0,0 +1,26 @@ +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Net; +using Microsoft.Extensions.Logging; + +namespace MediaBrowser.Api +{ + /// + /// Service for testing path value. + /// + public class TestService : BaseApiService + { + /// + /// Test service. + /// + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public TestService( + ILogger logger, + IServerConfigurationManager serverConfigurationManager, + IHttpResultFactory httpResultFactory) + : base(logger, serverConfigurationManager, httpResultFactory) + { + } + } +} diff --git a/tests/Jellyfin.Api.Tests/GetPathValueTests.cs b/tests/Jellyfin.Api.Tests/GetPathValueTests.cs index b01d1af1f0..397eb2edc3 100644 --- a/tests/Jellyfin.Api.Tests/GetPathValueTests.cs +++ b/tests/Jellyfin.Api.Tests/GetPathValueTests.cs @@ -31,8 +31,8 @@ namespace Jellyfin.Api.Tests var confManagerMock = Mock.Of(x => x.Configuration == conf); - var service = new BrandingService( - new NullLogger(), + var service = new TestService( + new NullLogger(), confManagerMock, Mock.Of()) { diff --git a/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs b/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs index 34698fe251..5d7f7765cd 100644 --- a/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs +++ b/tests/MediaBrowser.Api.Tests/BrandingServiceTests.cs @@ -43,7 +43,7 @@ namespace MediaBrowser.Api.Tests // Assert response.EnsureSuccessStatusCode(); - Assert.Equal("text/css", response.Content.Headers.ContentType.ToString()); + Assert.Equal("text/css; charset=utf-8", response.Content.Headers.ContentType.ToString()); } } }