mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-09 07:10:34 +02:00
Merge pull request #2984 from crobibero/api-library
Move Library Service to Jellyfin.API
This commit is contained in:
commit
7c1020cfc1
|
@ -42,11 +42,13 @@ namespace Jellyfin.Api.Auth
|
|||
/// <param name="claimsPrincipal">Request claims.</param>
|
||||
/// <param name="ignoreSchedule">Whether to ignore parental control.</param>
|
||||
/// <param name="localAccessOnly">Whether access is to be allowed locally only.</param>
|
||||
/// <param name="requiredDownloadPermission">Whether validation requires download permission.</param>
|
||||
/// <returns>Validated claim status.</returns>
|
||||
protected bool ValidateClaims(
|
||||
ClaimsPrincipal claimsPrincipal,
|
||||
bool ignoreSchedule = false,
|
||||
bool localAccessOnly = false)
|
||||
bool localAccessOnly = false,
|
||||
bool requiredDownloadPermission = false)
|
||||
{
|
||||
// Ensure claim has userId.
|
||||
var userId = ClaimHelpers.GetUserId(claimsPrincipal);
|
||||
|
@ -89,6 +91,13 @@ namespace Jellyfin.Api.Auth
|
|||
return false;
|
||||
}
|
||||
|
||||
// User attempting to download without permission.
|
||||
if (requiredDownloadPermission
|
||||
&& !user.HasPermission(PermissionKind.EnableContentDownloading))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
45
Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs
Normal file
45
Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Threading.Tasks;
|
||||
using Jellyfin.Api.Auth.DefaultAuthorizationPolicy;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Jellyfin.Api.Auth.DownloadPolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// Download authorization handler.
|
||||
/// </summary>
|
||||
public class DownloadHandler : BaseAuthorizationHandler<DownloadRequirement>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DownloadHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
||||
/// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
|
||||
/// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
|
||||
public DownloadHandler(
|
||||
IUserManager userManager,
|
||||
INetworkManager networkManager,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
: base(userManager, networkManager, httpContextAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, DownloadRequirement requirement)
|
||||
{
|
||||
var validated = ValidateClaims(context.User);
|
||||
if (validated)
|
||||
{
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Fail();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
11
Jellyfin.Api/Auth/DownloadPolicy/DownloadRequirement.cs
Normal file
11
Jellyfin.Api/Auth/DownloadPolicy/DownloadRequirement.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Jellyfin.Api.Auth.DownloadPolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// The download permission requirement.
|
||||
/// </summary>
|
||||
public class DownloadRequirement : IAuthorizationRequirement
|
||||
{
|
||||
}
|
||||
}
|
|
@ -29,5 +29,10 @@ namespace Jellyfin.Api.Constants
|
|||
/// Policy name for escaping schedule controls.
|
||||
/// </summary>
|
||||
public const string IgnoreSchedule = "IgnoreSchedule";
|
||||
|
||||
/// <summary>
|
||||
/// Policy name for requiring download permission.
|
||||
/// </summary>
|
||||
public const string Download = "Download";
|
||||
}
|
||||
}
|
||||
|
|
1049
Jellyfin.Api/Controllers/LibraryController.cs
Normal file
1049
Jellyfin.Api/Controllers/LibraryController.cs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -87,7 +87,7 @@ namespace Jellyfin.Api.Helpers
|
|||
return Array.Empty<Guid>();
|
||||
}
|
||||
|
||||
return value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
return Split(value, ',', true)
|
||||
.Select(i => new Guid(i))
|
||||
.ToArray();
|
||||
}
|
||||
|
|
18
Jellyfin.Api/Models/LibraryDtos/LibraryOptionInfoDto.cs
Normal file
18
Jellyfin.Api/Models/LibraryDtos/LibraryOptionInfoDto.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace Jellyfin.Api.Models.LibraryDtos
|
||||
{
|
||||
/// <summary>
|
||||
/// Library option info dto.
|
||||
/// </summary>
|
||||
public class LibraryOptionInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets name.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether default enabled.
|
||||
/// </summary>
|
||||
public bool DefaultEnabled { get; set; }
|
||||
}
|
||||
}
|
34
Jellyfin.Api/Models/LibraryDtos/LibraryOptionsResultDto.cs
Normal file
34
Jellyfin.Api/Models/LibraryDtos/LibraryOptionsResultDto.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Jellyfin.Api.Models.LibraryDtos
|
||||
{
|
||||
/// <summary>
|
||||
/// Library options result dto.
|
||||
/// </summary>
|
||||
public class LibraryOptionsResultDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata savers.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "MetadataSavers", Justification = "Imported from ServiceStack")]
|
||||
public LibraryOptionInfoDto[] MetadataSavers { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata readers.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "MetadataReaders", Justification = "Imported from ServiceStack")]
|
||||
public LibraryOptionInfoDto[] MetadataReaders { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the subtitle fetchers.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "SubtitleFetchers", Justification = "Imported from ServiceStack")]
|
||||
public LibraryOptionInfoDto[] SubtitleFetchers { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type options.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "TypeOptions", Justification = "Imported from ServiceStack")]
|
||||
public LibraryTypeOptionsDto[] TypeOptions { get; set; } = null!;
|
||||
}
|
||||
}
|
41
Jellyfin.Api/Models/LibraryDtos/LibraryTypeOptionsDto.cs
Normal file
41
Jellyfin.Api/Models/LibraryDtos/LibraryTypeOptionsDto.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using MediaBrowser.Model.Configuration;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace Jellyfin.Api.Models.LibraryDtos
|
||||
{
|
||||
/// <summary>
|
||||
/// Library type options dto.
|
||||
/// </summary>
|
||||
public class LibraryTypeOptionsDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the type.
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the metadata fetchers.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "MetadataFetchers", Justification = "Imported from ServiceStack")]
|
||||
public LibraryOptionInfoDto[] MetadataFetchers { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the image fetchers.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "ImageFetchers", Justification = "Imported from ServiceStack")]
|
||||
public LibraryOptionInfoDto[] ImageFetchers { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the supported image types.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "SupportedImageTypes", Justification = "Imported from ServiceStack")]
|
||||
public ImageType[] SupportedImageTypes { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default image options.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:ReturnArrays", MessageId = "DefaultImageOptions", Justification = "Imported from ServiceStack")]
|
||||
public ImageOption[] DefaultImageOptions { get; set; } = null!;
|
||||
}
|
||||
}
|
19
Jellyfin.Api/Models/LibraryDtos/MediaUpdateInfoDto.cs
Normal file
19
Jellyfin.Api/Models/LibraryDtos/MediaUpdateInfoDto.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
namespace Jellyfin.Api.Models.LibraryDtos
|
||||
{
|
||||
/// <summary>
|
||||
/// Media Update Info Dto.
|
||||
/// </summary>
|
||||
public class MediaUpdateInfoDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets media path.
|
||||
/// </summary>
|
||||
public string? Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets media update type.
|
||||
/// Created, Modified, Deleted.
|
||||
/// </summary>
|
||||
public string? UpdateType { get; set; }
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ using System.Reflection;
|
|||
using Jellyfin.Api;
|
||||
using Jellyfin.Api.Auth;
|
||||
using Jellyfin.Api.Auth.DefaultAuthorizationPolicy;
|
||||
using Jellyfin.Api.Auth.DownloadPolicy;
|
||||
using Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy;
|
||||
using Jellyfin.Api.Auth.IgnoreSchedulePolicy;
|
||||
using Jellyfin.Api.Auth.LocalAccessPolicy;
|
||||
|
@ -39,6 +40,7 @@ namespace Jellyfin.Server.Extensions
|
|||
public static IServiceCollection AddJellyfinApiAuthorization(this IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddSingleton<IAuthorizationHandler, DefaultAuthorizationHandler>();
|
||||
serviceCollection.AddSingleton<IAuthorizationHandler, DownloadHandler>();
|
||||
serviceCollection.AddSingleton<IAuthorizationHandler, FirstTimeSetupOrElevatedHandler>();
|
||||
serviceCollection.AddSingleton<IAuthorizationHandler, IgnoreScheduleHandler>();
|
||||
serviceCollection.AddSingleton<IAuthorizationHandler, LocalAccessHandler>();
|
||||
|
@ -52,6 +54,13 @@ namespace Jellyfin.Server.Extensions
|
|||
policy.AddAuthenticationSchemes(AuthenticationSchemes.CustomAuthentication);
|
||||
policy.AddRequirements(new DefaultAuthorizationRequirement());
|
||||
});
|
||||
options.AddPolicy(
|
||||
Policies.Download,
|
||||
policy =>
|
||||
{
|
||||
policy.AddAuthenticationSchemes(AuthenticationSchemes.CustomAuthentication);
|
||||
policy.AddRequirements(new DownloadRequirement());
|
||||
});
|
||||
options.AddPolicy(
|
||||
Policies.FirstTimeSetupOrElevated,
|
||||
policy =>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,10 @@
|
|||
<Compile Include="..\SharedVersion.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Library" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
|
|
Loading…
Reference in a new issue