mirror of https://github.com/jellyfin/jellyfin.git
Merge 8cc8e83750
into 5612cb8178
This commit is contained in:
commit
86b5db2fa9
|
@ -55,6 +55,7 @@ public class SessionController : BaseJellyfinApiController
|
|||
/// <param name="controllableByUserId">Filter by sessions that a given user is allowed to remote control.</param>
|
||||
/// <param name="deviceId">Filter by device Id.</param>
|
||||
/// <param name="activeWithinSeconds">Optional. Filter by sessions that were active in the last n seconds.</param>
|
||||
/// <param name="nowPlaying">Optional. Filter by sessions that are currently playing content.</param>
|
||||
/// <response code="200">List of sessions returned.</response>
|
||||
/// <returns>An <see cref="IEnumerable{SessionInfo}"/> with the available sessions.</returns>
|
||||
[HttpGet("Sessions")]
|
||||
|
@ -63,7 +64,8 @@ public class SessionController : BaseJellyfinApiController
|
|||
public ActionResult<IEnumerable<SessionInfo>> GetSessions(
|
||||
[FromQuery] Guid? controllableByUserId,
|
||||
[FromQuery] string? deviceId,
|
||||
[FromQuery] int? activeWithinSeconds)
|
||||
[FromQuery] int? activeWithinSeconds,
|
||||
[FromQuery] bool? nowPlaying)
|
||||
{
|
||||
var result = _sessionManager.Sessions;
|
||||
|
||||
|
@ -118,6 +120,13 @@ public class SessionController : BaseJellyfinApiController
|
|||
result = result.Where(i => i.LastActivityDate >= minActiveDate);
|
||||
}
|
||||
|
||||
if (nowPlaying.HasValue)
|
||||
{
|
||||
result = nowPlaying.Value
|
||||
? result.Where(i => i.NowPlayingItem != null)
|
||||
: result.Where(i => i.NowPlayingItem == null);
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
@ -24,4 +24,18 @@ public class SessionControllerTests : IClassFixture<JellyfinApplicationFactory>
|
|||
using var response = await client.GetAsync($"Sessions?controllableByUserId={Guid.NewGuid()}");
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("?nowPlaying=false")]
|
||||
[InlineData("?nowPlaying=true")]
|
||||
[InlineData("")]
|
||||
public async Task GetSessions_NowPlaying_Ok(string querystring)
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
client.DefaultRequestHeaders.AddAuthHeader(_accessToken ??= await AuthHelper.CompleteStartupAsync(client).ConfigureAwait(false));
|
||||
|
||||
using var response = await client.GetAsync($"Sessions{querystring}").ConfigureAwait(false);
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue