aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller/TaskProcessingApiController.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Controller/TaskProcessingApiController.php')
-rw-r--r--core/Controller/TaskProcessingApiController.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php
index 6a88ff9a731..9e0d7947a3a 100644
--- a/core/Controller/TaskProcessingApiController.php
+++ b/core/Controller/TaskProcessingApiController.php
@@ -360,4 +360,36 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}
+
+ /**
+ * This endpoint cancels a task
+ *
+ * @param int $taskId The id of the task
+ * @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
+ *
+ * 200: File content returned
+ * 404: Task not found
+ */
+ #[NoAdminRequired]
+ #[ApiRoute(verb: 'POST', url: '/tasks/{taskId}/cancel', root: '/taskprocessing')]
+ public function cancelTask(int $taskId): DataResponse {
+ try {
+ // Check if the current user can access the task
+ $this->taskProcessingManager->getUserTask($taskId, $this->userId);
+ // set result
+ $this->taskProcessingManager->cancelTask($taskId);
+ $task = $this->taskProcessingManager->getUserTask($taskId, $this->userId);
+
+ /** @var CoreTaskProcessingTask $json */
+ $json = $task->jsonSerialize();
+
+ return new DataResponse([
+ 'task' => $json,
+ ]);
+ } catch (\OCP\TaskProcessing\Exception\NotFoundException $e) {
+ return new DataResponse(['message' => $this->l->t('Not found')], Http::STATUS_NOT_FOUND);
+ } catch (Exception $e) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
+ }
+ }
}