BrandingController.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Model.Branding;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.AspNetCore.Mvc;
  6. namespace Jellyfin.Api.Controllers;
  7. /// <summary>
  8. /// Branding controller.
  9. /// </summary>
  10. public class BrandingController : BaseJellyfinApiController
  11. {
  12. private readonly IServerConfigurationManager _serverConfigurationManager;
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="BrandingController"/> class.
  15. /// </summary>
  16. /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
  17. public BrandingController(IServerConfigurationManager serverConfigurationManager)
  18. {
  19. _serverConfigurationManager = serverConfigurationManager;
  20. }
  21. /// <summary>
  22. /// Gets branding configuration.
  23. /// </summary>
  24. /// <response code="200">Branding configuration returned.</response>
  25. /// <returns>An <see cref="OkResult"/> containing the branding configuration.</returns>
  26. [HttpGet("Configuration")]
  27. [ProducesResponseType(StatusCodes.Status200OK)]
  28. public ActionResult<BrandingOptionsDto> GetBrandingOptions()
  29. {
  30. var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
  31. var brandingOptionsDto = new BrandingOptionsDto
  32. {
  33. LoginDisclaimer = brandingOptions.LoginDisclaimer,
  34. CustomCss = brandingOptions.CustomCss,
  35. SplashscreenEnabled = brandingOptions.SplashscreenEnabled
  36. };
  37. return brandingOptionsDto;
  38. }
  39. /// <summary>
  40. /// Gets branding css.
  41. /// </summary>
  42. /// <response code="200">Branding css returned.</response>
  43. /// <response code="204">No branding css configured.</response>
  44. /// <returns>
  45. /// An <see cref="OkResult"/> containing the branding css if exist,
  46. /// or a <see cref="NoContentResult"/> if the css is not configured.
  47. /// </returns>
  48. [HttpGet("Css")]
  49. [HttpGet("Css.css", Name = "GetBrandingCss_2")]
  50. [Produces("text/css")]
  51. [ProducesResponseType(StatusCodes.Status200OK)]
  52. [ProducesResponseType(StatusCodes.Status204NoContent)]
  53. public ActionResult<string> GetBrandingCss()
  54. {
  55. var options = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
  56. return options.CustomCss ?? string.Empty;
  57. }
  58. }