From bee13d56446d8fb3cb158b389f1eb7ed6fe501aa Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Tue, 14 Jun 2022 08:18:35 -0600 Subject: [PATCH] Fix splashscreen (#7895) --- Jellyfin.Api/Controllers/ImageController.cs | 37 ++++++++++++++++++- .../Branding/BrandingOptions.cs | 5 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.cs index 05d80ba35d..6c7842c7b9 100644 --- a/Jellyfin.Api/Controllers/ImageController.cs +++ b/Jellyfin.Api/Controllers/ImageController.cs @@ -1724,6 +1724,11 @@ namespace Jellyfin.Api.Controllers [FromQuery, Range(0, 100)] int quality = 90) { var brandingOptions = _serverConfigurationManager.GetConfiguration("branding"); + if (!brandingOptions.SplashscreenEnabled) + { + return NotFound(); + } + string splashscreenPath; if (!string.IsNullOrWhiteSpace(brandingOptions.SplashscreenLocation) @@ -1776,6 +1781,7 @@ namespace Jellyfin.Api.Controllers /// /// Uploads a custom splashscreen. + /// The body is expected to the image contents base64 encoded. /// /// A indicating success. /// Successfully uploaded new splashscreen. @@ -1799,7 +1805,13 @@ namespace Jellyfin.Api.Controllers return BadRequest("Error reading mimetype from uploaded image"); } - var filePath = Path.Combine(_appPaths.DataPath, "splashscreen-upload" + MimeTypes.ToExtension(mimeType.Value)); + var extension = MimeTypes.ToExtension(mimeType.Value); + if (string.IsNullOrEmpty(extension)) + { + return BadRequest("Error converting mimetype to an image extension"); + } + + var filePath = Path.Combine(_appPaths.DataPath, "splashscreen-upload" + extension); var brandingOptions = _serverConfigurationManager.GetConfiguration("branding"); brandingOptions.SplashscreenLocation = filePath; _serverConfigurationManager.SaveConfiguration("branding", brandingOptions); @@ -1812,6 +1824,29 @@ namespace Jellyfin.Api.Controllers return NoContent(); } + /// + /// Delete a custom splashscreen. + /// + /// A indicating success. + /// Successfully deleted the custom splashscreen. + /// User does not have permission to delete splashscreen.. + [HttpDelete("Branding/Splashscreen")] + [Authorize(Policy = Policies.RequiresElevation)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public ActionResult DeleteCustomSplashscreen() + { + var brandingOptions = _serverConfigurationManager.GetConfiguration("branding"); + if (!string.IsNullOrEmpty(brandingOptions.SplashscreenLocation) + && System.IO.File.Exists(brandingOptions.SplashscreenLocation)) + { + System.IO.File.Delete(brandingOptions.SplashscreenLocation); + brandingOptions.SplashscreenLocation = null; + _serverConfigurationManager.SaveConfiguration("branding", brandingOptions); + } + + return NoContent(); + } + private static async Task GetMemoryStream(Stream inputStream) { using var reader = new StreamReader(inputStream); diff --git a/MediaBrowser.Model/Branding/BrandingOptions.cs b/MediaBrowser.Model/Branding/BrandingOptions.cs index cc42c1718a..a0adb56ef7 100644 --- a/MediaBrowser.Model/Branding/BrandingOptions.cs +++ b/MediaBrowser.Model/Branding/BrandingOptions.cs @@ -20,6 +20,11 @@ public class BrandingOptions /// The custom CSS. public string? CustomCss { get; set; } + /// + /// Gets or sets a value indicating whether to enable the splashscreen. + /// + public bool SplashscreenEnabled { get; set; } = true; + /// /// Gets or sets the splashscreen location on disk. ///