Skip to content

Commit 1731caf

Browse files
Merge pull request #56390 from nextcloud/backport/56350/stable28
[stable28] Add AI input limits
2 parents 189c6c7 + 1a1e55a commit 1731caf

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
@@ -112,6 +112,9 @@ public function taskTypes(): DataResponse {
112112
#[NoAdminRequired]
113113
#[UserRateLimit(limit: 20, period: 120)]
114114
public function schedule(string $input, string $type, string $appId, string $identifier = ''): DataResponse {
115+
if (strlen($input) > 64_000) {
116+
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
117+
}
115118
try {
116119
$task = new Task($type, $input, $appId, $this->userId, $identifier);
117120
} catch (InvalidArgumentException) {

core/Controller/TextToImageApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public function isAvailable(): DataResponse {
9090
#[NoAdminRequired]
9191
#[UserRateLimit(limit: 20, period: 120)]
9292
public function schedule(string $input, string $appId, string $identifier = '', int $numberOfImages = 8): DataResponse {
93+
if (strlen($input) > 64_000) {
94+
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_PRECONDITION_FAILED);
95+
}
9396
$task = new Task($input, $appId, $numberOfImages, $this->userId, $identifier);
9497
try {
9598
try {

core/Controller/TranslationApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public function languages(): DataResponse {
7979
* 412: Translating is not possible
8080
*/
8181
public function translate(string $text, ?string $fromLanguage, string $toLanguage): DataResponse {
82+
if (strlen($text) > 64_000) {
83+
return new DataResponse(['message' => $this->l10n->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
84+
}
8285
try {
8386
$translation = $this->translationManager->translate($text, $fromLanguage, $toLanguage);
8487

0 commit comments

Comments
 (0)