Browse Source

Fix splashscreen (#7895)

Cody Robibero 3 years ago
parent
commit
bee13d5644

+ 36 - 1
Jellyfin.Api/Controllers/ImageController.cs

@@ -1724,6 +1724,11 @@ namespace Jellyfin.Api.Controllers
             [FromQuery, Range(0, 100)] int quality = 90)
             [FromQuery, Range(0, 100)] int quality = 90)
         {
         {
             var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
             var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
+            if (!brandingOptions.SplashscreenEnabled)
+            {
+                return NotFound();
+            }
+
             string splashscreenPath;
             string splashscreenPath;
 
 
             if (!string.IsNullOrWhiteSpace(brandingOptions.SplashscreenLocation)
             if (!string.IsNullOrWhiteSpace(brandingOptions.SplashscreenLocation)
@@ -1776,6 +1781,7 @@ namespace Jellyfin.Api.Controllers
 
 
         /// <summary>
         /// <summary>
         /// Uploads a custom splashscreen.
         /// Uploads a custom splashscreen.
+        /// The body is expected to the image contents base64 encoded.
         /// </summary>
         /// </summary>
         /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
         /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
         /// <response code="204">Successfully uploaded new splashscreen.</response>
         /// <response code="204">Successfully uploaded new splashscreen.</response>
@@ -1799,7 +1805,13 @@ namespace Jellyfin.Api.Controllers
                 return BadRequest("Error reading mimetype from uploaded image");
                 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<BrandingOptions>("branding");
             var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("branding");
             brandingOptions.SplashscreenLocation = filePath;
             brandingOptions.SplashscreenLocation = filePath;
             _serverConfigurationManager.SaveConfiguration("branding", brandingOptions);
             _serverConfigurationManager.SaveConfiguration("branding", brandingOptions);
@@ -1812,6 +1824,29 @@ namespace Jellyfin.Api.Controllers
             return NoContent();
             return NoContent();
         }
         }
 
 
+        /// <summary>
+        /// Delete a custom splashscreen.
+        /// </summary>
+        /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
+        /// <response code="204">Successfully deleted the custom splashscreen.</response>
+        /// <response code="403">User does not have permission to delete splashscreen..</response>
+        [HttpDelete("Branding/Splashscreen")]
+        [Authorize(Policy = Policies.RequiresElevation)]
+        [ProducesResponseType(StatusCodes.Status204NoContent)]
+        public ActionResult DeleteCustomSplashscreen()
+        {
+            var brandingOptions = _serverConfigurationManager.GetConfiguration<BrandingOptions>("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<MemoryStream> GetMemoryStream(Stream inputStream)
         private static async Task<MemoryStream> GetMemoryStream(Stream inputStream)
         {
         {
             using var reader = new StreamReader(inputStream);
             using var reader = new StreamReader(inputStream);

+ 5 - 0
MediaBrowser.Model/Branding/BrandingOptions.cs

@@ -20,6 +20,11 @@ public class BrandingOptions
     /// <value>The custom CSS.</value>
     /// <value>The custom CSS.</value>
     public string? CustomCss { get; set; }
     public string? CustomCss { get; set; }
 
 
+    /// <summary>
+    /// Gets or sets a value indicating whether to enable the splashscreen.
+    /// </summary>
+    public bool SplashscreenEnabled { get; set; } = true;
+
     /// <summary>
     /// <summary>
     /// Gets or sets the splashscreen location on disk.
     /// Gets or sets the splashscreen location on disk.
     /// </summary>
     /// </summary>