[Fix] Improve OpenAI authentication handling and error response

This commit is contained in:
misyaguziya
2025-11-14 10:42:40 +09:00
parent d6498a78ca
commit bc6798714d

View File

@@ -1813,6 +1813,8 @@ class Controller:
try:
data = str(data)
if data.startswith("sk-") and len(data) >= 164:
result = model.authenticationTranslatorOpenAIAuthKey(auth_key=data)
if result is True:
key = data
auth_keys = config.AUTH_KEYS
auth_keys[translator_name] = key
@@ -1827,6 +1829,14 @@ class Controller:
model.updateTranslatorOpenAIClient()
self.updateTranslationEngineAndEngineList()
response = {"status":200, "result":config.AUTH_KEYS[translator_name]}
else:
response = {
"status":400,
"result":{
"message":"Authentication failure of OpenAI auth key",
"data": config.AUTH_KEYS[translator_name]
}
}
else:
response = {
"status":400,