feat: 优化key验证流程

This commit is contained in:
tbphp
2025-07-13 23:21:50 +08:00
parent 411f8f2e78
commit 1a800dd452
6 changed files with 112 additions and 53 deletions

View File

@@ -48,7 +48,10 @@ func NewKeyValidator(params KeyValidatorParams) *KeyValidator {
// ValidateSingleKey performs a validation check on a single API key.
func (s *KeyValidator) ValidateSingleKey(key *models.APIKey, group *models.Group) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
if group.EffectiveConfig.AppUrl == "" {
group.EffectiveConfig = s.SettingsManager.GetEffectiveConfig(group.Config)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(group.EffectiveConfig.KeyValidationTimeoutSeconds)*time.Second)
defer cancel()
ch, err := s.channelFactory.GetChannel(group)
@@ -58,7 +61,6 @@ func (s *KeyValidator) ValidateSingleKey(key *models.APIKey, group *models.Group
isValid, validationErr := ch.ValidateKey(ctx, key.KeyValue)
group.EffectiveConfig = s.SettingsManager.GetEffectiveConfig(group.Config)
s.keypoolProvider.UpdateStatus(key, group, isValid)
if !isValid {