mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 21:10:51 +08:00
feat: enhance request logging and account handling in CLI proxy
- Added helper functions to log API request and response payloads in the Gin context. - Improved `AccountInfo` to support cookie-based authentication in addition to API key and OAuth. - Updated log messages for better clarity on account types used.
This commit is contained in:
@@ -254,10 +254,13 @@ func (m *Manager) executeWithProvider(ctx context.Context, provider string, req
|
||||
return cliproxyexecutor.Response{}, errPick
|
||||
}
|
||||
|
||||
if isAPIKey, info := auth.AccountInfo(); isAPIKey {
|
||||
log.Debugf("Use API key %s for model %s", util.HideAPIKey(info), req.Model)
|
||||
} else {
|
||||
log.Debugf("Use OAuth %s for model %s", info, req.Model)
|
||||
accountType, accountInfo := auth.AccountInfo()
|
||||
if accountType == "api_key" {
|
||||
log.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
||||
} else if accountType == "oauth" {
|
||||
log.Debugf("Use OAuth %s for model %s", accountInfo, req.Model)
|
||||
} else if accountType == "cookie" {
|
||||
log.Debugf("Use Cookie %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
||||
}
|
||||
|
||||
tried[auth.ID] = struct{}{}
|
||||
@@ -298,10 +301,13 @@ func (m *Manager) executeStreamWithProvider(ctx context.Context, provider string
|
||||
return nil, errPick
|
||||
}
|
||||
|
||||
if isAPIKey, info := auth.AccountInfo(); isAPIKey {
|
||||
log.Debugf("Use API key %s for model %s", util.HideAPIKey(info), req.Model)
|
||||
} else {
|
||||
log.Debugf("Use OAuth %s for model %s", info, req.Model)
|
||||
accountType, accountInfo := auth.AccountInfo()
|
||||
if accountType == "api_key" {
|
||||
log.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
||||
} else if accountType == "oauth" {
|
||||
log.Debugf("Use OAuth %s for model %s", accountInfo, req.Model)
|
||||
} else if accountType == "cookie" {
|
||||
log.Debugf("Use Cookie %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
||||
}
|
||||
|
||||
tried[auth.ID] = struct{}{}
|
||||
|
||||
@@ -80,38 +80,38 @@ func (a *Auth) Clone() *Auth {
|
||||
return ©Auth
|
||||
}
|
||||
|
||||
func (a *Auth) AccountInfo() (bool, string) {
|
||||
func (a *Auth) AccountInfo() (string, string) {
|
||||
if a == nil {
|
||||
return false, ""
|
||||
return "", ""
|
||||
}
|
||||
if strings.ToLower(a.Provider) == "gemini-web" {
|
||||
if a.Metadata != nil {
|
||||
if v, ok := a.Metadata["secure_1psid"].(string); ok && v != "" {
|
||||
return true, v
|
||||
return "cookie", v
|
||||
}
|
||||
if v, ok := a.Metadata["__Secure-1PSID"].(string); ok && v != "" {
|
||||
return true, v
|
||||
return "cookie", v
|
||||
}
|
||||
}
|
||||
if a.Attributes != nil {
|
||||
if v := a.Attributes["secure_1psid"]; v != "" {
|
||||
return true, v
|
||||
return "cookie", v
|
||||
}
|
||||
if v := a.Attributes["api_key"]; v != "" {
|
||||
return true, v
|
||||
return "cookie", v
|
||||
}
|
||||
}
|
||||
}
|
||||
if a.Metadata != nil {
|
||||
if v, ok := a.Metadata["email"].(string); ok {
|
||||
return false, v
|
||||
return "oauth", v
|
||||
}
|
||||
} else if a.Attributes != nil {
|
||||
if v := a.Attributes["api_key"]; v != "" {
|
||||
return true, v
|
||||
return "api_key", v
|
||||
}
|
||||
}
|
||||
return false, ""
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// ExpirationTime attempts to extract the credential expiration timestamp from metadata.
|
||||
|
||||
Reference in New Issue
Block a user