mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-05 14:44:46 -04:00
move to ActionResult<T>
This commit is contained in:
parent
8ab9949db5
commit
88b856796a
@ -14,7 +14,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scheduled Tasks Controller.
|
/// Scheduled Tasks Controller.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authenticated]
|
// [Authenticated]
|
||||||
public class ScheduledTasksController : BaseJellyfinApiController
|
public class ScheduledTasksController : BaseJellyfinApiController
|
||||||
{
|
{
|
||||||
private readonly ITaskManager _taskManager;
|
private readonly ITaskManager _taskManager;
|
||||||
@ -35,47 +35,30 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// <param name="isEnabled">Optional filter tasks that are enabled, or not.</param>
|
/// <param name="isEnabled">Optional filter tasks that are enabled, or not.</param>
|
||||||
/// <returns>Task list.</returns>
|
/// <returns>Task list.</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(TaskInfo[]), StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
public IEnumerable<IScheduledTaskWorker> GetTasks(
|
||||||
public IActionResult GetTasks(
|
|
||||||
[FromQuery] bool? isHidden = false,
|
[FromQuery] bool? isHidden = false,
|
||||||
[FromQuery] bool? isEnabled = false)
|
[FromQuery] bool? isEnabled = false)
|
||||||
{
|
{
|
||||||
IEnumerable<IScheduledTaskWorker> tasks = _taskManager.ScheduledTasks.OrderBy(o => o.Name);
|
IEnumerable<IScheduledTaskWorker> tasks = _taskManager.ScheduledTasks.OrderBy(o => o.Name);
|
||||||
|
|
||||||
if (isHidden.HasValue)
|
foreach (var task in tasks)
|
||||||
{
|
{
|
||||||
var hiddenValue = isHidden.Value;
|
if (task.ScheduledTask is IConfigurableScheduledTask scheduledTask)
|
||||||
tasks = tasks.Where(o =>
|
|
||||||
{
|
{
|
||||||
var itemIsHidden = false;
|
if (isHidden.HasValue && isHidden.Value != scheduledTask.IsHidden)
|
||||||
if (o.ScheduledTask is IConfigurableScheduledTask configurableScheduledTask)
|
|
||||||
{
|
{
|
||||||
itemIsHidden = configurableScheduledTask.IsHidden;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemIsHidden == hiddenValue;
|
if (isEnabled.HasValue && isEnabled.Value != scheduledTask.IsEnabled)
|
||||||
});
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnabled.HasValue)
|
yield return task;
|
||||||
{
|
|
||||||
var enabledValue = isEnabled.Value;
|
|
||||||
tasks = tasks.Where(o =>
|
|
||||||
{
|
|
||||||
var itemIsEnabled = false;
|
|
||||||
if (o.ScheduledTask is IConfigurableScheduledTask configurableScheduledTask)
|
|
||||||
{
|
|
||||||
itemIsEnabled = configurableScheduledTask.IsEnabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return itemIsEnabled == enabledValue;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var taskInfos = tasks.Select(ScheduledTaskHelpers.GetTaskInfo);
|
|
||||||
|
|
||||||
return Ok(taskInfos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -84,10 +67,9 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// <param name="taskId">Task Id.</param>
|
/// <param name="taskId">Task Id.</param>
|
||||||
/// <returns>Task Info.</returns>
|
/// <returns>Task Info.</returns>
|
||||||
[HttpGet("{TaskID}")]
|
[HttpGet("{TaskID}")]
|
||||||
[ProducesResponseType(typeof(TaskInfo), StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
public ActionResult<TaskInfo> GetTask([FromRoute] string taskId)
|
||||||
public IActionResult GetTask([FromRoute] string taskId)
|
|
||||||
{
|
{
|
||||||
var task = _taskManager.ScheduledTasks.FirstOrDefault(i =>
|
var task = _taskManager.ScheduledTasks.FirstOrDefault(i =>
|
||||||
string.Equals(i.Id, taskId, StringComparison.OrdinalIgnoreCase));
|
string.Equals(i.Id, taskId, StringComparison.OrdinalIgnoreCase));
|
||||||
@ -109,8 +91,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[HttpPost("Running/{TaskID}")]
|
[HttpPost("Running/{TaskID}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
public ActionResult StartTask([FromRoute] string taskId)
|
||||||
public IActionResult StartTask([FromRoute] string taskId)
|
|
||||||
{
|
{
|
||||||
var task = _taskManager.ScheduledTasks.FirstOrDefault(o =>
|
var task = _taskManager.ScheduledTasks.FirstOrDefault(o =>
|
||||||
o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase));
|
o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase));
|
||||||
@ -132,8 +113,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[HttpDelete("Running/{TaskID}")]
|
[HttpDelete("Running/{TaskID}")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
public ActionResult StopTask([FromRoute] string taskId)
|
||||||
public IActionResult StopTask([FromRoute] string taskId)
|
|
||||||
{
|
{
|
||||||
var task = _taskManager.ScheduledTasks.FirstOrDefault(o =>
|
var task = _taskManager.ScheduledTasks.FirstOrDefault(o =>
|
||||||
o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase));
|
o.Id.Equals(taskId, StringComparison.OrdinalIgnoreCase));
|
||||||
@ -156,8 +136,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[HttpPost("{TaskID}/Triggers")]
|
[HttpPost("{TaskID}/Triggers")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
|
public ActionResult UpdateTask(
|
||||||
public IActionResult UpdateTask(
|
|
||||||
[FromRoute] string taskId,
|
[FromRoute] string taskId,
|
||||||
[FromBody, BindRequired] TaskTriggerInfo[] triggerInfos)
|
[FromBody, BindRequired] TaskTriggerInfo[] triggerInfos)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user