diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-10-20 13:13:15 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2023-10-20 13:13:15 +0200 |
commit | b7fd5185b69be28338110cc1dc1655883d84c302 (patch) | |
tree | 66a1bcbeaf6e2415ce3201c763499ce157c73fb4 /core | |
parent | 8968573d9fa0b9abac1dd5c7684dd94258a080cf (diff) | |
download | nextcloud-server-b7fd5185b69be28338110cc1dc1655883d84c302.tar.gz nextcloud-server-b7fd5185b69be28338110cc1dc1655883d84c302.zip |
enh(TextToImage): Allow generating multiple images with one task
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/TextToImageApiController.php | 14 | ||||
-rw-r--r-- | core/ResponseDefinitions.php | 1 | ||||
-rw-r--r-- | core/routes.php | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/core/Controller/TextToImageApiController.php b/core/Controller/TextToImageApiController.php index c7878d7cdc3..aee3a462f5f 100644 --- a/core/Controller/TextToImageApiController.php +++ b/core/Controller/TextToImageApiController.php @@ -80,6 +80,7 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController { * @param string $input Input text * @param string $appId ID of the app that will execute the task * @param string $identifier An arbitrary identifier for the task + * @param int $numberOfImages The number of images to generate * * @return DataResponse<Http::STATUS_OK, array{task: CoreTextToImageTask}, array{}>|DataResponse<Http::STATUS_PRECONDITION_FAILED, array{message: string}, array{}> * @@ -89,8 +90,8 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController { #[PublicPage] #[UserRateLimit(limit: 20, period: 120)] #[AnonRateLimit(limit: 5, period: 120)] - public function schedule(string $input, string $appId, string $identifier = ''): DataResponse { - $task = new Task($input, $appId, $this->userId, $identifier); + public function schedule(string $input, string $appId, string $identifier = '', int $numberOfImages = 8): DataResponse { + $task = new Task($input, $appId, $numberOfImages, $this->userId, $identifier); try { try { $this->textToImageManager->runOrScheduleTask($task); @@ -145,6 +146,7 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController { * This endpoint allows downloading the resulting image of a task * * @param int $id The id of the task + * @param int $index The index of the image to retrieve * * @return FileDisplayResponse<Http::STATUS_OK, array{'Content-Type': string}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}> * @@ -153,15 +155,17 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController { */ #[PublicPage] #[BruteForceProtection(action: 'text2image')] - public function getImage(int $id): DataResponse|FileDisplayResponse { + public function getImage(int $id, int $index): DataResponse|FileDisplayResponse { try { $task = $this->textToImageManager->getUserTask($id, $this->userId); try { $folder = $this->appData->getFolder('text2image'); } catch(NotFoundException) { - $folder = $this->appData->newFolder('text2image'); + $res = new DataResponse(['message' => $this->l->t('Image not found')], Http::STATUS_NOT_FOUND); + $res->throttle(['action' => 'text2image']); + return $res; } - $file = $folder->getFile((string)$task->getId()); + $file = $folder->getFolder((string) $task->getId())->getFile((string) $index); $info = getimagesizefromstring($file->getContent()); return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => image_type_to_mime_type($info[2])]); diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index 2548880395a..103d4f84a7f 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -152,6 +152,7 @@ namespace OCA\Core; * appId: string, * input: string, * identifier: ?string, + * numberOfImages: int * } */ class ResponseDefinitions { diff --git a/core/routes.php b/core/routes.php index a779b130ba2..fe1fe6fcd75 100644 --- a/core/routes.php +++ b/core/routes.php @@ -159,7 +159,7 @@ $application->registerRoutes($this, [ ['root' => '/text2image', 'name' => 'TextToImageApi#isAvailable', 'url' => '/is_available', 'verb' => 'GET'], ['root' => '/text2image', 'name' => 'TextToImageApi#schedule', 'url' => '/schedule', 'verb' => 'POST'], ['root' => '/text2image', 'name' => 'TextToImageApi#getTask', 'url' => '/task/{id}', 'verb' => 'GET'], - ['root' => '/text2image', 'name' => 'TextToImageApi#getImage', 'url' => '/task/{id}/image', 'verb' => 'GET'], + ['root' => '/text2image', 'name' => 'TextToImageApi#getImage', 'url' => '/task/{id}/image/{index}', 'verb' => 'GET'], ['root' => '/text2image', 'name' => 'TextToImageApi#deleteTask', 'url' => '/task/{id}', 'verb' => 'DELETE'], ['root' => '/text2image', 'name' => 'TextToImageApi#listTasksByApp', 'url' => '/tasks/app/{appId}', 'verb' => 'GET'], ], |