mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-22 00:27:09 +01:00
Have device deletion take list of ids (#12834)
* add delete multiple devices via id * make atomic * use Add * Update Jellyfin.Api/Controllers/DevicesController.cs Co-authored-by: JPVenson <ger-delta-07@hotmail.de> * remove model binding, use functional device selection * use singular id * use BadRequest instead --------- Co-authored-by: JPVenson <ger-delta-07@hotmail.de>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Api.Attributes;
|
||||
using Jellyfin.Api.Helpers;
|
||||
using Jellyfin.Api.ModelBinders;
|
||||
using Jellyfin.Data.Dtos;
|
||||
using Jellyfin.Data.Queries;
|
||||
using MediaBrowser.Common.Api;
|
||||
@@ -112,28 +116,31 @@ public class DevicesController : BaseJellyfinApiController
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a device.
|
||||
/// Deletes devices.
|
||||
/// </summary>
|
||||
/// <param name="id">Device Id.</param>
|
||||
/// <param name="id">Device Ids.</param>
|
||||
/// <response code="204">Device deleted.</response>
|
||||
/// <response code="404">Device not found.</response>
|
||||
/// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="NotFoundResult"/> if the device could not be found.</returns>
|
||||
/// <response code="400">A requested device is invalid.</response>
|
||||
/// <returns>A <see cref="NoContentResult"/> on success, or a <see cref="BadRequestResult"/> if a requested device is invalid.</returns>
|
||||
[HttpDelete]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> DeleteDevice([FromQuery, Required] string id)
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<ActionResult> DeleteDevice([FromQuery] string[] id)
|
||||
{
|
||||
var existingDevice = _deviceManager.GetDevice(id);
|
||||
if (existingDevice is null)
|
||||
var devices = id.Select(_deviceManager.GetDevice).ToArray();
|
||||
if (devices.Any(f => f is null))
|
||||
{
|
||||
return NotFound();
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var sessions = _deviceManager.GetDevices(new DeviceQuery { DeviceId = id });
|
||||
|
||||
foreach (var session in sessions.Items)
|
||||
foreach (var device in devices)
|
||||
{
|
||||
await _sessionManager.Logout(session).ConfigureAwait(false);
|
||||
var sessions = _deviceManager.GetDevices(new DeviceQuery { DeviceId = device!.Id });
|
||||
|
||||
foreach (var session in sessions.Items)
|
||||
{
|
||||
await _sessionManager.Logout(session).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
|
||||
Reference in New Issue
Block a user