From d801621cfc902f1c65f3da8d466d625e1d7630b1 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 24 Jul 2020 17:22:32 -0600 Subject: [PATCH 1/3] Fix request parameters --- .../Controllers/LibraryStructureController.cs | 21 +++++---------- .../LibraryStructureDto/MediaPathDto.cs | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index d3537a7a70..88ae752aed 100644 --- a/Jellyfin.Api/Controllers/LibraryStructureController.cs +++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Jellyfin.Api.Constants; +using Jellyfin.Api.Models.LibraryStructureDto; using MediaBrowser.Common.Progress; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; @@ -16,6 +17,7 @@ using MediaBrowser.Model.Entities; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Jellyfin.Api.Controllers { @@ -74,7 +76,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? name, [FromQuery] string? collectionType, [FromQuery] string[] paths, - [FromQuery] LibraryOptions? libraryOptions, + [FromBody] LibraryOptions? libraryOptions, [FromQuery] bool refreshLibrary = false) { libraryOptions ??= new LibraryOptions(); @@ -194,9 +196,7 @@ namespace Jellyfin.Api.Controllers /// /// Add a media path to a library. /// - /// The name of the library. - /// The path to add. - /// The path info. + /// The media path dto. /// Whether to refresh the library. /// A . /// Media path added. @@ -204,23 +204,16 @@ namespace Jellyfin.Api.Controllers [HttpPost("Paths")] [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult AddMediaPath( - [FromQuery] string? name, - [FromQuery] string? path, - [FromQuery] MediaPathInfo? pathInfo, + [FromBody, BindRequired] MediaPathDto mediaPathDto, [FromQuery] bool refreshLibrary = false) { - if (string.IsNullOrWhiteSpace(name)) - { - throw new ArgumentNullException(nameof(name)); - } - _libraryMonitor.Stop(); try { - var mediaPath = pathInfo ?? new MediaPathInfo { Path = path }; + var mediaPath = mediaPathDto.PathInfo ?? new MediaPathInfo { Path = mediaPathDto.Path }; - _libraryManager.AddMediaPath(name, mediaPath); + _libraryManager.AddMediaPath(mediaPathDto.Name, mediaPath); } finally { diff --git a/Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs b/Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs new file mode 100644 index 0000000000..f659882595 --- /dev/null +++ b/Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; +using MediaBrowser.Model.Configuration; + +namespace Jellyfin.Api.Models.LibraryStructureDto +{ + /// + /// Media Path dto. + /// + public class MediaPathDto + { + /// + /// Gets or sets the name of the library. + /// + [Required] + public string? Name { get; set; } + + /// + /// Gets or sets the path to add. + /// + public string? Path { get; set; } + + /// + /// Gets or sets the path info. + /// + public MediaPathInfo? PathInfo { get; set; } + } +} \ No newline at end of file From 5924a81eebe8712bf140dd663272cc2aa23849b9 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 24 Jul 2020 17:31:11 -0600 Subject: [PATCH 2/3] Fix request parameters --- .../LibraryStructureDto/LibraryOptionsDto.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs diff --git a/Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs b/Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs new file mode 100644 index 0000000000..a13cb90dbe --- /dev/null +++ b/Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs @@ -0,0 +1,15 @@ +using MediaBrowser.Model.Configuration; + +namespace Jellyfin.Api.Models.LibraryStructureDto +{ + /// + /// Library options dto. + /// + public class LibraryOptionsDto + { + /// + /// Gets or sets library options. + /// + public LibraryOptions? LibraryOptions { get; set; } + } +} \ No newline at end of file From 259b5d7f0a051cb835839a90f7d9fd223cc12456 Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 24 Jul 2020 17:46:17 -0600 Subject: [PATCH 3/3] Fix request parameters --- Jellyfin.Api/Controllers/LibraryStructureController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index 88ae752aed..b7f3c9b07c 100644 --- a/Jellyfin.Api/Controllers/LibraryStructureController.cs +++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs @@ -66,7 +66,7 @@ namespace Jellyfin.Api.Controllers /// The name of the virtual folder. /// The type of the collection. /// The paths of the virtual folder. - /// The library options. + /// The library options. /// Whether to refresh the library. /// Folder added. /// A . @@ -76,10 +76,10 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? name, [FromQuery] string? collectionType, [FromQuery] string[] paths, - [FromBody] LibraryOptions? libraryOptions, + [FromBody] LibraryOptionsDto? libraryOptionsDto, [FromQuery] bool refreshLibrary = false) { - libraryOptions ??= new LibraryOptions(); + var libraryOptions = libraryOptionsDto?.LibraryOptions ?? new LibraryOptions(); if (paths != null && paths.Length > 0) {