mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
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:
parent
e1a98c0872
commit
2779a1a0b9
2 changed files with 6 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue