feat: Add ExApp endpoints

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
pull/45094/head
Marcel Klehr 4 weeks ago
parent 7a947980db
commit 8e5662602a

@ -98,7 +98,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
/**
* This endpoint allows scheduling a task
*
* @param array<array-key, mixed> $input Input text
* @param array<string, mixed> $input Input text
* @param string $type Type of the task
* @param string $appId ID of the app that will execute the task
* @param string $identifier An arbitrary identifier for the task
@ -118,6 +118,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
try {
$this->taskProcessingManager->scheduleTask($task);
/** @var CoreTaskProcessingTask $json */
$json = $task->jsonSerialize();
return new DataResponse([
@ -149,6 +150,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
try {
$task = $this->taskProcessingManager->getUserTask($id, $this->userId);
/** @var CoreTaskProcessingTask $json */
$json = $task->jsonSerialize();
return new DataResponse([
@ -255,7 +257,7 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
/**
* @param Task $task
* @return array
* @return list<mixed>
* @throws \OCP\TaskProcessing\Exception\NotFoundException
*/
private function extractFileIdsFromTask(Task $task) {
@ -270,11 +272,75 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
$ids[] = $task->getInput()[$key];
}
}
foreach ($taskType['outputShape'] + $taskType['optionalOutputShape'] as $key => $descriptor) {
if (in_array(EShapeType::getScalarType($descriptor->getShapeType()), [EShapeType::File, EShapeType::Image, EShapeType::Audio, EShapeType::Video], true)) {
$ids[] = $task->getOutput()[$key];
if ($task->getOutput() !== null) {
foreach ($taskType['outputShape'] + $taskType['optionalOutputShape'] as $key => $descriptor) {
if (in_array(EShapeType::getScalarType($descriptor->getShapeType()), [EShapeType::File, EShapeType::Image, EShapeType::Audio, EShapeType::Video], true)) {
$ids[] = $task->getOutput()[$key];
}
}
}
return $ids;
}
/**
* This endpoint sets the task progress
*
* @param int $taskId The id of the task
* @param float $progress The progress
* @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}/progress', root: '/taskprocessing')]
public function setProgress(int $taskId, float $progress): DataResponse {
try {
$this->taskProcessingManager->setTaskProgress($taskId, $progress);
$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);
}
}
/**
* This endpoint sets the task progress
*
* @param int $taskId The id of the task
* @param array<string,mixed>|null $output The resulting task output
* @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{}>
*
* 200: File content returned
* 404: Task not found
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'POST', url: '/tasks/{taskId}/result', root: '/taskprocessing')]
public function setResult(int $taskId, ?array $output = null, ?string $errorMessage = null): DataResponse {
try {
$this->taskProcessingManager->getUserTask($taskId, $this->userId);
$this->taskProcessingManager->setTaskResult($taskId, $errorMessage, $output);
$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);
}
}
}

@ -197,8 +197,8 @@ namespace OCA\Core;
* status: 0|1|2|3|4|5,
* userId: ?string,
* appId: string,
* input: ?array<array-key, mixed>,
* output: ?array<array-key, mixed>,
* input: ?array<string, mixed>,
* output: ?array<string, mixed>,
* identifier: ?string,
* completionExpectedAt: ?int,
* progress: ?float

@ -507,7 +507,15 @@
},
"status": {
"type": "integer",
"format": "int64"
"format": "int64",
"enum": [
0,
1,
2,
3,
4,
5
]
},
"userId": {
"type": "string",
@ -518,6 +526,7 @@
},
"input": {
"type": "object",
"nullable": true,
"additionalProperties": {
"type": "object"
}
@ -3792,6 +3801,36 @@
"responses": {
"200": {
"description": "Task 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"
}
}
}
}
}
}
}
},
"500": {
"description": "",
"content": {
"application/json": {
"schema": {
@ -3813,11 +3852,11 @@
"data": {
"type": "object",
"required": [
"task"
"message"
],
"properties": {
"task": {
"$ref": "#/components/schemas/TaskProcessingTask"
"message": {
"type": "string"
}
}
}
@ -3827,9 +3866,58 @@
}
}
}
}
}
}
},
"/ocs/v2.php/taskprocessing/tasks/app/{appId}": {
"get": {
"operationId": "task_processing_api-list-tasks-by-app",
"summary": "This endpoint returns a list of tasks of a user that are related with a specific appId and optionally with an identifier",
"tags": [
"task_processing_api"
],
"security": [
{
"bearer_auth": []
},
"404": {
"description": "Task not found",
{
"basic_auth": []
}
],
"parameters": [
{
"name": "identifier",
"in": "query",
"description": "An arbitrary identifier for the task",
"schema": {
"type": "string",
"nullable": true
}
},
{
"name": "appId",
"in": "path",
"description": "ID of the app",
"required": true,
"schema": {
"type": "string"
}
},
{
"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": "Task list returned",
"content": {
"application/json": {
"schema": {
@ -3851,11 +3939,14 @@
"data": {
"type": "object",
"required": [
"message"
"tasks"
],
"properties": {
"message": {
"type": "string"
"tasks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskProcessingTask"
}
}
}
}
@ -3907,10 +3998,10 @@
}
}
},
"/ocs/v2.php/taskprocessing/tasks/app/{appId}": {
"/ocs/v2.php/taskprocessing/tasks/{taskId}/file/{fileId}": {
"get": {
"operationId": "task_processing_api-list-tasks-by-app",
"summary": "This endpoint returns a list of tasks of a user that are related with a specific appId and optionally with an identifier",
"operationId": "task_processing_api-get-file-contents",
"summary": "This endpoint returns the contents of a file referenced in a task",
"tags": [
"task_processing_api"
],
@ -3924,21 +4015,23 @@
],
"parameters": [
{
"name": "identifier",
"in": "query",
"description": "An arbitrary identifier for the task",
"name": "taskId",
"in": "path",
"description": "The id of the task",
"required": true,
"schema": {
"type": "string",
"nullable": true
"type": "integer",
"format": "int64"
}
},
{
"name": "appId",
"name": "fileId",
"in": "path",
"description": "ID of the app",
"description": "The file id of the file to retrieve",
"required": true,
"schema": {
"type": "string"
"type": "integer",
"format": "int64"
}
},
{
@ -3954,7 +4047,18 @@
],
"responses": {
"200": {
"description": "Task list returned",
"description": "File content returned",
"content": {
"*/*": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
},
"500": {
"description": "",
"content": {
"application/json": {
"schema": {
@ -3976,14 +4080,11 @@
"data": {
"type": "object",
"required": [
"tasks"
"message"
],
"properties": {
"tasks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TaskProcessingTask"
}
"message": {
"type": "string"
}
}
}
@ -3994,8 +4095,8 @@
}
}
},
"500": {
"description": "",
"404": {
"description": "Task or file not found",
"content": {
"application/json": {
"schema": {
@ -4035,10 +4136,10 @@
}
}
},
"/ocs/v2.php/taskprocessing/tasks/{taskId}/file/{fileId}": {
"get": {
"operationId": "task_processing_api-get-file-contents",
"summary": "This endpoint returns the contents of a file referenced in a task",
"/ocs/v2.php/taskprocessing/tasks/{taskId}/progress": {
"post": {
"operationId": "task_processing_api-set-progress",
"summary": "This endpoint sets the task progress",
"tags": [
"task_processing_api"
],
@ -4051,6 +4152,16 @@
}
],
"parameters": [
{
"name": "progress",
"in": "query",
"description": "The progress",
"required": true,
"schema": {
"type": "number",
"format": "double"
}
},
{
"name": "taskId",
"in": "path",
@ -4062,9 +4173,172 @@
}
},
{
"name": "fileId",
"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/taskprocessing/tasks/{taskId}/result": {
"post": {
"operationId": "task_processing_api-set-result",
"summary": "This endpoint sets the task progress",
"tags": [
"task_processing_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "output",
"in": "query",
"description": "The resulting task output",
"schema": {
"type": "string",
"nullable": true
}
},
{
"name": "errorMessage",
"in": "query",
"description": "An error message if the task failed",
"schema": {
"type": "string",
"nullable": true
}
},
{
"name": "taskId",
"in": "path",
"description": "The file id of the file to retrieve",
"description": "The id of the task",
"required": true,
"schema": {
"type": "integer",
@ -4086,10 +4360,37 @@
"200": {
"description": "File content returned",
"content": {
"*/*": {
"application/json": {
"schema": {
"type": "string",
"format": "binary"
"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"
}
}
}
}
}
}
}
}
}
@ -4133,7 +4434,7 @@
}
},
"404": {
"description": "Task or file not found",
"description": "Task not found",
"content": {
"application/json": {
"schema": {

Loading…
Cancel
Save