mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-21 14:19:18 +08:00
fix(grok): satisfy lint checks
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"hash/fnv"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -1296,36 +1295,6 @@ func (a *Account) GetGrokMediaBaseURL() string {
|
||||
return a.GetGrokBaseURL()
|
||||
}
|
||||
|
||||
func isOfficialGrokAPIBaseURL(raw string) bool {
|
||||
return isOfficialGrokBaseURL(raw, xai.DefaultBaseURL)
|
||||
}
|
||||
|
||||
func isOfficialGrokCLIBaseURL(raw string) bool {
|
||||
return isOfficialGrokBaseURL(raw, xai.DefaultCLIBaseURL)
|
||||
}
|
||||
|
||||
func isOfficialGrokBaseURL(raw, expected string) bool {
|
||||
parsed, err := url.Parse(strings.TrimSpace(raw))
|
||||
if err != nil || parsed == nil || parsed.Opaque != "" || parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" {
|
||||
return false
|
||||
}
|
||||
defaultURL, err := url.Parse(expected)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if !strings.EqualFold(parsed.Scheme, defaultURL.Scheme) || !strings.EqualFold(parsed.Hostname(), defaultURL.Hostname()) {
|
||||
return false
|
||||
}
|
||||
if port := parsed.Port(); port != "" {
|
||||
portNumber, err := strconv.Atoi(port)
|
||||
if err != nil || portNumber != 443 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
path := strings.TrimRight(parsed.Path, "/")
|
||||
return path == "" || path == strings.TrimRight(defaultURL.Path, "/")
|
||||
}
|
||||
|
||||
func (a *Account) GetGrokAccessToken() string {
|
||||
if !a.IsGrok() {
|
||||
return ""
|
||||
|
||||
@@ -497,7 +497,12 @@ func (s *OpenAIGatewayService) validateCurrentGrokCredentialFailure(
|
||||
|
||||
func (s *OpenAIGatewayService) grokCredentialMutationLock(accountID int64) *oauthRefreshLocalLock {
|
||||
actual, _ := s.grokCredentialMutationLocks.LoadOrStore(accountID, newOAuthRefreshLocalLock())
|
||||
return actual.(*oauthRefreshLocalLock)
|
||||
mu, ok := actual.(*oauthRefreshLocalLock)
|
||||
if !ok {
|
||||
mu = newOAuthRefreshLocalLock()
|
||||
s.grokCredentialMutationLocks.Store(accountID, mu)
|
||||
}
|
||||
return mu
|
||||
}
|
||||
|
||||
func (s *OpenAIGatewayService) grokCredentialMutationCommitted(accountID int64, class grokCredentialFailureClass, until time.Time) bool {
|
||||
|
||||
@@ -22,7 +22,6 @@ var (
|
||||
errGrokOAuthAccessTokenMissing = errors.New("grok oauth access token is missing")
|
||||
errGrokOAuthAccessTokenExpired = errors.New("grok oauth access token is expired")
|
||||
errGrokOAuthConfiguredProxyMiss = errors.New("grok oauth configured proxy is missing")
|
||||
errGrokOAuthRefreshLockTimeout = errors.New("grok oauth refresh lock wait timed out")
|
||||
)
|
||||
|
||||
type GrokTokenCache = GeminiTokenCache
|
||||
|
||||
@@ -105,7 +105,12 @@ func (s *OpenAIGatewayService) BlockAccountScheduling(account *Account, until ti
|
||||
|
||||
func (s *OpenAIGatewayService) openAIAccountRuntimeBlockLock(accountID int64) *sync.Mutex {
|
||||
actual, _ := s.openaiAccountRuntimeBlockLocks.LoadOrStore(accountID, &sync.Mutex{})
|
||||
return actual.(*sync.Mutex)
|
||||
mu, ok := actual.(*sync.Mutex)
|
||||
if !ok {
|
||||
mu = &sync.Mutex{}
|
||||
s.openaiAccountRuntimeBlockLocks.Store(accountID, mu)
|
||||
}
|
||||
return mu
|
||||
}
|
||||
|
||||
func (s *OpenAIGatewayService) blockAccountSchedulingLocked(account *Account, until time.Time, _ string) (uint64, bool) {
|
||||
|
||||
Reference in New Issue
Block a user