mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
fix(cliproxy): update auth before model registration
This commit is contained in:
@@ -273,27 +273,42 @@ func (s *Service) wsOnDisconnected(channelID string, reason error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) applyCoreAuthAddOrUpdate(ctx context.Context, auth *coreauth.Auth) {
|
func (s *Service) applyCoreAuthAddOrUpdate(ctx context.Context, auth *coreauth.Auth) {
|
||||||
if s == nil || auth == nil || auth.ID == "" {
|
if s == nil || s.coreManager == nil || auth == nil || auth.ID == "" {
|
||||||
return
|
|
||||||
}
|
|
||||||
if s.coreManager == nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
auth = auth.Clone()
|
auth = auth.Clone()
|
||||||
s.ensureExecutorsForAuth(auth)
|
s.ensureExecutorsForAuth(auth)
|
||||||
s.registerModelsForAuth(auth)
|
|
||||||
if existing, ok := s.coreManager.GetByID(auth.ID); ok && existing != nil {
|
// IMPORTANT: Update coreManager FIRST, before model registration.
|
||||||
|
// This ensures that configuration changes (proxy_url, prefix, etc.) take effect
|
||||||
|
// immediately for API calls, rather than waiting for model registration to complete.
|
||||||
|
// Model registration may involve network calls (e.g., FetchAntigravityModels) that
|
||||||
|
// could timeout if the new proxy_url is unreachable.
|
||||||
|
op := "register"
|
||||||
|
var err error
|
||||||
|
if existing, ok := s.coreManager.GetByID(auth.ID); ok {
|
||||||
auth.CreatedAt = existing.CreatedAt
|
auth.CreatedAt = existing.CreatedAt
|
||||||
auth.LastRefreshedAt = existing.LastRefreshedAt
|
auth.LastRefreshedAt = existing.LastRefreshedAt
|
||||||
auth.NextRefreshAfter = existing.NextRefreshAfter
|
auth.NextRefreshAfter = existing.NextRefreshAfter
|
||||||
if _, err := s.coreManager.Update(ctx, auth); err != nil {
|
op = "update"
|
||||||
log.Errorf("failed to update auth %s: %v", auth.ID, err)
|
_, err = s.coreManager.Update(ctx, auth)
|
||||||
|
} else {
|
||||||
|
_, err = s.coreManager.Register(ctx, auth)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to %s auth %s: %v", op, auth.ID, err)
|
||||||
|
current, ok := s.coreManager.GetByID(auth.ID)
|
||||||
|
if !ok || current.Disabled {
|
||||||
|
GlobalModelRegistry().UnregisterClient(auth.ID)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
auth = current
|
||||||
}
|
|
||||||
if _, err := s.coreManager.Register(ctx, auth); err != nil {
|
|
||||||
log.Errorf("failed to register auth %s: %v", auth.ID, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register models after auth is updated in coreManager.
|
||||||
|
// This operation may block on network calls, but the auth configuration
|
||||||
|
// is already effective at this point.
|
||||||
|
s.registerModelsForAuth(auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) applyCoreAuthRemoval(ctx context.Context, id string) {
|
func (s *Service) applyCoreAuthRemoval(ctx context.Context, id string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user