aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2024-05-07 13:23:53 +0200
committerMarcel Klehr <mklehr@gmx.net>2024-05-14 11:38:41 +0200
commitc079a611815d973157be0a93b10c85e5cb505b38 (patch)
tree71fda454a765a6821577ca8167b923696983c8ea /core
parentf2ab6cb0a9af462df5d8dd00f6487db2efcdea66 (diff)
downloadnextcloud-server-c079a611815d973157be0a93b10c85e5cb505b38.tar.gz
nextcloud-server-c079a611815d973157be0a93b10c85e5cb505b38.zip
feat: Add cancel endpoint to OCS API
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'core')
-rw-r--r--core/Controller/TaskProcessingApiController.php32
-rw-r--r--core/openapi.json155
2 files changed, 187 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);
+ }
+ }
}
diff --git a/core/openapi.json b/core/openapi.json
index ae64ec1e33d..eeb366f3031 100644
--- a/core/openapi.json
+++ b/core/openapi.json
@@ -4551,6 +4551,161 @@
}
}
},
+ "/ocs/v2.php/taskprocessing/tasks/{taskId}/cancel": {
+ "post": {
+ "operationId": "task_processing_api-cancel-task",
+ "summary": "This endpoint cancels a task",
+ "tags": [
+ "task_processing_api"
+ ],
+ "security": [
+ {
+ "bearer_auth": []
+ },
+ {
+ "basic_auth": []
+ }
+ ],
+ "parameters": [
+ {
+ "name": "taskId",
+ "in": "path",
+ "description": "The id of the task",
+ "required": true,
+ "schema": {
+ "type": "integer",
+ "format": "int64"
+ }
+ },
+ {
+ "name": "OCS-APIRequest",
+ "in": "header",
+ "description": "Required to be true for the API request to pass",
+ "required": true,
+ "schema": {
+ "type": "boolean",
+ "default": true
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "File content returned",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "ocs"
+ ],
+ "properties": {
+ "ocs": {
+ "type": "object",
+ "required": [
+ "meta",
+ "data"
+ ],
+ "properties": {
+ "meta": {
+ "$ref": "#/components/schemas/OCSMeta"
+ },
+ "data": {
+ "type": "object",
+ "required": [
+ "task"
+ ],
+ "properties": {
+ "task": {
+ "$ref": "#/components/schemas/TaskProcessingTask"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "ocs"
+ ],
+ "properties": {
+ "ocs": {
+ "type": "object",
+ "required": [
+ "meta",
+ "data"
+ ],
+ "properties": {
+ "meta": {
+ "$ref": "#/components/schemas/OCSMeta"
+ },
+ "data": {
+ "type": "object",
+ "required": [
+ "message"
+ ],
+ "properties": {
+ "message": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "Task not found",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "required": [
+ "ocs"
+ ],
+ "properties": {
+ "ocs": {
+ "type": "object",
+ "required": [
+ "meta",
+ "data"
+ ],
+ "properties": {
+ "meta": {
+ "$ref": "#/components/schemas/OCSMeta"
+ },
+ "data": {
+ "type": "object",
+ "required": [
+ "message"
+ ],
+ "properties": {
+ "message": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/ocs/v2.php/teams/{teamId}/resources": {
"get": {
"operationId": "teams_api-resolve-one",