2020-11-21 14:26:03 +01:00
|
|
|
using System;
|
2020-06-26 00:46:09 +02:00
|
|
|
using System.Collections.Generic;
|
2020-09-06 01:11:44 +02:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2020-06-26 00:46:09 +02:00
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
|
|
|
using Jellyfin.Api.Extensions;
|
2024-03-03 21:51:31 +01:00
|
|
|
using Jellyfin.Api.Helpers;
|
2020-11-17 04:29:46 +01:00
|
|
|
using Jellyfin.Api.ModelBinders;
|
2020-06-26 00:46:09 +02:00
|
|
|
using Jellyfin.Api.Models.UserViewDtos;
|
2023-11-09 22:00:29 +01:00
|
|
|
using Jellyfin.Data.Enums;
|
2020-06-26 00:46:09 +02:00
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
using MediaBrowser.Model.Library;
|
|
|
|
using MediaBrowser.Model.Querying;
|
2022-03-18 21:56:42 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2020-06-26 00:46:09 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
namespace Jellyfin.Api.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// User views controller.
|
|
|
|
/// </summary>
|
|
|
|
[Route("")]
|
2023-02-08 23:55:26 +01:00
|
|
|
[Authorize]
|
2023-01-31 12:18:10 +01:00
|
|
|
public class UserViewsController : BaseJellyfinApiController
|
2020-06-26 00:46:09 +02:00
|
|
|
{
|
2023-01-31 12:18:10 +01:00
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
private readonly IUserViewManager _userViewManager;
|
|
|
|
private readonly IDtoService _dtoService;
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
2020-06-26 00:46:09 +02:00
|
|
|
/// <summary>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// Initializes a new instance of the <see cref="UserViewsController"/> class.
|
2020-06-26 00:46:09 +02:00
|
|
|
/// </summary>
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <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="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
|
|
|
public UserViewsController(
|
|
|
|
IUserManager userManager,
|
|
|
|
IUserViewManager userViewManager,
|
|
|
|
IDtoService dtoService,
|
|
|
|
ILibraryManager libraryManager)
|
2020-06-26 00:46:09 +02:00
|
|
|
{
|
2023-01-31 12:18:10 +01:00
|
|
|
_userManager = userManager;
|
|
|
|
_userViewManager = userViewManager;
|
|
|
|
_dtoService = dtoService;
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
}
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
/// <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>
|
|
|
|
/// <param name="includeHidden">Whether or not to include hidden content.</param>
|
|
|
|
/// <response code="200">User views returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the user views.</returns>
|
2024-03-03 21:51:31 +01:00
|
|
|
[HttpGet("UserViews")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
public QueryResult<BaseItemDto> GetUserViews(
|
2024-03-03 21:51:31 +01:00
|
|
|
[FromQuery] Guid? userId,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] bool? includeExternalContent,
|
2023-11-09 22:00:29 +01:00
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] CollectionType?[] presetViews,
|
2023-01-31 12:18:10 +01:00
|
|
|
[FromQuery] bool includeHidden = false)
|
|
|
|
{
|
2024-03-03 21:51:31 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
|
|
|
|
|
|
|
var query = new UserViewQuery { UserId = userId.Value, IncludeHidden = includeHidden };
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
if (includeExternalContent.HasValue)
|
2020-06-26 00:46:09 +02:00
|
|
|
{
|
2023-01-31 12:18:10 +01:00
|
|
|
query.IncludeExternalContent = includeExternalContent.Value;
|
|
|
|
}
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
if (presetViews.Length != 0)
|
|
|
|
{
|
|
|
|
query.PresetViews = presetViews;
|
|
|
|
}
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var folders = _userViewManager.GetUserViews(query);
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
var dtoOptions = new DtoOptions().AddClientFields(User);
|
2024-04-30 21:32:59 +02:00
|
|
|
dtoOptions.Fields = [..dtoOptions.Fields, ItemFields.PrimaryImageAspectRatio, ItemFields.DisplayPreferencesId];
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2024-03-03 21:51:31 +01:00
|
|
|
var user = _userManager.GetUserById(userId.Value);
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2024-04-30 21:32:59 +02:00
|
|
|
var dtos = Array.ConvertAll(folders, i => _dtoService.GetBaseItemDto(i, dtoOptions, user));
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
return new QueryResult<BaseItemDto>(dtos);
|
|
|
|
}
|
2020-06-26 00:46:09 +02:00
|
|
|
|
2024-03-03 21:51:31 +01:00
|
|
|
/// <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>
|
|
|
|
/// <param name="includeHidden">Whether or not to include hidden content.</param>
|
|
|
|
/// <response code="200">User views returned.</response>
|
|
|
|
/// <returns>An <see cref="OkResult"/> containing the user views.</returns>
|
|
|
|
[HttpGet("Users/{userId}/Views")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[Obsolete("Kept for backwards compatibility")]
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
public QueryResult<BaseItemDto> GetUserViewsLegacy(
|
|
|
|
[FromRoute, Required] Guid userId,
|
|
|
|
[FromQuery] bool? includeExternalContent,
|
|
|
|
[FromQuery, ModelBinder(typeof(CommaDelimitedArrayModelBinder))] CollectionType?[] presetViews,
|
|
|
|
[FromQuery] bool includeHidden = false)
|
|
|
|
=> GetUserViews(userId, includeExternalContent, presetViews, includeHidden);
|
|
|
|
|
2023-01-31 12:18:10 +01: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>
|
2024-03-03 21:51:31 +01:00
|
|
|
[HttpGet("UserViews/GroupingOptions")]
|
2023-01-31 12:18:10 +01:00
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-03-03 21:51:31 +01:00
|
|
|
public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptions([FromQuery] Guid? userId)
|
2023-01-31 12:18:10 +01:00
|
|
|
{
|
2024-03-03 21:51:31 +01:00
|
|
|
userId = RequestHelpers.GetUserId(User, userId);
|
|
|
|
var user = _userManager.GetUserById(userId.Value);
|
2023-01-31 12:18:10 +01:00
|
|
|
if (user is null)
|
|
|
|
{
|
|
|
|
return NotFound();
|
2020-06-26 00:46:09 +02:00
|
|
|
}
|
|
|
|
|
2023-01-31 12:18:10 +01:00
|
|
|
return Ok(_libraryManager.GetUserRootFolder()
|
|
|
|
.GetChildren(user, true)
|
|
|
|
.OfType<Folder>()
|
|
|
|
.Where(UserView.IsEligibleForGrouping)
|
|
|
|
.Select(i => new SpecialViewOptionDto
|
2020-06-26 00:46:09 +02:00
|
|
|
{
|
2023-01-31 12:18:10 +01:00
|
|
|
Name = i.Name,
|
|
|
|
Id = i.Id.ToString("N", CultureInfo.InvariantCulture)
|
|
|
|
})
|
|
|
|
.OrderBy(i => i.Name)
|
|
|
|
.AsEnumerable());
|
2020-06-26 00:46:09 +02:00
|
|
|
}
|
2024-03-03 21:51:31 +01: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>
|
|
|
|
[HttpGet("Users/{userId}/GroupingOptions")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
[Obsolete("Kept for backwards compatibility")]
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
public ActionResult<IEnumerable<SpecialViewOptionDto>> GetGroupingOptionsLegacy(
|
|
|
|
[FromRoute, Required] Guid userId)
|
|
|
|
=> GetGroupingOptions(userId);
|
2020-06-26 00:46:09 +02:00
|
|
|
}
|