Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions internal/api/handlers/management/api_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,21 +613,15 @@ func tokenValueFromMetadata(metadata map[string]any) string {
}

func (h *Handler) authByIndex(authIndex string) *coreauth.Auth {
authIndex = strings.TrimSpace(authIndex)
if authIndex == "" || h == nil || h.authManager == nil {
return nil
}
auths := h.authManager.List()
for _, auth := range auths {
if auth == nil {
continue
}
auth.EnsureIndex()
if auth.Index == authIndex {
return auth
}
}
return nil
authIndex = strings.TrimSpace(authIndex)
if authIndex == "" || h == nil || h.authManager == nil {
return nil
}
// 使用直接查找替代 List() 全量拷贝
if auth, ok := h.authManager.GetByIndex(authIndex); ok {
return auth
}
return nil
}

func (h *Handler) apiCallTransport(auth *coreauth.Auth) http.RoundTripper {
Expand Down
19 changes: 19 additions & 0 deletions sdk/cliproxy/auth/conductor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2879,3 +2879,22 @@ func (m *Manager) HttpRequest(ctx context.Context, auth *Auth, req *http.Request
}
return exec.HttpRequest(ctx, auth, req)
}

func (m *Manager) GetByIndex(index string) (*Auth, bool) {
index = strings.TrimSpace(index)
if index == "" {
return nil, false
}
m.mu.Lock()
defer m.mu.Unlock()
for _, auth := range m.auths {
if auth == nil {
continue
}
auth.EnsureIndex()
if auth.Index == index {
return auth.Clone(), true
}
}
return nil, false
}
Loading