mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 17:44:43 +01:00
Make device/session code async
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data.Entities;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Library;
|
||||
@@ -23,7 +24,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
_sessionManager = sessionManager;
|
||||
}
|
||||
|
||||
public SessionInfo GetSession(HttpContext requestContext)
|
||||
public Task<SessionInfo> GetSession(HttpContext requestContext)
|
||||
{
|
||||
var authorization = _authContext.GetAuthorizationInfo(requestContext);
|
||||
|
||||
@@ -31,19 +32,19 @@ namespace Emby.Server.Implementations.HttpServer.Security
|
||||
return _sessionManager.LogSessionActivity(authorization.Client, authorization.Version, authorization.DeviceId, authorization.Device, requestContext.GetNormalizedRemoteIp(), user);
|
||||
}
|
||||
|
||||
public SessionInfo GetSession(object requestContext)
|
||||
public Task<SessionInfo> GetSession(object requestContext)
|
||||
{
|
||||
return GetSession((HttpContext)requestContext);
|
||||
}
|
||||
|
||||
public User GetUser(HttpContext requestContext)
|
||||
public async Task<User> GetUser(HttpContext requestContext)
|
||||
{
|
||||
var session = GetSession(requestContext);
|
||||
var session = await GetSession(requestContext).ConfigureAwait(false);
|
||||
|
||||
return session == null || session.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(session.UserId);
|
||||
}
|
||||
|
||||
public User GetUser(object requestContext)
|
||||
public Task<User> GetUser(object requestContext)
|
||||
{
|
||||
return GetUser(((HttpRequest)requestContext).HttpContext);
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <param name="remoteEndPoint">The remote end point.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <returns>SessionInfo.</returns>
|
||||
public SessionInfo LogSessionActivity(
|
||||
public async Task<SessionInfo> LogSessionActivity(
|
||||
string appName,
|
||||
string appVersion,
|
||||
string deviceId,
|
||||
@@ -280,7 +280,7 @@ namespace Emby.Server.Implementations.Session
|
||||
}
|
||||
|
||||
var activityDate = DateTime.UtcNow;
|
||||
var session = GetSessionInfo(appName, appVersion, deviceId, deviceName, remoteEndPoint, user);
|
||||
var session = await GetSessionInfo(appName, appVersion, deviceId, deviceName, remoteEndPoint, user).ConfigureAwait(false);
|
||||
var lastActivityDate = session.LastActivityDate;
|
||||
session.LastActivityDate = activityDate;
|
||||
|
||||
@@ -458,7 +458,7 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <param name="remoteEndPoint">The remote end point.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <returns>SessionInfo.</returns>
|
||||
private SessionInfo GetSessionInfo(
|
||||
private async Task<SessionInfo> GetSessionInfo(
|
||||
string appName,
|
||||
string appVersion,
|
||||
string deviceId,
|
||||
@@ -477,9 +477,11 @@ namespace Emby.Server.Implementations.Session
|
||||
|
||||
CheckDisposed();
|
||||
|
||||
var sessionInfo = _activeConnections.GetOrAdd(
|
||||
key,
|
||||
k => CreateSession(k, appName, appVersion, deviceId, deviceName, remoteEndPoint, user));
|
||||
if (!_activeConnections.TryGetValue(key, out var sessionInfo))
|
||||
{
|
||||
_activeConnections[key] = await CreateSession(key, appName, appVersion, deviceId, deviceName, remoteEndPoint, user).ConfigureAwait(false);
|
||||
sessionInfo = _activeConnections[key];
|
||||
}
|
||||
|
||||
sessionInfo.UserId = user?.Id ?? Guid.Empty;
|
||||
sessionInfo.UserName = user?.Username;
|
||||
@@ -502,7 +504,7 @@ namespace Emby.Server.Implementations.Session
|
||||
return sessionInfo;
|
||||
}
|
||||
|
||||
private SessionInfo CreateSession(
|
||||
private async Task<SessionInfo> CreateSession(
|
||||
string key,
|
||||
string appName,
|
||||
string appVersion,
|
||||
@@ -532,7 +534,7 @@ namespace Emby.Server.Implementations.Session
|
||||
deviceName = "Network Device";
|
||||
}
|
||||
|
||||
var deviceOptions = _deviceManager.GetDeviceOptions(deviceId);
|
||||
var deviceOptions = await _deviceManager.GetDeviceOptions(deviceId).ConfigureAwait(false);
|
||||
if (string.IsNullOrEmpty(deviceOptions.CustomName))
|
||||
{
|
||||
sessionInfo.DeviceName = deviceName;
|
||||
@@ -1507,13 +1509,13 @@ namespace Emby.Server.Implementations.Session
|
||||
|
||||
var token = GetAuthorizationToken(user, request.DeviceId, request.App, request.AppVersion, request.DeviceName);
|
||||
|
||||
var session = LogSessionActivity(
|
||||
var session = await LogSessionActivity(
|
||||
request.App,
|
||||
request.AppVersion,
|
||||
request.DeviceId,
|
||||
request.DeviceName,
|
||||
request.RemoteEndPoint,
|
||||
user);
|
||||
user).ConfigureAwait(false);
|
||||
|
||||
var returnResult = new AuthenticationResult
|
||||
{
|
||||
@@ -1811,7 +1813,7 @@ namespace Emby.Server.Implementations.Session
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public SessionInfo GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion)
|
||||
public Task<SessionInfo> GetSessionByAuthenticationToken(AuthenticationInfo info, string deviceId, string remoteEndpoint, string appVersion)
|
||||
{
|
||||
if (info == null)
|
||||
{
|
||||
@@ -1844,7 +1846,7 @@ namespace Emby.Server.Implementations.Session
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public SessionInfo GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint)
|
||||
public Task<SessionInfo> GetSessionByAuthenticationToken(string token, string deviceId, string remoteEndpoint)
|
||||
{
|
||||
var items = _authRepo.Get(new AuthenticationInfoQuery
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <inheritdoc />
|
||||
public async Task ProcessWebSocketConnectedAsync(IWebSocketConnection connection)
|
||||
{
|
||||
var session = GetSession(connection.QueryString, connection.RemoteEndPoint.ToString());
|
||||
var session = await GetSession(connection.QueryString, connection.RemoteEndPoint.ToString()).ConfigureAwait(false);
|
||||
if (session != null)
|
||||
{
|
||||
EnsureController(session, connection);
|
||||
@@ -109,7 +109,7 @@ namespace Emby.Server.Implementations.Session
|
||||
}
|
||||
}
|
||||
|
||||
private SessionInfo GetSession(IQueryCollection queryString, string remoteEndpoint)
|
||||
private Task<SessionInfo> GetSession(IQueryCollection queryString, string remoteEndpoint)
|
||||
{
|
||||
if (queryString == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user