aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Devices
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2021-05-20 23:56:59 -0400
committerPatrick Barron <barronpm@gmail.com>2021-05-20 23:56:59 -0400
commita0c6f7276211ac0429877fafa400368aba1430a9 (patch)
tree498d9caa19eefdf9fd93fdb181535facde652417 /Jellyfin.Server.Implementations/Devices
parentb03f2353d8bb023e659e735e12bd6230f07ca19c (diff)
Migrate authentication db to EF Core
Diffstat (limited to 'Jellyfin.Server.Implementations/Devices')
-rw-r--r--Jellyfin.Server.Implementations/Devices/DeviceManager.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs
index bde8eb86e..9fd2e5ad4 100644
--- a/Jellyfin.Server.Implementations/Devices/DeviceManager.cs
+++ b/Jellyfin.Server.Implementations/Devices/DeviceManager.cs
@@ -6,6 +6,7 @@ using Jellyfin.Data.Entities;
using Jellyfin.Data.Entities.Security;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Events;
+using Jellyfin.Data.Queries;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Devices;
@@ -56,6 +57,17 @@ namespace Jellyfin.Server.Implementations.Devices
}
/// <inheritdoc />
+ public async Task<Device> CreateDevice(Device device)
+ {
+ await using var dbContext = _dbProvider.CreateContext();
+
+ dbContext.Devices.Add(device);
+
+ await dbContext.SaveChangesAsync().ConfigureAwait(false);
+ return device;
+ }
+
+ /// <inheritdoc />
public async Task<DeviceOptions?> GetDeviceOptions(string deviceId)
{
await using var dbContext = _dbProvider.CreateContext();
@@ -91,6 +103,61 @@ namespace Jellyfin.Server.Implementations.Devices
}
/// <inheritdoc />
+ public async Task<QueryResult<Device>> GetDevices(DeviceQuery query)
+ {
+ await using var dbContext = _dbProvider.CreateContext();
+
+ var devices = dbContext.Devices.AsQueryable();
+
+ if (query.UserId.HasValue)
+ {
+ devices = devices.Where(device => device.UserId == query.UserId.Value);
+ }
+
+ if (query.DeviceId != null)
+ {
+ devices = devices.Where(device => device.DeviceId == query.DeviceId);
+ }
+
+ if (query.AccessToken != null)
+ {
+ devices = devices.Where(device => device.AccessToken == query.AccessToken);
+ }
+
+ if (query.Skip.HasValue)
+ {
+ devices = devices.Skip(query.Skip.Value);
+ }
+
+ var count = await devices.CountAsync().ConfigureAwait(false);
+
+ if (query.Limit.HasValue)
+ {
+ devices = devices.Take(query.Limit.Value);
+ }
+
+ return new QueryResult<Device>
+ {
+ Items = await devices.ToListAsync().ConfigureAwait(false),
+ StartIndex = query.Skip ?? 0,
+ TotalRecordCount = count
+ };
+ }
+
+ /// <inheritdoc />
+ public async Task<QueryResult<DeviceInfo>> GetDeviceInfos(DeviceQuery query)
+ {
+ var devices = await GetDevices(query).ConfigureAwait(false);
+
+ return new QueryResult<DeviceInfo>
+ {
+ Items = devices.Items.Select(ToDeviceInfo).ToList(),
+ StartIndex = devices.StartIndex,
+ TotalRecordCount = devices.TotalRecordCount
+ };
+ }
+
+ /// <inheritdoc />
public async Task<QueryResult<DeviceInfo>> GetDevicesForUser(Guid? userId, bool? supportsSync)
{
await using var dbContext = _dbProvider.CreateContext();
@@ -118,6 +185,12 @@ namespace Jellyfin.Server.Implementations.Devices
}
/// <inheritdoc />
+ public async Task DeleteDevice(Device device)
+ {
+ await using var dbContext = _dbProvider.CreateContext();
+ }
+
+ /// <inheritdoc />
public bool CanAccessDevice(User user, string deviceId)
{
if (user == null)