mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-31 14:33:54 -04:00
Add endpoint for getting playlists by id (#12697)
This commit is contained in:
parent
bc9594aeed
commit
e67dd3fc0e
@ -149,6 +149,37 @@ public class PlaylistsController : BaseJellyfinApiController
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a playlist.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="playlistId">The playlist id.</param>
|
||||||
|
/// <response code="200">The playlist.</response>
|
||||||
|
/// <response code="404">Playlist not found.</response>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="Playlist"/> objects.
|
||||||
|
/// </returns>
|
||||||
|
[HttpGet("{playlistId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
public ActionResult<PlaylistDto> GetPlaylist(
|
||||||
|
[FromRoute, Required] Guid playlistId)
|
||||||
|
{
|
||||||
|
var userId = User.GetUserId();
|
||||||
|
|
||||||
|
var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId);
|
||||||
|
if (playlist is null)
|
||||||
|
{
|
||||||
|
return NotFound("Playlist not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlaylistDto()
|
||||||
|
{
|
||||||
|
Shares = playlist.Shares,
|
||||||
|
OpenAccess = playlist.OpenAccess,
|
||||||
|
ItemIds = playlist.GetManageableItems().Select(t => t.Item2.Id).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a playlist's users.
|
/// Get a playlist's users.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -467,32 +498,23 @@ public class PlaylistsController : BaseJellyfinApiController
|
|||||||
[FromQuery] int? imageTypeLimit,
|
[FromQuery] int? imageTypeLimit,
|
||||||
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes)
|
||||||
{
|
{
|
||||||
userId = RequestHelpers.GetUserId(User, userId);
|
var callingUserId = userId ?? User.GetUserId();
|
||||||
var playlist = _playlistManager.GetPlaylistForUser(playlistId, userId.Value);
|
var playlist = _playlistManager.GetPlaylistForUser(playlistId, callingUserId);
|
||||||
if (playlist is null)
|
if (playlist is null)
|
||||||
{
|
{
|
||||||
return NotFound("Playlist not found");
|
return NotFound("Playlist not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
var isPermitted = playlist.OpenAccess
|
var isPermitted = playlist.OpenAccess
|
||||||
|| playlist.OwnerUserId.Equals(userId.Value)
|
|| playlist.OwnerUserId.Equals(callingUserId)
|
||||||
|| playlist.Shares.Any(s => s.UserId.Equals(userId.Value));
|
|| playlist.Shares.Any(s => s.UserId.Equals(callingUserId));
|
||||||
|
|
||||||
if (!isPermitted)
|
if (!isPermitted)
|
||||||
{
|
{
|
||||||
return Forbid();
|
return Forbid();
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = userId.IsNullOrEmpty()
|
var items = playlist.GetManageableItems().ToArray();
|
||||||
? null
|
|
||||||
: _userManager.GetUserById(userId.Value);
|
|
||||||
var item = _libraryManager.GetItemById<Playlist>(playlistId, user);
|
|
||||||
if (item is null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
var items = item.GetManageableItems().ToArray();
|
|
||||||
var count = items.Length;
|
var count = items.Length;
|
||||||
if (startIndex.HasValue)
|
if (startIndex.HasValue)
|
||||||
{
|
{
|
||||||
@ -507,7 +529,7 @@ public class PlaylistsController : BaseJellyfinApiController
|
|||||||
var dtoOptions = new DtoOptions { Fields = fields }
|
var dtoOptions = new DtoOptions { Fields = fields }
|
||||||
.AddClientFields(User)
|
.AddClientFields(User)
|
||||||
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
||||||
|
var user = _userManager.GetUserById(callingUserId);
|
||||||
var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user);
|
var dtos = _dtoService.GetBaseItemDtos(items.Select(i => i.Item2).ToList(), dtoOptions, user);
|
||||||
for (int index = 0; index < dtos.Count; index++)
|
for (int index = 0; index < dtos.Count; index++)
|
||||||
{
|
{
|
||||||
|
26
MediaBrowser.Model/Dto/PlaylistDto.cs
Normal file
26
MediaBrowser.Model/Dto/PlaylistDto.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Model.Dto;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// DTO for playlists.
|
||||||
|
/// </summary>
|
||||||
|
public class PlaylistDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the playlist is publicly readable.
|
||||||
|
/// </summary>
|
||||||
|
public bool OpenAccess { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the share permissions.
|
||||||
|
/// </summary>
|
||||||
|
public required IReadOnlyList<PlaylistUserPermissions> Shares { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the item ids.
|
||||||
|
/// </summary>
|
||||||
|
public required IReadOnlyList<Guid> ItemIds { get; set; }
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user