mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-10 03:03:43 +08:00
feat: 定期保存 API KEY 的最后一次调用时间
This commit is contained in:
@@ -332,7 +332,12 @@ func (s *Server) getApiKey(failedKey string) string {
|
||||
rand.NewSource(time.Now().UnixNano())
|
||||
if len(keys) > 0 {
|
||||
key := keys[rand.Intn(len(keys))]
|
||||
key.LastUsed = time.Now().Unix()
|
||||
// 更新选中 Key 的最后使用时间
|
||||
for i, item := range s.Config.Chat.ApiKeys {
|
||||
if item.Value == key.Value {
|
||||
s.Config.Chat.ApiKeys[i].LastUsed = time.Now().Unix()
|
||||
}
|
||||
}
|
||||
return key.Value
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -143,6 +143,8 @@ func (s *Server) Run(webRoot embed.FS, path string, debug bool) {
|
||||
delete(s.ChatContexts, key)
|
||||
}
|
||||
}
|
||||
// 保存配置文档
|
||||
_ = utils.SaveConfig(s.Config, s.ConfigPath)
|
||||
time.Sleep(time.Second * 5) // 每隔 5 秒钟清理一次
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user