BrandingController.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. {
  8. /// <summary>
  9. /// Branding controller.
  10. /// </summary>
  11. public class BrandingController : BaseJellyfinApiController
  12. {
  13. private readonly IServerConfigurationManager _serverConfigurationManager;
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="BrandingController"/> class.
  16. /// </summary>
  17. /// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
  18. public BrandingController(IServerConfigurationManager serverConfigurationManager)
  19. {
  20. _serverConfigurationManager = serverConfigurationManager;
  21. }
  22. /// <summary>
  23. /// Gets branding configuration.
  24. /// </summary>
  25. /// <response code="200">Branding configuration returned.</response>
  26. /// <returns>An <see cref="OkResult"/> containing the branding configuration.</returns>
  27. [HttpGet("Configuration")]
  28. [ProducesResponseType(StatusCodes.Status200OK)]
  29. public ActionResult<BrandingOptions> GetBrandingOptions()
  30. {
  31. return _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
  32. }
  33. /// <summary>
  34. /// Gets branding css.
  35. /// </summary>
  36. /// <response code="200">Branding css returned.</response>
  37. /// <response code="204">No branding css configured.</response>
  38. /// <returns>
  39. /// An <see cref="OkResult"/> containing the branding css if exist,
  40. /// or a <see cref="NoContentResult"/> if the css is not configured.
  41. /// </returns>
  42. [HttpGet("Css")]
  43. [HttpGet("Css.css")]
  44. [Produces("text/css")]
  45. [ProducesResponseType(StatusCodes.Status200OK)]
  46. [ProducesResponseType(StatusCodes.Status204NoContent)]
  47. public ActionResult<string> GetBrandingCss()
  48. {
  49. var options = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
  50. if (string.IsNullOrEmpty(options.CustomCss))
  51. {
  52. return NoContent();
  53. }
  54. return options.CustomCss;
  55. }
  56. }
  57. }