mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Code cleanup
This commit is contained in:
parent
0945659cb5
commit
3c91aa0c3d
@ -14,6 +14,7 @@ using MediaBrowser.Model.Services;
|
|||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
|
using MediaBrowser.Controller.Authentication;
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.QuickConnect
|
namespace Emby.Server.Implementations.QuickConnect
|
||||||
{
|
{
|
||||||
@ -83,13 +84,13 @@ namespace Emby.Server.Implementations.QuickConnect
|
|||||||
public void Activate()
|
public void Activate()
|
||||||
{
|
{
|
||||||
DateActivated = DateTime.Now;
|
DateActivated = DateTime.Now;
|
||||||
SetEnabled(QuickConnectState.Active);
|
SetState(QuickConnectState.Active);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void SetEnabled(QuickConnectState newState)
|
public void SetState(QuickConnectState newState)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Changed quick connect state from {0} to {1}", State, newState);
|
_logger.LogDebug("Changed quick connect state from {State} to {newState}", State, newState);
|
||||||
|
|
||||||
ExpireRequests(true);
|
ExpireRequests(true);
|
||||||
|
|
||||||
@ -107,12 +108,8 @@ namespace Emby.Server.Implementations.QuickConnect
|
|||||||
|
|
||||||
if (State != QuickConnectState.Active)
|
if (State != QuickConnectState.Active)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Refusing quick connect initiation request, current state is {0}", State);
|
_logger.LogDebug("Refusing quick connect initiation request, current state is {State}", State);
|
||||||
|
throw new AuthenticationException("Quick connect is not active on this server");
|
||||||
return new QuickConnectResult()
|
|
||||||
{
|
|
||||||
Error = "Quick connect is not active on this server"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug("Got new quick connect request from {friendlyName}", friendlyName);
|
_logger.LogDebug("Got new quick connect request from {friendlyName}", friendlyName);
|
||||||
@ -200,7 +197,7 @@ namespace Emby.Server.Implementations.QuickConnect
|
|||||||
UserId = auth.UserId
|
UserId = auth.UserId
|
||||||
});
|
});
|
||||||
|
|
||||||
_logger.LogInformation("Allowing device {0} to login as user {1} with quick connect code {2}", result.FriendlyName, auth.User.Username, result.Code);
|
_logger.LogInformation("Allowing device {FriendlyName} to login as user {Username} with quick connect code {Code}", result.FriendlyName, auth.User.Username, result.Code);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -216,13 +213,15 @@ namespace Emby.Server.Implementations.QuickConnect
|
|||||||
|
|
||||||
var tokens = raw.Items.Where(x => x.AppName.StartsWith(TokenNamePrefix, StringComparison.CurrentCulture));
|
var tokens = raw.Items.Where(x => x.AppName.StartsWith(TokenNamePrefix, StringComparison.CurrentCulture));
|
||||||
|
|
||||||
|
var removed = 0;
|
||||||
foreach (var token in tokens)
|
foreach (var token in tokens)
|
||||||
{
|
{
|
||||||
_authenticationRepository.Delete(token);
|
_authenticationRepository.Delete(token);
|
||||||
_logger.LogDebug("Deleted token {0}", token.AccessToken);
|
_logger.LogDebug("Deleted token {AccessToken}", token.AccessToken);
|
||||||
|
removed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokens.Count();
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -261,7 +260,7 @@ namespace Emby.Server.Implementations.QuickConnect
|
|||||||
if (State == QuickConnectState.Active && DateTime.Now > DateActivated.AddMinutes(Timeout) && !expireAll)
|
if (State == QuickConnectState.Active && DateTime.Now > DateActivated.AddMinutes(Timeout) && !expireAll)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Quick connect time expired, deactivating");
|
_logger.LogDebug("Quick connect time expired, deactivating");
|
||||||
SetEnabled(QuickConnectState.Available);
|
SetState(QuickConnectState.Available);
|
||||||
expireAll = true;
|
expireAll = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ namespace MediaBrowser.Api.QuickConnect
|
|||||||
|
|
||||||
public object Post(Available request)
|
public object Post(Available request)
|
||||||
{
|
{
|
||||||
_quickConnect.SetEnabled(request.Status);
|
_quickConnect.SetState(request.Status);
|
||||||
return _quickConnect.State;
|
return _quickConnect.State;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,16 +41,16 @@ namespace MediaBrowser.Controller.QuickConnect
|
|||||||
void Activate();
|
void Activate();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Changes the status of quick connect.
|
/// Changes the state of quick connect.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newState">New state to change to.</param>
|
/// <param name="newState">New state to change to.</param>
|
||||||
void SetEnabled(QuickConnectState newState);
|
void SetState(QuickConnectState newState);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initiates a new quick connect request.
|
/// Initiates a new quick connect request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="friendlyName">Friendly device name to display in the request UI.</param>
|
/// <param name="friendlyName">Friendly device name to display in the request UI.</param>
|
||||||
/// <returns>A quick connect result with tokens to proceed or a descriptive error message otherwise.</returns>
|
/// <returns>A quick connect result with tokens to proceed or throws an exception if not active.</returns>
|
||||||
QuickConnectResult TryConnect(string friendlyName);
|
QuickConnectResult TryConnect(string friendlyName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user