2020-11-21 13:26:03 +00:00
|
|
|
using System;
|
2020-09-05 23:11:44 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-11-02 03:37:03 +00:00
|
|
|
using Jellyfin.Api.Constants;
|
2020-06-19 20:18:46 +00:00
|
|
|
using Jellyfin.Api.Extensions;
|
2020-11-17 03:29:46 +00:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2020-08-03 18:01:24 +00:00
|
|
|
using Jellyfin.Data.Enums;
|
2020-06-19 20:18:46 +00:00
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Querying;
|
2020-11-02 03:37:03 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-19 20:18:46 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The suggestions controller.
|
|
|
|
/// </summary>
|
2020-08-04 18:48:53 +00:00
|
|
|
[Route("")]
|
2020-11-02 03:37:03 +00:00
|
|
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
2020-06-19 20:18:46 +00:00
|
|
|
public class SuggestionsController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SuggestionsController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
|
|
|
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|
|
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
|
|
public SuggestionsController(
|
|
|
|
IDtoService dtoService,
|
|
|
|
IUserManager userManager,
|
|
|
|
ILibraryManager libraryManager)
|
|
|
|
{
|
|
|
|
_dtoService = dtoService;
|
|
|
|
_userManager = userManager;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets suggestions.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">The user id.</param>
|
|
|
|
/// <param name="mediaType">The media types.</param>
|
|
|
|
/// <param name="type">The type.</param>
|
|
|
|
/// <param name="startIndex">Optional. The start index.</param>
|
|
|
|
/// <param name="limit">Optional. The limit.</param>
|
2020-07-07 15:10:51 +00:00
|
|
|
/// <param name="enableTotalRecordCount">Whether to enable the total record count.</param>
|
2020-06-19 20:18:46 +00:00
|
|
|
/// <response code="200">Suggestions returned.</response>
|
|
|
|
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the suggestions.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Suggestions")]
|
2020-06-19 20:18:46 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public ActionResult<QueryResult<BaseItemDto>> GetSuggestions(
|
2020-09-06 15:07:27 +00:00
|
|
|
[FromRoute, Required] Guid userId,
|
2020-11-17 03:29:46 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] mediaType,
|
2021-12-12 02:31:30 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] BaseItemKind[] type,
|
2020-06-19 20:18:46 +00:00
|
|
|
[FromQuery] int? startIndex,
|
2020-07-07 15:10:51 +00:00
|
|
|
[FromQuery] int? limit,
|
|
|
|
[FromQuery] bool enableTotalRecordCount = false)
|
2020-06-19 20:18:46 +00:00
|
|
|
{
|
2022-02-21 13:15:09 +00:00
|
|
|
var user = userId.Equals(default)
|
|
|
|
? null
|
|
|
|
: _userManager.GetUserById(userId);
|
2020-06-19 20:18:46 +00:00
|
|
|
|
2022-10-06 11:57:47 +00:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2020-06-19 20:18:46 +00:00
|
|
|
var result = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
|
|
|
|
{
|
2021-04-21 20:25:08 +00:00
|
|
|
OrderBy = new[] { (ItemSortBy.Random, SortOrder.Descending) },
|
2020-11-17 03:29:46 +00:00
|
|
|
MediaTypes = mediaType,
|
|
|
|
IncludeItemTypes = type,
|
2020-06-19 20:18:46 +00:00
|
|
|
IsVirtualItem = false,
|
|
|
|
StartIndex = startIndex,
|
|
|
|
Limit = limit,
|
|
|
|
DtoOptions = dtoOptions,
|
|
|
|
EnableTotalRecordCount = enableTotalRecordCount,
|
|
|
|
Recursive = true
|
|
|
|
});
|
|
|
|
|
|
|
|
var dtoList = _dtoService.GetBaseItemDtos(result.Items, dtoOptions, user);
|
|
|
|
|
2022-01-20 15:46:17 +00:00
|
|
|
return new QueryResult<BaseItemDto>(
|
|
|
|
startIndex,
|
|
|
|
result.TotalRecordCount,
|
|
|
|
dtoList);
|
2020-06-19 20:18:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|