Skip to content

Commit bc84a7f

Browse files
Merge pull request #56391 from nextcloud/backport/56350/stable29
[stable29] Add AI input limits
2 parents 99ed8fa + 1251cdc commit bc84a7f

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

core/Controller/TextProcessingApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public function taskTypes(): DataResponse {
117117
#[AnonRateLimit(limit: 5, period: 120)]
118118
#[ApiRoute(verb: 'POST', url: '/schedule', root: '/textprocessing')]
119119
public function schedule(string $input, string $type, string $appId, string $identifier = ''): DataResponse {
120+
if (strlen($input) > 64_000) {
121+
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
122+
}
120123
try {
121124
$task = new Task($type, $input, $appId, $this->userId, $identifier);
122125
} catch (InvalidArgumentException) {

core/Controller/TextToImageApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public function isAvailable(): DataResponse {
9393
#[UserRateLimit(limit: 20, period: 120)]
9494
#[ApiRoute(verb: 'POST', url: '/schedule', root: '/text2image')]
9595
public function schedule(string $input, string $appId, string $identifier = '', int $numberOfImages = 8): DataResponse {
96+
if (strlen($input) > 64_000) {
97+
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_PRECONDITION_FAILED);
98+
}
9699
$task = new Task($input, $appId, $numberOfImages, $this->userId, $identifier);
97100
try {
98101
try {

core/Controller/TranslationApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public function languages(): DataResponse {
8282
*/
8383
#[ApiRoute(verb: 'POST', url: '/translate', root: '/translation')]
8484
public function translate(string $text, ?string $fromLanguage, string $toLanguage): DataResponse {
85+
if (strlen($text) > 64_000) {
86+
return new DataResponse(['message' => $this->l10n->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
87+
}
8588
try {
8689
$translation = $this->translationManager->translate($text, $fromLanguage, $toLanguage);
8790

0 commit comments

Comments
 (0)