Skip to content

Commit e8b2855

Browse files
committed
fix(TextToImage): Refactor scheduling mechanism
1 parent 34c2125 commit e8b2855

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

core/Controller/TextToImageApiController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ public function schedule(string $input, string $appId, string $identifier = '',
8181
if (strlen($input) > 64_000) {
8282
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_PRECONDITION_FAILED);
8383
}
84+
if ($numberOfImages > 12) {
85+
return new DataResponse(['message' => $this->l->t('Cannot generate more than 12 images')], Http::STATUS_PRECONDITION_FAILED);
86+
}
87+
if ($numberOfImages < 1) {
88+
return new DataResponse(['message' => $this->l->t('Cannot generate less than 1 image')], Http::STATUS_PRECONDITION_FAILED);
89+
}
8490
$task = new Task($input, $appId, $numberOfImages, $this->userId, $identifier);
8591
try {
8692
try {

lib/public/TextToImage/Task.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ final public function __construct(
6868
protected ?string $userId,
6969
protected ?string $identifier = '',
7070
) {
71+
if ($this->numberOfImages > 12) {
72+
throw new \ValueError('Cannot generate more than 12 images');
73+
}
74+
if ($this->numberOfImages < 1) {
75+
throw new \ValueError('Cannot generate less than 1 image');
76+
}
7177
}
7278

7379
/**

0 commit comments

Comments
 (0)