From 1535f363b28ab7e57354f2724f5f1900a000b5cc Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 3 Aug 2020 13:33:43 -0600 Subject: [PATCH] Fix some request parameters --- Jellyfin.Api/Auth/BaseAuthorizationHandler.cs | 3 +- .../Controllers/LibraryStructureController.cs | 4 +- Jellyfin.Api/Controllers/LiveTvController.cs | 1 - .../Controllers/MediaInfoController.cs | 13 ++-- Jellyfin.Api/Helpers/RequestHelpers.cs | 1 - .../Models/MediaInfoDtos/OpenLiveStreamDto.cs | 24 ++++++++ .../SessionInfoWebSocketListener.cs | 60 +++++++++---------- 7 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs diff --git a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs index 495ff9d128..aa366f5672 100644 --- a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs +++ b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs @@ -1,5 +1,4 @@ -using System.Net; -using System.Security.Claims; +using System.Security.Claims; using Jellyfin.Api.Helpers; using Jellyfin.Data.Enums; using MediaBrowser.Common.Net; diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs index b7f3c9b07c..827879e0a8 100644 --- a/Jellyfin.Api/Controllers/LibraryStructureController.cs +++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs @@ -249,7 +249,7 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult UpdateMediaPath( [FromQuery] string? name, - [FromQuery] MediaPathInfo? pathInfo) + [FromBody] MediaPathInfo? pathInfo) { if (string.IsNullOrWhiteSpace(name)) { @@ -320,7 +320,7 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status204NoContent)] public ActionResult UpdateLibraryOptions( [FromQuery] string? id, - [FromQuery] LibraryOptions? libraryOptions) + [FromBody] LibraryOptions? libraryOptions) { var collectionFolder = (CollectionFolder)_libraryManager.GetItemById(id); diff --git a/Jellyfin.Api/Controllers/LiveTvController.cs b/Jellyfin.Api/Controllers/LiveTvController.cs index 9144d6f285..bbe5544f93 100644 --- a/Jellyfin.Api/Controllers/LiveTvController.cs +++ b/Jellyfin.Api/Controllers/LiveTvController.cs @@ -23,7 +23,6 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Net; using MediaBrowser.Model.Querying; diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs index 57aff21b0a..5b0f46b02e 100644 --- a/Jellyfin.Api/Controllers/MediaInfoController.cs +++ b/Jellyfin.Api/Controllers/MediaInfoController.cs @@ -7,6 +7,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Jellyfin.Api.Constants; +using Jellyfin.Api.Models.MediaInfoDtos; using Jellyfin.Api.Models.VideoDtos; using Jellyfin.Data.Entities; using Jellyfin.Data.Enums; @@ -91,7 +92,7 @@ namespace Jellyfin.Api.Controllers [ProducesResponseType(StatusCodes.Status200OK)] public async Task> GetPlaybackInfo([FromRoute] Guid itemId, [FromQuery] Guid? userId) { - return await GetPlaybackInfoInternal(itemId, userId, null, null).ConfigureAwait(false); + return await GetPlaybackInfoInternal(itemId, userId).ConfigureAwait(false); } /// @@ -231,8 +232,7 @@ namespace Jellyfin.Api.Controllers /// The subtitle stream index. /// The maximum number of audio channels. /// The item id. - /// The device profile. - /// The direct play protocols. Default: . + /// The open live stream dto. /// Whether to enable direct play. Default: true. /// Whether to enable direct stream. Default: true. /// Media source opened. @@ -249,8 +249,7 @@ namespace Jellyfin.Api.Controllers [FromQuery] int? subtitleStreamIndex, [FromQuery] int? maxAudioChannels, [FromQuery] Guid? itemId, - [FromQuery] DeviceProfile? deviceProfile, - [FromQuery] MediaProtocol[] directPlayProtocols, + [FromBody] OpenLiveStreamDto openLiveStreamDto, [FromQuery] bool enableDirectPlay = true, [FromQuery] bool enableDirectStream = true) { @@ -265,10 +264,10 @@ namespace Jellyfin.Api.Controllers SubtitleStreamIndex = subtitleStreamIndex, MaxAudioChannels = maxAudioChannels, ItemId = itemId ?? Guid.Empty, - DeviceProfile = deviceProfile, + DeviceProfile = openLiveStreamDto?.DeviceProfile, EnableDirectPlay = enableDirectPlay, EnableDirectStream = enableDirectStream, - DirectPlayProtocols = directPlayProtocols ?? new[] { MediaProtocol.Http } + DirectPlayProtocols = openLiveStreamDto?.DirectPlayProtocols ?? new[] { MediaProtocol.Http } }; return await OpenMediaSource(request).ConfigureAwait(false); } diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs index d9e993d496..fbaa692700 100644 --- a/Jellyfin.Api/Helpers/RequestHelpers.cs +++ b/Jellyfin.Api/Helpers/RequestHelpers.cs @@ -5,7 +5,6 @@ using System.Net; using Jellyfin.Data.Enums; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Session; -using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; using Microsoft.AspNetCore.Http; diff --git a/Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs b/Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs new file mode 100644 index 0000000000..f797a38076 --- /dev/null +++ b/Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs @@ -0,0 +1,24 @@ +using System.Diagnostics.CodeAnalysis; +using MediaBrowser.Model.Dlna; +using MediaBrowser.Model.MediaInfo; + +namespace Jellyfin.Api.Models.MediaInfoDtos +{ + /// + /// Open live stream dto. + /// + public class OpenLiveStreamDto + { + /// + /// Gets or sets the device profile. + /// + public DeviceProfile? DeviceProfile { get; set; } + + /// + /// Gets or sets the device play protocols. + /// + [SuppressMessage("Microsoft.Performance", "CA1819:DontReturnArrays", MessageId = "DevicePlayProtocols", Justification = "Imported from ServiceStack")] + [SuppressMessage("Microsoft.Performance", "SA1011:ClosingBracketsSpace", MessageId = "DevicePlayProtocols", Justification = "Imported from ServiceStack")] + public MediaProtocol[]? DirectPlayProtocols { get; set; } + } +} diff --git a/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs index ab9f789a16..1fb5dc412c 100644 --- a/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs +++ b/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs @@ -12,20 +12,13 @@ namespace Jellyfin.Api.WebSocketListeners /// public class SessionInfoWebSocketListener : BasePeriodicWebSocketListener, WebSocketListenerState> { - /// - /// Gets the name. - /// - /// The name. - protected override string Name => "Sessions"; - - /// - /// The _kernel. - /// private readonly ISessionManager _sessionManager; /// /// Initializes a new instance of the class. /// + /// Instance of the interface. + /// Instance of the interface. public SessionInfoWebSocketListener(ILogger logger, ISessionManager sessionManager) : base(logger) { @@ -40,6 +33,32 @@ namespace Jellyfin.Api.WebSocketListeners _sessionManager.SessionActivity += OnSessionManagerSessionActivity; } + /// + protected override string Name => "Sessions"; + + /// + /// Gets the data to send. + /// + /// Task{SystemInfo}. + protected override Task> GetDataToSend() + { + return Task.FromResult(_sessionManager.Sessions); + } + + /// + protected override void Dispose(bool dispose) + { + _sessionManager.SessionStarted -= OnSessionManagerSessionStarted; + _sessionManager.SessionEnded -= OnSessionManagerSessionEnded; + _sessionManager.PlaybackStart -= OnSessionManagerPlaybackStart; + _sessionManager.PlaybackStopped -= OnSessionManagerPlaybackStopped; + _sessionManager.PlaybackProgress -= OnSessionManagerPlaybackProgress; + _sessionManager.CapabilitiesChanged -= OnSessionManagerCapabilitiesChanged; + _sessionManager.SessionActivity -= OnSessionManagerSessionActivity; + + base.Dispose(dispose); + } + private async void OnSessionManagerSessionActivity(object sender, SessionEventArgs e) { await SendData(false).ConfigureAwait(false); @@ -74,28 +93,5 @@ namespace Jellyfin.Api.WebSocketListeners { await SendData(true).ConfigureAwait(false); } - - /// - /// Gets the data to send. - /// - /// Task{SystemInfo}. - protected override Task> GetDataToSend() - { - return Task.FromResult(_sessionManager.Sessions); - } - - /// - protected override void Dispose(bool dispose) - { - _sessionManager.SessionStarted -= OnSessionManagerSessionStarted; - _sessionManager.SessionEnded -= OnSessionManagerSessionEnded; - _sessionManager.PlaybackStart -= OnSessionManagerPlaybackStart; - _sessionManager.PlaybackStopped -= OnSessionManagerPlaybackStopped; - _sessionManager.PlaybackProgress -= OnSessionManagerPlaybackProgress; - _sessionManager.CapabilitiesChanged -= OnSessionManagerCapabilitiesChanged; - _sessionManager.SessionActivity -= OnSessionManagerSessionActivity; - - base.Dispose(dispose); - } } }