2020-11-18 13:23:45 +00:00
|
|
|
using System;
|
2020-06-25 23:28:12 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-05 23:11:44 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-06-25 23:28:12 +00:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Jellyfin.Api.Constants;
|
|
|
|
using Jellyfin.Api.Extensions;
|
2020-11-09 21:59:04 +00:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2022-09-10 00:14:23 +00:00
|
|
|
using Jellyfin.Api.Models.UserDtos;
|
2021-02-11 00:09:23 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2020-06-25 23:28:12 +00:00
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2022-09-15 23:45:26 +00:00
|
|
|
using MediaBrowser.Controller.Lyrics;
|
2020-06-25 23:28:12 +00:00
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
using MediaBrowser.Model.Querying;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// User library controller.
|
|
|
|
/// </summary>
|
2020-08-04 18:48:53 +00:00
|
|
|
[Route("")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
|
|
|
public class UserLibraryController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly IUserDataManager _userDataRepository;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
|
|
|
private readonly IFileSystem _fileSystem;
|
2022-09-16 00:49:25 +00:00
|
|
|
private readonly ILyricManager _lyricManager;
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="UserLibraryController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|
|
|
/// <param name="userDataRepository">Instance of the <see cref="IUserDataManager"/> interface.</param>
|
|
|
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
|
|
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
|
|
|
|
/// <param name="userViewManager">Instance of the <see cref="IUserViewManager"/> interface.</param>
|
|
|
|
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
2022-09-16 00:49:25 +00:00
|
|
|
/// <param name="lyricManager">Instance of the <see cref="ILyricManager"/> interface.</param>
|
2020-06-25 23:28:12 +00:00
|
|
|
public UserLibraryController(
|
|
|
|
IUserManager userManager,
|
|
|
|
IUserDataManager userDataRepository,
|
|
|
|
ILibraryManager libraryManager,
|
|
|
|
IDtoService dtoService,
|
|
|
|
IUserViewManager userViewManager,
|
2022-09-15 00:39:26 +00:00
|
|
|
IFileSystem fileSystem,
|
2022-09-16 00:49:25 +00:00
|
|
|
ILyricManager lyricManager)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
_userManager = userManager;
|
|
|
|
_userDataRepository = userDataRepository;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
_dtoService = dtoService;
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
_fileSystem = fileSystem;
|
2022-09-16 00:49:25 +00:00
|
|
|
_lyricManager = lyricManager;
|
2020-06-25 23:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets an item from a user's library.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Item returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the d item.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/{itemId}")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public async Task<ActionResult<BaseItemDto>> GetItem([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-02-21 13:15:09 +00:00
|
|
|
var item = itemId.Equals(default)
|
2020-06-25 23:28:12 +00:00
|
|
|
? _libraryManager.GetUserRootFolder()
|
|
|
|
: _libraryManager.GetItemById(itemId);
|
|
|
|
|
|
|
|
await RefreshItemOnDemandIfNeeded(item).ConfigureAwait(false);
|
|
|
|
|
2022-10-06 11:57:47 +00:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
return _dtoService.GetBaseItemDto(item, dtoOptions, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the root folder from a user's library.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <response code="200">Root folder returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the user's root folder.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/Root")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<BaseItemDto> GetRootFolder([FromRoute, Required] Guid userId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
var item = _libraryManager.GetUserRootFolder();
|
2022-10-06 11:57:47 +00:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2020-06-25 23:28:12 +00:00
|
|
|
return _dtoService.GetBaseItemDto(item, dtoOptions, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets intros to play before the main media item plays.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Intros returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the intros to play.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/{itemId}/Intros")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public async Task<ActionResult<QueryResult<BaseItemDto>>> GetIntros([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-02-21 13:15:09 +00:00
|
|
|
var item = itemId.Equals(default)
|
2020-06-25 23:28:12 +00:00
|
|
|
? _libraryManager.GetUserRootFolder()
|
|
|
|
: _libraryManager.GetItemById(itemId);
|
|
|
|
|
|
|
|
var items = await _libraryManager.GetIntros(item, user).ConfigureAwait(false);
|
2022-10-06 11:57:47 +00:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2020-06-25 23:28:12 +00:00
|
|
|
var dtos = items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray();
|
|
|
|
|
2022-01-20 15:46:17 +00:00
|
|
|
return new QueryResult<BaseItemDto>(dtos);
|
2020-06-25 23:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Marks an item as a favorite.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Item marked as favorite.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the <see cref="UserItemDataDto"/>.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpPost("Users/{userId}/FavoriteItems/{itemId}")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<UserItemDataDto> MarkFavoriteItem([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
return MarkFavorite(userId, itemId, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Unmarks item as a favorite.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Item unmarked as favorite.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the <see cref="UserItemDataDto"/>.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpDelete("Users/{userId}/FavoriteItems/{itemId}")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<UserItemDataDto> UnmarkFavoriteItem([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
return MarkFavorite(userId, itemId, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Deletes a user's saved personal rating for an item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Personal rating removed.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the <see cref="UserItemDataDto"/>.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpDelete("Users/{userId}/Items/{itemId}/Rating")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<UserItemDataDto> DeleteUserItemRating([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
return UpdateUserItemRatingInternal(userId, itemId, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates a user's rating for an item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <param name="likes">Whether this <see cref="UpdateUserItemRating" /> is likes.</param>
|
|
|
|
/// <response code="200">Item rating updated.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the <see cref="UserItemDataDto"/>.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpPost("Users/{userId}/Items/{itemId}/Rating")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<UserItemDataDto> UpdateUserItemRating([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId, [FromQuery] bool? likes)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
return UpdateUserItemRatingInternal(userId, itemId, likes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets local trailers for an item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">An <see cref="OkResult"/> containing the item's local trailers.</response>
|
|
|
|
/// <returns>The items local trailers.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/{itemId}/LocalTrailers")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<IEnumerable<BaseItemDto>> GetLocalTrailers([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-02-21 13:15:09 +00:00
|
|
|
var item = itemId.Equals(default)
|
2020-06-25 23:28:12 +00:00
|
|
|
? _libraryManager.GetUserRootFolder()
|
|
|
|
: _libraryManager.GetItemById(itemId);
|
|
|
|
|
2022-10-06 11:57:47 +00:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
if (item is IHasTrailers hasTrailers)
|
|
|
|
{
|
2021-12-07 14:18:17 +00:00
|
|
|
var trailers = hasTrailers.LocalTrailers;
|
2023-01-04 15:01:31 +00:00
|
|
|
return Ok(_dtoService.GetBaseItemDtos(trailers, dtoOptions, user, item).AsEnumerable());
|
2020-06-25 23:28:12 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 10:34:52 +00:00
|
|
|
return Ok(item.GetExtras()
|
|
|
|
.Where(e => e.ExtraType == ExtraType.Trailer)
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)));
|
2020-06-25 23:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets special features for an item.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Special features returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the special features.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/{itemId}/SpecialFeatures")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<IEnumerable<BaseItemDto>> GetSpecialFeatures([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-02-21 13:15:09 +00:00
|
|
|
var item = itemId.Equals(default)
|
2020-06-25 23:28:12 +00:00
|
|
|
? _libraryManager.GetUserRootFolder()
|
|
|
|
: _libraryManager.GetItemById(itemId);
|
|
|
|
|
2022-10-06 11:57:47 +00:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
return Ok(item
|
2022-09-13 22:40:47 +00:00
|
|
|
.GetExtras()
|
|
|
|
.Where(i => i.ExtraType.HasValue && BaseItem.DisplayExtraTypes.Contains(i.ExtraType.Value))
|
2020-06-25 23:28:12 +00:00
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets latest media.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="parentId">Specify this to localize the search to a specific item or folder. Omit to use the root.</param>
|
2020-10-09 23:35:08 +00:00
|
|
|
/// <param name="fields">Optional. Specify additional fields of information to return in the output.</param>
|
2020-11-18 13:23:45 +00:00
|
|
|
/// <param name="includeItemTypes">Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimited.</param>
|
2020-06-25 23:28:12 +00:00
|
|
|
/// <param name="isPlayed">Filter by items that are played, or not.</param>
|
|
|
|
/// <param name="enableImages">Optional. include image information in output.</param>
|
|
|
|
/// <param name="imageTypeLimit">Optional. the max number of images to return, per image type.</param>
|
|
|
|
/// <param name="enableImageTypes">Optional. The image types to include in the output.</param>
|
|
|
|
/// <param name="enableUserData">Optional. include user data.</param>
|
|
|
|
/// <param name="limit">Return item limit.</param>
|
|
|
|
/// <param name="groupItems">Whether or not to group items into a parent container.</param>
|
|
|
|
/// <response code="200">Latest media returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the latest media.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/Latest")]
|
2020-06-25 23:28:12 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<IEnumerable<BaseItemDto>> GetLatestMedia(
|
2020-09-06 15:07:27 +00:00
|
|
|
[FromRoute, Required] Guid userId,
|
2020-07-07 15:10:51 +00:00
|
|
|
[FromQuery] Guid? parentId,
|
2020-11-09 21:59:04 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ItemFields[] fields,
|
2021-02-11 00:09:23 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] includeItemTypes,
|
2020-06-25 23:28:12 +00:00
|
|
|
[FromQuery] bool? isPlayed,
|
|
|
|
[FromQuery] bool? enableImages,
|
|
|
|
[FromQuery] int? imageTypeLimit,
|
2020-11-09 21:53:23 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] ImageType[] enableImageTypes,
|
2020-06-25 23:28:12 +00:00
|
|
|
[FromQuery] bool? enableUserData,
|
|
|
|
[FromQuery] int limit = 20,
|
|
|
|
[FromQuery] bool groupItems = true)
|
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
|
|
|
if (!isPlayed.HasValue)
|
|
|
|
{
|
|
|
|
if (user.HidePlayedInLatest)
|
|
|
|
{
|
|
|
|
isPlayed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 17:36:45 +00:00
|
|
|
var dtoOptions = new DtoOptions { Fields = fields }
|
2022-10-06 11:57:47 +00:00
|
|
|
.AddClientFields(User)
|
2020-06-25 23:28:12 +00:00
|
|
|
.AddAdditionalDtoOptions(enableImages, enableUserData, imageTypeLimit, enableImageTypes);
|
|
|
|
|
|
|
|
var list = _userViewManager.GetLatestItems(
|
|
|
|
new LatestItemsQuery
|
|
|
|
{
|
|
|
|
GroupItems = groupItems,
|
2021-12-12 02:31:30 +00:00
|
|
|
IncludeItemTypes = includeItemTypes,
|
2020-06-25 23:28:12 +00:00
|
|
|
IsPlayed = isPlayed,
|
|
|
|
Limit = limit,
|
2020-07-07 15:10:51 +00:00
|
|
|
ParentId = parentId ?? Guid.Empty,
|
2020-06-25 23:28:12 +00:00
|
|
|
UserId = userId,
|
2021-12-24 17:28:27 +00:00
|
|
|
},
|
|
|
|
dtoOptions);
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
var dtos = list.Select(i =>
|
|
|
|
{
|
|
|
|
var item = i.Item2[0];
|
|
|
|
var childCount = 0;
|
|
|
|
|
2022-12-05 14:01:13 +00:00
|
|
|
if (i.Item1 is not null && (i.Item2.Count > 1 || i.Item1 is MusicAlbum))
|
2020-06-25 23:28:12 +00:00
|
|
|
{
|
|
|
|
item = i.Item1;
|
|
|
|
childCount = i.Item2.Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dto = _dtoService.GetBaseItemDto(item, dtoOptions, user);
|
|
|
|
|
|
|
|
dto.ChildCount = childCount;
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
});
|
|
|
|
|
|
|
|
return Ok(dtos);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task RefreshItemOnDemandIfNeeded(BaseItem item)
|
|
|
|
{
|
|
|
|
if (item is Person)
|
|
|
|
{
|
|
|
|
var hasMetdata = !string.IsNullOrWhiteSpace(item.Overview) && item.HasImage(ImageType.Primary);
|
|
|
|
var performFullRefresh = !hasMetdata && (DateTime.UtcNow - item.DateLastRefreshed).TotalDays >= 3;
|
|
|
|
|
|
|
|
if (!hasMetdata)
|
|
|
|
{
|
|
|
|
var options = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
|
|
|
|
{
|
|
|
|
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
|
|
|
|
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
|
|
|
|
ForceSave = performFullRefresh
|
|
|
|
};
|
|
|
|
|
|
|
|
await item.RefreshMetadata(options, CancellationToken.None).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Marks the favorite.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">The user id.</param>
|
|
|
|
/// <param name="itemId">The item id.</param>
|
|
|
|
/// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
|
|
|
|
private UserItemDataDto MarkFavorite(Guid userId, Guid itemId, bool isFavorite)
|
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-02-21 13:15:09 +00:00
|
|
|
var item = itemId.Equals(default) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId);
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
// Get the user data for this item
|
|
|
|
var data = _userDataRepository.GetUserData(user, item);
|
|
|
|
|
|
|
|
// Set favorite status
|
|
|
|
data.IsFavorite = isFavorite;
|
|
|
|
|
|
|
|
_userDataRepository.SaveUserData(user, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None);
|
|
|
|
|
|
|
|
return _userDataRepository.GetUserDataDto(item, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the user item rating.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">The user id.</param>
|
|
|
|
/// <param name="itemId">The item id.</param>
|
|
|
|
/// <param name="likes">if set to <c>true</c> [likes].</param>
|
|
|
|
private UserItemDataDto UpdateUserItemRatingInternal(Guid userId, Guid itemId, bool? likes)
|
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-02-21 13:15:09 +00:00
|
|
|
var item = itemId.Equals(default) ? _libraryManager.GetUserRootFolder() : _libraryManager.GetItemById(itemId);
|
2020-06-25 23:28:12 +00:00
|
|
|
|
|
|
|
// Get the user data for this item
|
|
|
|
var data = _userDataRepository.GetUserData(user, item);
|
|
|
|
|
|
|
|
data.Likes = likes;
|
|
|
|
|
|
|
|
_userDataRepository.SaveUserData(user, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None);
|
|
|
|
|
|
|
|
return _userDataRepository.GetUserDataDto(item, user);
|
|
|
|
}
|
2022-09-10 00:14:23 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets an item's lyrics.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="itemId">Item id.</param>
|
|
|
|
/// <response code="200">Lyrics returned.</response>
|
|
|
|
/// <response code="404">Something went wrong. No Lyrics will be returned.</response>
|
2022-09-17 00:52:40 +00:00
|
|
|
/// <returns>An <see cref="OkResult"/> containing the item's lyrics.</returns>
|
2022-09-10 00:14:23 +00:00
|
|
|
[HttpGet("Users/{userId}/Items/{itemId}/Lyrics")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2022-09-22 12:13:53 +00:00
|
|
|
public async Task<ActionResult<LyricResponse>> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
2022-09-10 00:14:23 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
2022-12-05 14:00:20 +00:00
|
|
|
if (user is null)
|
2022-09-10 00:14:23 +00:00
|
|
|
{
|
2022-09-10 01:08:38 +00:00
|
|
|
return NotFound();
|
2022-09-10 00:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var item = itemId.Equals(default)
|
|
|
|
? _libraryManager.GetUserRootFolder()
|
|
|
|
: _libraryManager.GetItemById(itemId);
|
|
|
|
|
2022-12-05 14:00:20 +00:00
|
|
|
if (item is null)
|
2022-09-10 00:14:23 +00:00
|
|
|
{
|
2022-09-10 01:15:57 +00:00
|
|
|
return NotFound();
|
2022-09-10 00:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 12:13:53 +00:00
|
|
|
var result = await _lyricManager.GetLyrics(item).ConfigureAwait(false);
|
2022-09-15 23:45:26 +00:00
|
|
|
if (result is not null)
|
2022-09-10 00:14:23 +00:00
|
|
|
{
|
2022-09-16 00:49:25 +00:00
|
|
|
return Ok(result);
|
2022-09-10 00:14:23 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 18:29:30 +00:00
|
|
|
return NotFound();
|
2022-09-10 00:14:23 +00:00
|
|
|
}
|
2020-06-25 23:28:12 +00:00
|
|
|
}
|
|
|
|
}
|