fix(ai-apis): reject text inputs that are longer than 64K chars

Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
Julien Veyssier 2025-11-12 12:25:40 +01:00
parent e1a98c0872
commit 2779a1a0b9
No known key found for this signature in database
GPG key ID: 4141FEE162030638
2 changed files with 6 additions and 0 deletions

View file

@ -104,6 +104,9 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController {
#[NoAdminRequired]
#[UserRateLimit(limit: 20, period: 120)]
public function schedule(string $input, string $type, string $appId, string $identifier = ''): DataResponse {
if (strlen($input) > 64_000) {
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
}
try {
$task = new Task($type, $input, $appId, $this->userId, $identifier);
} catch (InvalidArgumentException) {

View file

@ -67,6 +67,9 @@ class TranslationApiController extends \OCP\AppFramework\OCSController {
* @AnonRateThrottle(limit=10, period=120)
*/
public function translate(string $text, ?string $fromLanguage, string $toLanguage): DataResponse {
if (strlen($text) > 64_000) {
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
}
try {
$translation = $this->translationManager->translate($text, $fromLanguage, $toLanguage);