mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 03:48:06 +02:00
Merge pull request #3693 from crobibero/api-library
Fix LibraryStructure API parameters
This commit is contained in:
commit
6015ceb731
3 changed files with 51 additions and 16 deletions
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Api.Constants;
|
using Jellyfin.Api.Constants;
|
||||||
|
using Jellyfin.Api.Models.LibraryStructureDto;
|
||||||
using MediaBrowser.Common.Progress;
|
using MediaBrowser.Common.Progress;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
@ -16,6 +17,7 @@ using MediaBrowser.Model.Entities;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
|
||||||
namespace Jellyfin.Api.Controllers
|
namespace Jellyfin.Api.Controllers
|
||||||
{
|
{
|
||||||
|
@ -64,7 +66,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
/// <param name="name">The name of the virtual folder.</param>
|
/// <param name="name">The name of the virtual folder.</param>
|
||||||
/// <param name="collectionType">The type of the collection.</param>
|
/// <param name="collectionType">The type of the collection.</param>
|
||||||
/// <param name="paths">The paths of the virtual folder.</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>
|
/// <param name="refreshLibrary">Whether to refresh the library.</param>
|
||||||
/// <response code="204">Folder added.</response>
|
/// <response code="204">Folder added.</response>
|
||||||
/// <returns>A <see cref="NoContentResult"/>.</returns>
|
/// <returns>A <see cref="NoContentResult"/>.</returns>
|
||||||
|
@ -74,10 +76,10 @@ namespace Jellyfin.Api.Controllers
|
||||||
[FromQuery] string? name,
|
[FromQuery] string? name,
|
||||||
[FromQuery] string? collectionType,
|
[FromQuery] string? collectionType,
|
||||||
[FromQuery] string[] paths,
|
[FromQuery] string[] paths,
|
||||||
[FromQuery] LibraryOptions? libraryOptions,
|
[FromBody] LibraryOptionsDto? libraryOptionsDto,
|
||||||
[FromQuery] bool refreshLibrary = false)
|
[FromQuery] bool refreshLibrary = false)
|
||||||
{
|
{
|
||||||
libraryOptions ??= new LibraryOptions();
|
var libraryOptions = libraryOptionsDto?.LibraryOptions ?? new LibraryOptions();
|
||||||
|
|
||||||
if (paths != null && paths.Length > 0)
|
if (paths != null && paths.Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -194,9 +196,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a media path to a library.
|
/// Add a media path to a library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name of the library.</param>
|
/// <param name="mediaPathDto">The media path dto.</param>
|
||||||
/// <param name="path">The path to add.</param>
|
|
||||||
/// <param name="pathInfo">The path info.</param>
|
|
||||||
/// <param name="refreshLibrary">Whether to refresh the library.</param>
|
/// <param name="refreshLibrary">Whether to refresh the library.</param>
|
||||||
/// <returns>A <see cref="NoContentResult"/>.</returns>
|
/// <returns>A <see cref="NoContentResult"/>.</returns>
|
||||||
/// <response code="204">Media path added.</response>
|
/// <response code="204">Media path added.</response>
|
||||||
|
@ -204,23 +204,16 @@ namespace Jellyfin.Api.Controllers
|
||||||
[HttpPost("Paths")]
|
[HttpPost("Paths")]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
public ActionResult AddMediaPath(
|
public ActionResult AddMediaPath(
|
||||||
[FromQuery] string? name,
|
[FromBody, BindRequired] MediaPathDto mediaPathDto,
|
||||||
[FromQuery] string? path,
|
|
||||||
[FromQuery] MediaPathInfo? pathInfo,
|
|
||||||
[FromQuery] bool refreshLibrary = false)
|
[FromQuery] bool refreshLibrary = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
_libraryMonitor.Stop();
|
_libraryMonitor.Stop();
|
||||||
|
|
||||||
try
|
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
|
finally
|
||||||
{
|
{
|
||||||
|
|
15
Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs
Normal file
15
Jellyfin.Api/Models/LibraryStructureDto/LibraryOptionsDto.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
27
Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs
Normal file
27
Jellyfin.Api/Models/LibraryStructureDto/MediaPathDto.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue