From a8fea6a4212c34bbf0e4cafce5788f5a4c1f18b8 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Wed, 4 Mar 2026 16:47:26 +0100 Subject: [PATCH 1/3] fix(image): follow override image gen service URL to determine if we are using OpenAI (fixes the default toggle value) and to get the credentials when retrieving the images Signed-off-by: Julien Veyssier --- lib/Service/OpenAiAPIService.php | 36 +++++++++++++++++---------- lib/Service/OpenAiSettingsService.php | 5 ++++ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/Service/OpenAiAPIService.php b/lib/Service/OpenAiAPIService.php index fa2deb1a..bddcc76a 100644 --- a/lib/Service/OpenAiAPIService.php +++ b/lib/Service/OpenAiAPIService.php @@ -884,24 +884,38 @@ public function requestImageCreation( * @return array */ public function getImageRequestOptions(?string $userId): array { - $timeout = $this->openAiSettingsService->getRequestTimeout(); $requestOptions = [ - 'timeout' => $timeout, 'headers' => [ 'User-Agent' => Application::USER_AGENT, ], ]; if ($this->openAiSettingsService->getIsImageRetrievalAuthenticated()) { - $useBasicAuth = $this->openAiSettingsService->getUseBasicAuth(); - if ($useBasicAuth) { + if ($this->openAiSettingsService->imageOverrideEnabled()) { + $useBasicAuth = $this->openAiSettingsService->getAdminImageUseBasicAuth(); + + $apiKey = $this->openAiSettingsService->getAdminImageApiKey(); + $basicUser = $this->openAiSettingsService->getAdminImageBasicUser(); + $basicPassword = $this->openAiSettingsService->getAdminImageBasicPassword(); + + $requestOptions['timeout'] = $this->openAiSettingsService->getImageRequestTimeout(); + } else { + // image service settings are not overridden + $useBasicAuth = $this->openAiSettingsService->getUseBasicAuth(); + + // this has no equivalent when the service URL is overridden + // so the user-defined credentials will be ignored + $apiKey = $this->openAiSettingsService->getUserApiKey($userId, true); $basicUser = $this->openAiSettingsService->getUserBasicUser($userId, true); $basicPassword = $this->openAiSettingsService->getUserBasicPassword($userId, true); + + $requestOptions['timeout'] = $this->openAiSettingsService->getRequestTimeout(); + } + if ($useBasicAuth) { if ($basicUser !== '' && $basicPassword !== '') { $requestOptions['headers']['Authorization'] = 'Basic ' . base64_encode($basicUser . ':' . $basicPassword); } } else { - $apiKey = $this->openAiSettingsService->getUserApiKey($userId, true); $requestOptions['headers']['Authorization'] = 'Bearer ' . $apiKey; } } @@ -1007,15 +1021,11 @@ public function updateExpImgProcessingTime(int $runtime): void { * @return array decoded request result or error * @throws Exception */ - public function request(?string $userId, string $endPoint, array $params = [], string $method = 'GET', ?string $contentType = null, bool $logErrors = true, ?string $serviceType = null): array { + public function request( + ?string $userId, string $endPoint, array $params = [], string $method = 'GET', + ?string $contentType = null, bool $logErrors = true, ?string $serviceType = null, + ): array { try { - $serviceUrl = ''; - $apiKey = ''; - $basicUser = ''; - $basicPassword = ''; - $useBasicAuth = false; - $timeout = 0; - if ($serviceType === Application::SERVICE_TYPE_IMAGE && $this->openAiSettingsService->imageOverrideEnabled()) { $serviceUrl = $this->openAiSettingsService->getImageServiceUrl(); $apiKey = $this->openAiSettingsService->getAdminImageApiKey(); diff --git a/lib/Service/OpenAiSettingsService.php b/lib/Service/OpenAiSettingsService.php index a2a79d27..26603ee8 100644 --- a/lib/Service/OpenAiSettingsService.php +++ b/lib/Service/OpenAiSettingsService.php @@ -660,6 +660,11 @@ public function getTranslationProviderEnabled(): bool { */ public function getIsImageRetrievalAuthenticated(): bool { $serviceUrl = $this->getServiceUrl(); + // the image_request_auth default depends on the service used for image generation + // if we override it, we check the one we are really gonna use + if ($this->imageOverrideEnabled()) { + $serviceUrl = $this->getImageServiceUrl(); + } $isUsingOpenAI = $serviceUrl === '' || $serviceUrl === Application::OPENAI_API_BASE_URL; $default = $isUsingOpenAI ? '0' : '1'; return $this->appConfig->getValueString(Application::APP_ID, 'image_request_auth', $default, lazy: true) === '1'; From d4ed8070c0b01c00cb81b122370ad8cd540ae368 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 12 Mar 2026 10:39:53 +0100 Subject: [PATCH 2/3] fix: always set a request timeout when retrieving generated images from a URL Signed-off-by: Julien Veyssier --- lib/Service/OpenAiAPIService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Service/OpenAiAPIService.php b/lib/Service/OpenAiAPIService.php index bddcc76a..a6bef17a 100644 --- a/lib/Service/OpenAiAPIService.php +++ b/lib/Service/OpenAiAPIService.php @@ -885,6 +885,7 @@ public function requestImageCreation( */ public function getImageRequestOptions(?string $userId): array { $requestOptions = [ + 'timeout' => $this->openAiSettingsService->getRequestTimeout(), 'headers' => [ 'User-Agent' => Application::USER_AGENT, ], @@ -908,8 +909,6 @@ public function getImageRequestOptions(?string $userId): array { $apiKey = $this->openAiSettingsService->getUserApiKey($userId, true); $basicUser = $this->openAiSettingsService->getUserBasicUser($userId, true); $basicPassword = $this->openAiSettingsService->getUserBasicPassword($userId, true); - - $requestOptions['timeout'] = $this->openAiSettingsService->getRequestTimeout(); } if ($useBasicAuth) { if ($basicUser !== '' && $basicPassword !== '') { From 5501ca196262ffc60ec3efe611c724f86c1f24ad Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 12 Mar 2026 17:49:44 +0100 Subject: [PATCH 3/3] fix: adjust the post-update-cmd to only install pkgs instead of updating them which can break scoping if there actually is an update (the pkg is reinstalled and not scoped anymore) Signed-off-by: Julien Veyssier --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 003bf18a..64a2209d 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "@composer bin all install --ansi", "grep -r 'OCA\\\\OpenAi\\\\Vendor' ./vendor || vendor/bin/php-scoper add-prefix --prefix='OCA\\OpenAi\\Vendor' --output-dir=\".\" --working-dir=\"./vendor/\" -f --config=\"../scoper.inc.php\"", "composer dump-autoload", - "composer update --no-scripts" + "composer install --no-scripts" ] }, "require-dev": {