diff options
| author | Patrick Barron <18354464+barronpm@users.noreply.github.com> | 2020-07-26 16:09:31 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-26 16:09:31 +0000 |
| commit | 6015ceb731c204e7b0c2d7c69440f984558848d2 (patch) | |
| tree | 1de14d0d19b6027fa350e5157117d75e2d36889f | |
| parent | 44acb9f7d92920d26590dbac6757aef8537da736 (diff) | |
| parent | 259b5d7f0a051cb835839a90f7d9fd223cc12456 (diff) | |
Merge pull request #3693 from crobibero/api-library
Fix LibraryStructure API parameters
3 files changed, 51 insertions, 16 deletions
diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index d3537a7a7..b7f3c9b07 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 { @@ -64,7 +66,7 @@ namespace Jellyfin.Api.Controllers /// <param name="name">The name of the virtual folder.</param> /// <param name="collectionType">The type of the collection.</param> /// <param name="paths">The paths of the virtual folder.</param> - /// <param name="libraryOptions">The library options.</param> + /// <param name="libraryOptionsDto">The library options.</param> /// <param name="refreshLibrary">Whether to refresh the library.</param> /// <response code="204">Folder added.</response> /// <returns>A <see cref="NoContentResult"/>.</returns> @@ -74,10 +76,10 @@ namespace Jellyfin.Api.Controllers [FromQuery] string? name, [FromQuery] string? collectionType, [FromQuery] string[] paths, - [FromQuery] LibraryOptions? libraryOptions, + [FromBody] LibraryOptionsDto? libraryOptionsDto, [FromQuery] bool refreshLibrary = false) { - libraryOptions ??= new LibraryOptions(); + var libraryOptions = libraryOptionsDto?.LibraryOptions ?? new LibraryOptions(); if (paths != null && paths.Length > 0) { @@ -194,9 +196,7 @@ namespace Jellyfin.Api.Controllers /// <summary> /// Add a media path to a library. /// </summary> - /// <param name="name">The name of the library.</param> - /// <param name="path">The path to add.</param> - /// <param name="pathInfo">The path info.</param> + /// <param name="mediaPathDto">The media path dto.</param> /// <param name="refreshLibrary">Whether to refresh the library.</param> /// <returns>A <see cref="NoContentResult"/>.</returns> /// <response code="204">Media path added.</response> @@ -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/LibraryOptionsDto.cs b/Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs new file mode 100644 index 000000000..a13cb90db --- /dev/null +++ b/Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs @@ -0,0 +1,15 @@ +using MediaBrowser.Model.Configuration; + +namespace Jellyfin.Api.Models.LibraryStructureDto +{ + /// <summary> + /// Library options dto. + /// </summary> + public class LibraryOptionsDto + { + /// <summary> + /// Gets or sets library options. + /// </summary> + public LibraryOptions? LibraryOptions { get; set; } + } +}
\ No newline at end of file diff --git a/Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs b/Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs new file mode 100644 index 000000000..f65988259 --- /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 +{ + /// <summary> + /// Media Path dto. + /// </summary> + public class MediaPathDto + { + /// <summary> + /// Gets or sets the name of the library. + /// </summary> + [Required] + public string? Name { get; set; } + + /// <summary> + /// Gets or sets the path to add. + /// </summary> + public string? Path { get; set; } + + /// <summary> + /// Gets or sets the path info. + /// </summary> + public MediaPathInfo? PathInfo { get; set; } + } +}
\ No newline at end of file |
