Update web-app/src/lib/completion.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Louis 2025-10-08 10:10:42 +07:00 committed by GitHub
parent cf62729cd0
commit 38bdfd51ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,10 +175,13 @@ export const sendCompletion = async (
try { try {
const bytes = CryptoJS.AES.decrypt(encryptedKey, key) const bytes = CryptoJS.AES.decrypt(encryptedKey, key)
const decryptedKey = bytes.toString(CryptoJS.enc.Utf8) const decryptedKey = bytes.toString(CryptoJS.enc.Utf8)
return decryptedKey || encryptedKey // Return original if decryption fails if (!decryptedKey) {
throw new Error('Failed to decrypt API key: result is empty')
}
return decryptedKey
} catch (error) { } catch (error) {
console.warn('Failed to decrypt API key, using original value:', error) console.warn('Failed to decrypt API key:', error)
return encryptedKey throw new Error('Failed to decrypt API key')
} }
} }
if (!secretKey) { if (!secretKey) {