2020-11-21 13:26:03 +00:00
|
|
|
using System;
|
2020-06-25 22:46:09 +00:00
|
|
|
using System.Collections.Generic;
|
2020-09-05 23:11:44 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-06-25 22:46:09 +00:00
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
2021-05-21 03:56:59 +00:00
|
|
|
using System.Threading.Tasks;
|
2022-03-18 20:56:42 +00:00
|
|
|
using Jellyfin.Api.Constants;
|
2020-06-25 22:46:09 +00:00
|
|
|
using Jellyfin.Api.Extensions;
|
2020-11-17 03:29:46 +00:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2020-06-25 22:46:09 +00:00
|
|
|
using Jellyfin.Api.Models.UserViewDtos;
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Library;
|
|
|
|
using MediaBrowser.Model.Querying;
|
2022-03-18 20:56:42 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-25 22:46:09 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Jellyfin.Api.Controllers
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// User views controller.
|
|
|
|
/// </summary>
|
2020-08-04 18:48:53 +00:00
|
|
|
[Route("")]
|
2022-03-18 20:56:42 +00:00
|
|
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
2020-06-25 22:46:09 +00:00
|
|
|
public class UserViewsController : BaseJellyfinApiController
|
|
|
|
{
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly IAuthorizationContext _authContext;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="UserViewsController"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
|
|
|
/// <param name="userViewManager">Instance of the <see cref="IUserViewManager"/> interface.</param>
|
|
|
|
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
|
|
|
|
/// <param name="authContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
|
|
|
|
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
|
|
public UserViewsController(
|
|
|
|
IUserManager userManager,
|
|
|
|
IUserViewManager userViewManager,
|
|
|
|
IDtoService dtoService,
|
|
|
|
IAuthorizationContext authContext,
|
|
|
|
ILibraryManager libraryManager)
|
|
|
|
{
|
|
|
|
_userManager = userManager;
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
_dtoService = dtoService;
|
|
|
|
_authContext = authContext;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get user views.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <param name="includeExternalContent">Whether or not to include external views such as channels or live tv.</param>
|
|
|
|
/// <param name="presetViews">Preset views.</param>
|
2020-07-07 15:10:51 +00:00
|
|
|
/// <param name="includeHidden">Whether or not to include hidden content.</param>
|
2020-06-25 22:46:09 +00:00
|
|
|
/// <response code="200">User views returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the user views.</returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/Views")]
|
2020-06-25 22:46:09 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
2022-03-18 21:16:08 +00:00
|
|
|
public QueryResult<BaseItemDto> GetUserViews(
|
2020-09-06 15:07:27 +00:00
|
|
|
[FromRoute, Required] Guid userId,
|
2020-06-25 22:46:09 +00:00
|
|
|
[FromQuery] bool? includeExternalContent,
|
2020-11-17 03:29:46 +00:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] string[] presetViews,
|
2020-07-07 15:10:51 +00:00
|
|
|
[FromQuery] bool includeHidden = false)
|
2020-06-25 22:46:09 +00:00
|
|
|
{
|
|
|
|
var query = new UserViewQuery
|
|
|
|
{
|
|
|
|
UserId = userId,
|
|
|
|
IncludeHidden = includeHidden
|
|
|
|
};
|
|
|
|
|
|
|
|
if (includeExternalContent.HasValue)
|
|
|
|
{
|
|
|
|
query.IncludeExternalContent = includeExternalContent.Value;
|
|
|
|
}
|
|
|
|
|
2020-11-17 03:29:46 +00:00
|
|
|
if (presetViews.Length != 0)
|
2020-06-25 22:46:09 +00:00
|
|
|
{
|
2020-11-17 03:29:46 +00:00
|
|
|
query.PresetViews = presetViews;
|
2020-06-25 22:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var folders = _userViewManager.GetUserViews(query);
|
|
|
|
|
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(Request);
|
|
|
|
var fields = dtoOptions.Fields.ToList();
|
|
|
|
|
|
|
|
fields.Add(ItemFields.PrimaryImageAspectRatio);
|
|
|
|
fields.Add(ItemFields.DisplayPreferencesId);
|
|
|
|
fields.Remove(ItemFields.BasicSyncInfo);
|
|
|
|
dtoOptions.Fields = fields.ToArray();
|
|
|
|
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
|
|
|
var dtos = folders.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user))
|
|
|
|
.ToArray();
|
|
|
|
|
2022-01-20 15:46:17 +00:00
|
|
|
return new QueryResult<BaseItemDto>(dtos);
|
2020-06-25 22:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Get user view grouping options.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="userId">User id.</param>
|
|
|
|
/// <response code="200">User view grouping options returned.</response>
|
|
|
|
/// <response code="404">User not found.</response>
|
|
|
|
/// <returns>
|
|
|
|
/// An <see cref="OkResult"/> containing the user view grouping options
|
|
|
|
/// or a <see cref="NotFoundResult"/> if user not found.
|
|
|
|
/// </returns>
|
2020-08-04 18:48:53 +00:00
|
|
|
[HttpGet("Users/{userId}/GroupingOptions")]
|
2020-06-25 22:46:09 +00:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2020-09-06 15:07:27 +00:00
|
|
|
public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptions([FromRoute, Required] Guid userId)
|
2020-06-25 22:46:09 +00:00
|
|
|
{
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
if (user == null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok(_libraryManager.GetUserRootFolder()
|
|
|
|
.GetChildren(user, true)
|
|
|
|
.OfType<Folder>()
|
|
|
|
.Where(UserView.IsEligibleForGrouping)
|
|
|
|
.Select(i => new SpecialViewOptionDto
|
|
|
|
{
|
|
|
|
Name = i.Name,
|
|
|
|
Id = i.Id.ToString("N", CultureInfo.InvariantCulture)
|
|
|
|
})
|
|
|
|
.OrderBy(i => i.Name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|