feat: geminikey load balancing

This commit is contained in:
syfantasy 2024-12-30 21:07:14 +08:00 committed by GitHub
parent c9a0ac5d7b
commit 6bc453abda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -266,6 +266,15 @@ config.version = defaultConfig.version
// config.version = latestTag // config.version = latestTag
export const Config = new Proxy(config, { export const Config = new Proxy(config, {
get(target, property) {
if (property === 'geminiKey') {
if (typeof target[property] === 'string' && target[property].includes(',')) {
const keys = target[property].split(',').map(key => key.trim()).filter(Boolean)
return keys[Math.floor(Math.random() * keys.length)]
}
}
return target[property]
},
set (target, property, value) { set (target, property, value) {
target[property] = value target[property] = value
const change = lodash.transform(target, function (result, value, key) { const change = lodash.transform(target, function (result, value, key) {