From 38d0b004baf4ff80d178a30d720e81e66b532b75 Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 24 Sep 2024 22:12:04 +0800 Subject: [PATCH 1/2] Only move trickplay file should not be saved with media to metadata dir (#12704) --- Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs b/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs index 73e31279f4be..f6c48498ca69 100644 --- a/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs +++ b/Jellyfin.Server.Implementations/Trickplay/TrickplayManager.cs @@ -105,7 +105,7 @@ public async Task MoveGeneratedTrickplayDataAsync(Video video, LibraryOptions? l _logger.LogInformation("Moved trickplay images for {ItemName} to {Location}", video.Name, mediaOutputDir); } } - else if (Directory.Exists(mediaOutputDir)) + else if (!shouldBeSavedWithMedia && Directory.Exists(mediaOutputDir)) { var mediaDirFiles = Directory.GetFiles(mediaOutputDir); var localDirExists = Directory.Exists(localOutputDir); From 75bbd3029613829a9b55ac01e27093583fc8cf52 Mon Sep 17 00:00:00 2001 From: gnattu Date: Tue, 24 Sep 2024 22:15:53 +0800 Subject: [PATCH 2/2] Fix get sessions with api key (#12696) --- .../Session/SessionManager.cs | 44 +++++++++++++++---- Jellyfin.Api/Controllers/SessionController.cs | 3 +- .../Session/ISessionManager.cs | 3 +- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs index 55e4856692b4..6a8ad2bdc5b5 100644 --- a/Emby.Server.Implementations/Session/SessionManager.cs +++ b/Emby.Server.Implementations/Session/SessionManager.cs @@ -1858,15 +1858,38 @@ public IReadOnlyList GetSessions( Guid userId, string deviceId, int? activeWithinSeconds, - Guid? controllableUserToCheck) + Guid? controllableUserToCheck, + bool isApiKey) { var result = Sessions; - var user = _userManager.GetUserById(userId); if (!string.IsNullOrEmpty(deviceId)) { result = result.Where(i => string.Equals(i.DeviceId, deviceId, StringComparison.OrdinalIgnoreCase)); } + var userCanControlOthers = false; + var userIsAdmin = false; + User user = null; + + if (isApiKey) + { + userCanControlOthers = true; + userIsAdmin = true; + } + else if (!userId.IsEmpty()) + { + user = _userManager.GetUserById(userId); + if (user is not null) + { + userCanControlOthers = user.HasPermission(PermissionKind.EnableRemoteControlOfOtherUsers); + userIsAdmin = user.HasPermission(PermissionKind.IsAdministrator); + } + else + { + return []; + } + } + if (!controllableUserToCheck.IsNullOrEmpty()) { result = result.Where(i => i.SupportsRemoteControl); @@ -1883,29 +1906,34 @@ public IReadOnlyList GetSessions( result = result.Where(i => !i.UserId.IsEmpty()); } - if (!user.HasPermission(PermissionKind.EnableRemoteControlOfOtherUsers)) + if (!userCanControlOthers) { // User cannot control other user's sessions, validate user id. - result = result.Where(i => i.UserId.IsEmpty() || i.ContainsUser(user.Id)); + result = result.Where(i => i.UserId.IsEmpty() || i.ContainsUser(userId)); } result = result.Where(i => { - if (!string.IsNullOrWhiteSpace(i.DeviceId) && !_deviceManager.CanAccessDevice(user, i.DeviceId)) + if (isApiKey) + { + return true; + } + + if (user is null) { return false; } - return true; + return string.IsNullOrWhiteSpace(i.DeviceId) || _deviceManager.CanAccessDevice(user, i.DeviceId); }); } - else if (!user.HasPermission(PermissionKind.IsAdministrator)) + else if (!userIsAdmin) { // Request isn't from administrator, limit to "own" sessions. result = result.Where(i => i.UserId.IsEmpty() || i.ContainsUser(userId)); } - if (!user.HasPermission(PermissionKind.IsAdministrator)) + if (!userIsAdmin) { // Don't report acceleration type for non-admin users. result = result.Select(r => diff --git a/Jellyfin.Api/Controllers/SessionController.cs b/Jellyfin.Api/Controllers/SessionController.cs index 72eb93eff28d..2f9e9f091d5f 100644 --- a/Jellyfin.Api/Controllers/SessionController.cs +++ b/Jellyfin.Api/Controllers/SessionController.cs @@ -62,7 +62,8 @@ public ActionResult> GetSessions( User.GetUserId(), deviceId, activeWithinSeconds, - controllableUserToCheck); + controllableUserToCheck, + User.GetIsApiKey()); return Ok(result); } diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index f2e98dd78746..462a624553ae 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -300,8 +300,9 @@ public interface ISessionManager /// The device id. /// Active within session limit. /// Filter for sessions remote controllable for this user. + /// Is the request authenticated with API key. /// IReadOnlyList{SessionInfoDto}. - IReadOnlyList GetSessions(Guid userId, string deviceId, int? activeWithinSeconds, Guid? controllableUserToCheck); + IReadOnlyList GetSessions(Guid userId, string deviceId, int? activeWithinSeconds, Guid? controllableUserToCheck, bool isApiKey); /// /// Gets the session by authentication token.