mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
fix
This commit is contained in:
parent
ed5bc3f873
commit
3b2a0d84be
2 changed files with 52 additions and 1 deletions
52
src/Ombi.Core/Authentication/PlexTokenKeepAliveService.cs
Normal file
52
src/Ombi.Core/Authentication/PlexTokenKeepAliveService.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ombi.Api.Plex;
|
||||
|
||||
namespace Ombi.Core.Authentication
|
||||
{
|
||||
public interface IPlexTokenKeepAliveService
|
||||
{
|
||||
Task<bool> KeepTokenAliveAsync(string token, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public class PlexTokenKeepAliveService : IPlexTokenKeepAliveService
|
||||
{
|
||||
private readonly IPlexApi _plexApi;
|
||||
private readonly ILogger<PlexTokenKeepAliveService> _logger;
|
||||
|
||||
public PlexTokenKeepAliveService(IPlexApi plexApi, ILogger<PlexTokenKeepAliveService> logger)
|
||||
{
|
||||
_plexApi = plexApi;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<bool> KeepTokenAliveAsync(string token, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
_logger.LogWarning("Token is null or empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use the Ping method to validate the token
|
||||
var isValid = await _plexApi.Ping(token, cancellationToken);
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
_logger.LogWarning("Token validation failed - token may be expired or invalid");
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error occurred while keeping token alive");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,6 @@ using Ombi.Core.Notifications;
|
|||
using Microsoft.AspNetCore.Identity;
|
||||
using Ombi.Store.Repository.Requests;
|
||||
using Ombi.Core;
|
||||
using Ombi.Core.Authentication;
|
||||
|
||||
namespace Ombi.Schedule.Jobs.Plex
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue