mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 22:07:13 -04:00
Merge pull request #3419 from crobibero/api-branding
move BrandingService.cs to Jellyfin.Api
This commit is contained in:
commit
68e89be349
57
Jellyfin.Api/Controllers/BrandingController.cs
Normal file
57
Jellyfin.Api/Controllers/BrandingController.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using MediaBrowser.Common.Configuration;
|
||||||
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using MediaBrowser.Model.Branding;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Branding controller.
|
||||||
|
/// </summary>
|
||||||
|
public class BrandingController : BaseJellyfinApiController
|
||||||
|
{
|
||||||
|
private readonly IServerConfigurationManager _serverConfigurationManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="BrandingController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
||||||
|
public BrandingController(IServerConfigurationManager serverConfigurationManager)
|
||||||
|
{
|
||||||
|
_serverConfigurationManager = serverConfigurationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets branding configuration.
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200">Branding configuration returned.</response>
|
||||||
|
/// <returns>An <see cref="OkResult"/> containing the branding configuration.</returns>
|
||||||
|
[HttpGet("Configuration")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public ActionResult<BrandingOptions> GetBrandingOptions()
|
||||||
|
{
|
||||||
|
return _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets branding css.
|
||||||
|
/// </summary>
|
||||||
|
/// <response code="200">Branding css returned.</response>
|
||||||
|
/// <response code="204">No branding css configured.</response>
|
||||||
|
/// <returns>
|
||||||
|
/// An <see cref="OkResult"/> containing the branding css if exist,
|
||||||
|
/// or a <see cref="NoContentResult"/> if the css is not configured.
|
||||||
|
/// </returns>
|
||||||
|
[HttpGet("Css")]
|
||||||
|
[HttpGet("Css.css")]
|
||||||
|
[Produces("text/css")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
public ActionResult<string> GetBrandingCss()
|
||||||
|
{
|
||||||
|
var options = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
|
||||||
|
return options.CustomCss ?? string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<BrandingOptions>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[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<BrandingService> logger,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory)
|
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetBrandingOptions request)
|
|
||||||
{
|
|
||||||
return ServerConfigurationManager.GetConfiguration<BrandingOptions>("branding");
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetBrandingCss request)
|
|
||||||
{
|
|
||||||
var result = ServerConfigurationManager.GetConfiguration<BrandingOptions>("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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
26
MediaBrowser.Api/TestService.cs
Normal file
26
MediaBrowser.Api/TestService.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using MediaBrowser.Controller.Net;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Service for testing path value.
|
||||||
|
/// </summary>
|
||||||
|
public class TestService : BaseApiService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Test service.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logger">Instance of the <see cref="ILogger{TestService}"/> interface.</param>
|
||||||
|
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
||||||
|
/// <param name="httpResultFactory">Instance of the <see cref="IHttpResultFactory"/> interface.</param>
|
||||||
|
public TestService(
|
||||||
|
ILogger<TestService> logger,
|
||||||
|
IServerConfigurationManager serverConfigurationManager,
|
||||||
|
IHttpResultFactory httpResultFactory)
|
||||||
|
: base(logger, serverConfigurationManager, httpResultFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -31,8 +31,8 @@ namespace Jellyfin.Api.Tests
|
|||||||
|
|
||||||
var confManagerMock = Mock.Of<IServerConfigurationManager>(x => x.Configuration == conf);
|
var confManagerMock = Mock.Of<IServerConfigurationManager>(x => x.Configuration == conf);
|
||||||
|
|
||||||
var service = new BrandingService(
|
var service = new TestService(
|
||||||
new NullLogger<BrandingService>(),
|
new NullLogger<TestService>(),
|
||||||
confManagerMock,
|
confManagerMock,
|
||||||
Mock.Of<IHttpResultFactory>())
|
Mock.Of<IHttpResultFactory>())
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ namespace MediaBrowser.Api.Tests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
Assert.Equal("text/css", response.Content.Headers.ContentType.ToString());
|
Assert.Equal("text/css; charset=utf-8", response.Content.Headers.ContentType.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user