aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Controller/TaskProcessingApiController.php57
-rw-r--r--core/openapi-ex_app.json197
-rw-r--r--core/openapi-full.json197
3 files changed, 447 insertions, 4 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php
index 90ee650f1ed..d9bcbd5da45 100644
--- a/core/Controller/TaskProcessingApiController.php
+++ b/core/Controller/TaskProcessingApiController.php
@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace OC\Core\Controller;
use OC\Core\ResponseDefinitions;
+use OC\Files\SimpleFS\SimpleFile;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
use OCP\AppFramework\Http\Attribute\ApiRoute;
@@ -22,6 +23,7 @@ use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\Files\File;
use OCP\Files\GenericFileException;
+use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IL10N;
@@ -50,6 +52,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
private IL10N $l,
private ?string $userId,
private IRootFolder $rootFolder,
+ private IAppData $appData,
) {
parent::__construct($appName, $request);
}
@@ -287,6 +290,40 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
}
/**
+ * Upload a file so it can be referenced in a task result (ExApp route version)
+ *
+ * Use field 'file' for the file upload
+ *
+ * @param int $taskId The id of the task
+ * @return DataResponse<Http::STATUS_CREATED, array{fileId: int}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
+ *
+ * 201: File created
+ * 400: File upload failed or no file was uploaded
+ * 404: Task not found
+ */
+ #[ExAppRequired]
+ #[ApiRoute(verb: 'POST', url: '/tasks_provider/{taskId}/file', root: '/taskprocessing')]
+ public function setFileContentsExApp(int $taskId): DataResponse {
+ try {
+ $task = $this->taskProcessingManager->getTask($taskId);
+ $file = $this->request->getUploadedFile('file');
+ if (!isset($file['tmp_name'])) {
+ return new DataResponse(['message' => $this->l->t('Bad request')], Http::STATUS_BAD_REQUEST);
+ }
+ $handle = fopen($file['tmp_name'], 'r');
+ if (!$handle) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
+ }
+ $fileId = $this->setFileContentsInternal($handle);
+ return new DataResponse(['fileId' => $fileId], Http::STATUS_CREATED);
+ } catch (NotFoundException) {
+ return new DataResponse(['message' => $this->l->t('Not found')], Http::STATUS_NOT_FOUND);
+ } catch (Exception) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
+ }
+ }
+
+ /**
* @throws NotPermittedException
* @throws NotFoundException
* @throws GenericFileException
@@ -384,7 +421,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
* Sets the task result
*
* @param int $taskId The id of the task
- * @param array<string,mixed>|null $output The resulting task output
+ * @param array<string,mixed>|null $output The resulting task output, files are represented by their IDs
* @param string|null $errorMessage An error message if the task failed
* @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
@@ -396,7 +433,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
public function setResult(int $taskId, ?array $output = null, ?string $errorMessage = null): DataResponse {
try {
// set result
- $this->taskProcessingManager->setTaskResult($taskId, $errorMessage, $output);
+ $this->taskProcessingManager->setTaskResult($taskId, $errorMessage, $output, true);
$task = $this->taskProcessingManager->getTask($taskId);
/** @var CoreTaskProcessingTask $json */
@@ -493,4 +530,20 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}
+
+ /**
+ * @param resource $data
+ * @return int
+ * @throws NotPermittedException
+ */
+ private function setFileContentsInternal($data): int {
+ try {
+ $folder = $this->appData->getFolder('TaskProcessing');
+ } catch (\OCP\Files\NotFoundException) {
+ $folder = $this->appData->newFolder('TaskProcessing');
+ }
+ /** @var SimpleFile $file */
+ $file = $folder->newFile(time() . '-' . rand(1, 100000), $data);
+ return $file->getId();
+ }
}
diff --git a/core/openapi-ex_app.json b/core/openapi-ex_app.json
index e0cf06753de..3f5de516172 100644
--- a/core/openapi-ex_app.json
+++ b/core/openapi-ex_app.json
@@ -339,6 +339,201 @@
}
}
},
+ "/ocs/v2.php/taskprocessing/tasks_provider/{taskId}/file": {
+ "post": {
+ "operationId": "task_processing_api-set-file-contents-ex-app",
+ "summary": "Upload a file so it can be referenced in a task result (ExApp route version)",
+ "description": "Use field 'file' for the file upload\nThis endpoint requires admin access",
+ "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": {
+ "201": {
+ "description": "File created",
+ "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": [
+ "fileId"
+ ],
+ "properties": {
+ "fileId": {
+ "type": "integer",
+ "format": "int64"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "File upload failed or no file was uploaded",
+ "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"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "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/taskprocessing/tasks_provider/{taskId}/progress": {
"post": {
"operationId": "task_processing_api-set-progress",
@@ -541,7 +736,7 @@
"output": {
"type": "object",
"nullable": true,
- "description": "The resulting task output",
+ "description": "The resulting task output, files are represented by their IDs",
"additionalProperties": {
"type": "object"
}
diff --git a/core/openapi-full.json b/core/openapi-full.json
index a62e587bf06..290dc462cdc 100644
--- a/core/openapi-full.json
+++ b/core/openapi-full.json
@@ -8597,6 +8597,201 @@
}
}
},
+ "/ocs/v2.php/taskprocessing/tasks_provider/{taskId}/file": {
+ "post": {
+ "operationId": "task_processing_api-set-file-contents-ex-app",
+ "summary": "Upload a file so it can be referenced in a task result (ExApp route version)",
+ "description": "Use field 'file' for the file upload\nThis endpoint requires admin access",
+ "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": {
+ "201": {
+ "description": "File created",
+ "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": [
+ "fileId"
+ ],
+ "properties": {
+ "fileId": {
+ "type": "integer",
+ "format": "int64"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "File upload failed or no file was uploaded",
+ "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"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "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/taskprocessing/tasks_provider/{taskId}/progress": {
"post": {
"operationId": "task_processing_api-set-progress",
@@ -8799,7 +8994,7 @@
"output": {
"type": "object",
"nullable": true,
- "description": "The resulting task output",
+ "description": "The resulting task output, files are represented by their IDs",
"additionalProperties": {
"type": "object"
}