fix(handlers): add base URL validation and improve API key deletion tests

This commit is contained in:
Luis Pater
2026-04-09 20:51:54 +08:00
parent 730809d8ea
commit 1dba2d0f81
3 changed files with 300 additions and 24 deletions

View File

@@ -865,6 +865,7 @@ func (cfg *Config) SanitizeClaudeKeys() {
}
// SanitizeGeminiKeys deduplicates and normalizes Gemini credentials.
// It uses API key + base URL as the uniqueness key.
func (cfg *Config) SanitizeGeminiKeys() {
if cfg == nil {
return
@@ -883,10 +884,11 @@ func (cfg *Config) SanitizeGeminiKeys() {
entry.ProxyURL = strings.TrimSpace(entry.ProxyURL)
entry.Headers = NormalizeHeaders(entry.Headers)
entry.ExcludedModels = NormalizeExcludedModels(entry.ExcludedModels)
if _, exists := seen[entry.APIKey]; exists {
uniqueKey := entry.APIKey + "|" + entry.BaseURL
if _, exists := seen[uniqueKey]; exists {
continue
}
seen[entry.APIKey] = struct{}{}
seen[uniqueKey] = struct{}{}
out = append(out, entry)
}
cfg.GeminiKey = out