mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-24 09:30:28 +00:00
refactor: standardize constant naming and improve file-based auth handling
- Renamed constants from uppercase to CamelCase for consistency. - Replaced redundant file-based auth handling logic with the new `util.CountAuthFiles` helper. - Fixed various error-handling inconsistencies and enhanced robustness in file operations. - Streamlined auth client reload logic in server and watcher components. - Applied minor code readability improvements across multiple packages.
This commit is contained in:
@@ -439,38 +439,14 @@ func (s *Server) UpdateClients(cfg *config.Config) {
|
||||
s.mgmt.SetAuthManager(s.handlers.AuthManager)
|
||||
}
|
||||
|
||||
// Count types from AuthManager state + config
|
||||
authFiles := 0
|
||||
glAPIKeyCount := 0
|
||||
claudeAPIKeyCount := 0
|
||||
codexAPIKeyCount := 0
|
||||
// Count client sources from configuration and auth directory
|
||||
authFiles := util.CountAuthFiles(cfg.AuthDir)
|
||||
glAPIKeyCount := len(cfg.GlAPIKey)
|
||||
claudeAPIKeyCount := len(cfg.ClaudeKey)
|
||||
codexAPIKeyCount := len(cfg.CodexKey)
|
||||
openAICompatCount := 0
|
||||
|
||||
if s.handlers != nil && s.handlers.AuthManager != nil {
|
||||
for _, a := range s.handlers.AuthManager.List() {
|
||||
if a == nil {
|
||||
continue
|
||||
}
|
||||
if a.Attributes != nil {
|
||||
if p := a.Attributes["path"]; p != "" {
|
||||
authFiles++
|
||||
continue
|
||||
}
|
||||
}
|
||||
switch strings.ToLower(a.Provider) {
|
||||
case "gemini":
|
||||
glAPIKeyCount++
|
||||
case "claude":
|
||||
claudeAPIKeyCount++
|
||||
case "codex":
|
||||
codexAPIKeyCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
if cfg != nil {
|
||||
for i := range cfg.OpenAICompatibility {
|
||||
openAICompatCount += len(cfg.OpenAICompatibility[i].APIKeys)
|
||||
}
|
||||
for i := range cfg.OpenAICompatibility {
|
||||
openAICompatCount += len(cfg.OpenAICompatibility[i].APIKeys)
|
||||
}
|
||||
|
||||
total := authFiles + glAPIKeyCount + claudeAPIKeyCount + codexAPIKeyCount + openAICompatCount
|
||||
|
||||
Reference in New Issue
Block a user