Skip to content

Commit 6dcbfc5

Browse files
authored
Merge pull request #147 from nextcloud/fix/138/api-key-image-retrieval
Fix: Use api key in image retrieval request
2 parents d0bd61a + 1f06ee6 commit 6dcbfc5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/Service/OpenAiAPIService.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,17 @@ public function getImageRequestOptions(?string $userId): array {
593593
],
594594
];
595595

596-
$useBasicAuth = $this->openAiSettingsService->getUseBasicAuth();
597-
if ($useBasicAuth && !$this->isUsingOpenAi()) {
598-
$basicUser = $this->openAiSettingsService->getUserBasicUser($userId, true);
599-
$basicPassword = $this->openAiSettingsService->getUserBasicPassword($userId, true);
600-
if ($basicUser !== '' && $basicPassword !== '') {
601-
$requestOptions['headers']['Authorization'] = 'Basic ' . base64_encode($basicUser . ':' . $basicPassword);
596+
if (!$this->isUsingOpenAi()) {
597+
$useBasicAuth = $this->openAiSettingsService->getUseBasicAuth();
598+
if ($useBasicAuth) {
599+
$basicUser = $this->openAiSettingsService->getUserBasicUser($userId, true);
600+
$basicPassword = $this->openAiSettingsService->getUserBasicPassword($userId, true);
601+
if ($basicUser !== '' && $basicPassword !== '') {
602+
$requestOptions['headers']['Authorization'] = 'Basic ' . base64_encode($basicUser . ':' . $basicPassword);
603+
}
604+
} else {
605+
$apiKey = $this->openAiSettingsService->getUserApiKey($userId, true);
606+
$requestOptions['headers']['Authorization'] = 'Bearer ' . $apiKey;
602607
}
603608
}
604609
return $requestOptions;

0 commit comments

Comments
 (0)