diff --git a/src/Kyoo.Abstractions/Models/Utils/Constants.cs b/src/Kyoo.Abstractions/Models/Utils/Constants.cs
index 985f0254..7f857df1 100644
--- a/src/Kyoo.Abstractions/Models/Utils/Constants.cs
+++ b/src/Kyoo.Abstractions/Models/Utils/Constants.cs
@@ -46,5 +46,10 @@ namespace Kyoo.Abstractions.Models.Utils
/// A group name for . It should be used for endpoints useful for playback.
///
public const string WatchGroup = "2:Watch";
+
+ ///
+ /// A group name for . It should be used for endpoints used by admins.
+ ///
+ public const string AdminGroup = "3:Admin";
}
}
diff --git a/src/Kyoo.Core/Views/Admin/TaskApi.cs b/src/Kyoo.Core/Views/Admin/TaskApi.cs
new file mode 100644
index 00000000..310cad81
--- /dev/null
+++ b/src/Kyoo.Core/Views/Admin/TaskApi.cs
@@ -0,0 +1,108 @@
+// Kyoo - A portable and vast media library solution.
+// Copyright (c) Kyoo.
+//
+// See AUTHORS.md and LICENSE file in the project root for full license information.
+//
+// Kyoo is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// Kyoo is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Kyoo. If not, see .
+
+using System;
+using System.Collections.Generic;
+using Kyoo.Abstractions.Controllers;
+using Kyoo.Abstractions.Models.Attributes;
+using Kyoo.Abstractions.Models.Exceptions;
+using Kyoo.Abstractions.Models.Permissions;
+using Kyoo.Abstractions.Models.Utils;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using static Kyoo.Abstractions.Models.Utils.Constants;
+
+namespace Kyoo.Core.Api
+{
+ ///
+ /// An endpoint to list and run tasks in the background.
+ ///
+ [Route("api/tasks")]
+ [Route("api/task", Order = AlternativeRoute)]
+ [ApiController]
+ [ResourceView]
+ [PartialPermission(nameof(TaskApi), Group = Group.Admin)]
+ [ApiDefinition("Tasks", Group = AdminGroup)]
+ public class TaskApi : ControllerBase
+ {
+ ///
+ /// The task manager used to retrieve and start tasks.
+ ///
+ private readonly ITaskManager _taskManager;
+
+ ///
+ /// Create a new .
+ ///
+ /// The task manager used to start tasks.
+ public TaskApi(ITaskManager taskManager)
+ {
+ _taskManager = taskManager;
+ }
+
+ ///
+ /// Get all tasks
+ ///
+ ///
+ /// Retrieve all tasks available in this instance of Kyoo.
+ ///
+ /// A list of every tasks that this instance know.
+ [HttpGet]
+ [PartialPermission(Kind.Read)]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ public ActionResult> GetTasks()
+ {
+ return Ok(_taskManager.GetAllTasks());
+ }
+
+ ///
+ /// Start task
+ ///
+ ///
+ /// Start a task with the given arguments. If a task is already running, it may be queued and started only when
+ /// a runner become available.
+ ///
+ /// The slug of the task to start.
+ /// The list of arguments to give to the task.
+ /// The task has been started or is queued.
+ /// The task misses an argument or an argument is invalid.
+ /// No task could be found with the given slug.
+ [HttpPut("{taskSlug}")]
+ [HttpGet("{taskSlug}", Order = AlternativeRoute)]
+ [PartialPermission(Kind.Create)]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ public IActionResult RunTask(string taskSlug,
+ [FromQuery] Dictionary args)
+ {
+ try
+ {
+ _taskManager.StartTask(taskSlug, new Progress(), args);
+ return Ok();
+ }
+ catch (ItemNotFoundException)
+ {
+ return NotFound();
+ }
+ catch (ArgumentException ex)
+ {
+ return BadRequest(new RequestError(ex.Message));
+ }
+ }
+ }
+}
diff --git a/src/Kyoo.Core/Views/TaskApi.cs b/src/Kyoo.Core/Views/TaskApi.cs
deleted file mode 100644
index d7b91427..00000000
--- a/src/Kyoo.Core/Views/TaskApi.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-// Kyoo - A portable and vast media library solution.
-// Copyright (c) Kyoo.
-//
-// See AUTHORS.md and LICENSE file in the project root for full license information.
-//
-// Kyoo is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// any later version.
-//
-// Kyoo is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Kyoo. If not, see .
-
-using System;
-using System.Collections.Generic;
-using Kyoo.Abstractions.Controllers;
-using Kyoo.Abstractions.Models.Exceptions;
-using Kyoo.Abstractions.Models.Permissions;
-using Microsoft.AspNetCore.Mvc;
-
-namespace Kyoo.Core.Api
-{
- [Route("api/task")]
- [Route("api/tasks")]
- [ApiController]
- public class TaskApi : ControllerBase
- {
- private readonly ITaskManager _taskManager;
-
- public TaskApi(ITaskManager taskManager)
- {
- _taskManager = taskManager;
- }
-
- [HttpGet]
- [Permission(nameof(TaskApi), Kind.Read)]
- public ActionResult> GetTasks()
- {
- return Ok(_taskManager.GetAllTasks());
- }
-
- [HttpGet("{taskSlug}")]
- [HttpPut("{taskSlug}")]
- [Permission(nameof(TaskApi), Kind.Create)]
- public IActionResult RunTask(string taskSlug, [FromQuery] Dictionary args)
- {
- try
- {
- _taskManager.StartTask(taskSlug, new Progress(), args);
- return Ok();
- }
- catch (ItemNotFoundException)
- {
- return NotFound();
- }
- catch (ArgumentException ex)
- {
- return BadRequest(new { Error = ex.Message });
- }
- }
- }
-}
diff --git a/src/Kyoo.Core/Views/SubtitleApi.cs b/src/Kyoo.Core/Views/Watch/SubtitleApi.cs
similarity index 100%
rename from src/Kyoo.Core/Views/SubtitleApi.cs
rename to src/Kyoo.Core/Views/Watch/SubtitleApi.cs