This commit is contained in:
Cody Robibero 2024-03-25 17:53:42 -06:00
parent 24d30df23e
commit 6d8ee4eb7a
7 changed files with 11 additions and 27 deletions

View File

@ -15,7 +15,7 @@ namespace Jellyfin.Plugin.OpenSubtitles.API
/// </summary> /// </summary>
[ApiController] [ApiController]
[Produces(MediaTypeNames.Application.Json)] [Produces(MediaTypeNames.Application.Json)]
[Authorize(Policy = "DefaultAuthorization")] [Authorize]
public class OpenSubtitlesController : ControllerBase public class OpenSubtitlesController : ControllerBase
{ {
/// <summary> /// <summary>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
@ -19,7 +19,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Jellyfin.Common" Version="10.*-*" /> <PackageReference Include="Jellyfin.Common" Version="10.*-*" />
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" /> <PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" /> <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup> </ItemGroup>

View File

@ -82,10 +82,7 @@ namespace Jellyfin.Plugin.OpenSubtitles
/// <inheritdoc /> /// <inheritdoc />
public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest request, CancellationToken cancellationToken) public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest request, CancellationToken cancellationToken)
{ {
if (request == null) ArgumentNullException.ThrowIfNull(request);
{
throw new ArgumentNullException(nameof(request));
}
await Login(cancellationToken).ConfigureAwait(false); await Login(cancellationToken).ConfigureAwait(false);

View File

@ -39,10 +39,7 @@ namespace Jellyfin.Plugin.OpenSubtitles.OpenSubtitlesHandler
/// <returns>logout status.</returns> /// <returns>logout status.</returns>
public static async Task<bool> LogOutAsync(LoginInfo user, string apiKey, CancellationToken cancellationToken) public static async Task<bool> LogOutAsync(LoginInfo user, string apiKey, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(user.Token)) ArgumentException.ThrowIfNullOrEmpty(user.Token);
{
throw new ArgumentNullException(nameof(user.Token), "Token is null or empty");
}
var headers = new Dictionary<string, string> { { "Authorization", user.Token } }; var headers = new Dictionary<string, string> { { "Authorization", user.Token } };
@ -60,10 +57,7 @@ namespace Jellyfin.Plugin.OpenSubtitles.OpenSubtitlesHandler
/// <returns>The encapsulated user info.</returns> /// <returns>The encapsulated user info.</returns>
public static async Task<ApiResponse<EncapsulatedUserInfo>> GetUserInfo(LoginInfo user, string apiKey, CancellationToken cancellationToken) public static async Task<ApiResponse<EncapsulatedUserInfo>> GetUserInfo(LoginInfo user, string apiKey, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(user.Token)) ArgumentException.ThrowIfNullOrEmpty(user.Token);
{
throw new ArgumentNullException(nameof(user.Token), "Token is null or empty");
}
var headers = new Dictionary<string, string> { { "Authorization", user.Token } }; var headers = new Dictionary<string, string> { { "Authorization", user.Token } };
@ -82,10 +76,7 @@ namespace Jellyfin.Plugin.OpenSubtitles.OpenSubtitlesHandler
/// <returns>The subtitle download info.</returns> /// <returns>The subtitle download info.</returns>
public static async Task<ApiResponse<SubtitleDownloadInfo>> GetSubtitleLinkAsync(int file, LoginInfo user, string apiKey, CancellationToken cancellationToken) public static async Task<ApiResponse<SubtitleDownloadInfo>> GetSubtitleLinkAsync(int file, LoginInfo user, string apiKey, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(user.Token)) ArgumentException.ThrowIfNullOrEmpty(user.Token);
{
throw new ArgumentNullException(nameof(user.Token), "Token is null or empty");
}
var headers = new Dictionary<string, string> { { "Authorization", user.Token } }; var headers = new Dictionary<string, string> { { "Authorization", user.Token } };

View File

@ -53,11 +53,7 @@ namespace Jellyfin.Plugin.OpenSubtitles.OpenSubtitlesHandler
throw new ArgumentException("Provided API key is blank", nameof(apiKey)); throw new ArgumentException("Provided API key is blank", nameof(apiKey));
} }
if (!headers.ContainsKey("Api-Key")) headers.TryAdd("Api-Key", apiKey);
{
headers.Add("Api-Key", apiKey);
}
if (_hRemaining == 0) if (_hRemaining == 0)
{ {
await Task.Delay(1000 * _hReset, cancellationToken).ConfigureAwait(false); await Task.Delay(1000 * _hReset, cancellationToken).ConfigureAwait(false);

View File

@ -2,8 +2,8 @@ name: "Open Subtitles"
guid: "4b9ed42f-5185-48b5-9803-6ff2989014c4" guid: "4b9ed42f-5185-48b5-9803-6ff2989014c4"
imageUrl: "https://repo.jellyfin.org/releases/plugin/images/jellyfin-plugin-opensubtitles.png" imageUrl: "https://repo.jellyfin.org/releases/plugin/images/jellyfin-plugin-opensubtitles.png"
version: 19 version: 19
targetAbi: "10.8.10.0" targetAbi: "10.9.0.0"
framework: "net6.0" framework: "net8.0"
owner: "jellyfin" owner: "jellyfin"
overview: "Download subtitles for your media" overview: "Download subtitles for your media"
description: "Download subtitles from the internet to use with your media files." description: "Download subtitles from the internet to use with your media files."

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>