Skip to content

Commit eb8c804

Browse files
Merge pull request #58113 from nextcloud/backport/58015/stable29
[stable29] fix(TextToImage): Refactor scheduling mechanism
2 parents c7f4b81 + 709b1bb commit eb8c804

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

core/Controller/TextToImageApiController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ public function schedule(string $input, string $appId, string $identifier = '',
9696
if (strlen($input) > 64_000) {
9797
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_PRECONDITION_FAILED);
9898
}
99+
if ($numberOfImages > 12) {
100+
return new DataResponse(['message' => $this->l->t('Cannot generate more than 12 images')], Http::STATUS_PRECONDITION_FAILED);
101+
}
102+
if ($numberOfImages < 1) {
103+
return new DataResponse(['message' => $this->l->t('Cannot generate less than 1 image')], Http::STATUS_PRECONDITION_FAILED);
104+
}
99105
$task = new Task($input, $appId, $numberOfImages, $this->userId, $identifier);
100106
try {
101107
try {

lib/public/TextToImage/Task.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ final public function __construct(
8383
protected ?string $userId,
8484
protected ?string $identifier = '',
8585
) {
86+
if ($this->numberOfImages > 12) {
87+
throw new \ValueError('Cannot generate more than 12 images');
88+
}
89+
if ($this->numberOfImages < 1) {
90+
throw new \ValueError('Cannot generate less than 1 image');
91+
}
8692
}
8793

8894
/**

0 commit comments

Comments
 (0)