feat: publish sanitized custom.97 source
This commit is contained in:
1022 files changed
+69903
-19207
No files matched your search
+18
-19
@@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/i18n"
|
||||
"github.com/QuantumNous/new-api/logger"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -52,7 +51,7 @@ func (p *GitHubProvider) IsEnabled() bool {
|
||||
|
||||
func (p *GitHubProvider) ExchangeToken(ctx context.Context, code string, c *gin.Context) (*OAuthToken, error) {
|
||||
if code == "" {
|
||||
return nil, NewOAuthError(i18n.MsgOAuthInvalidCode, nil)
|
||||
return nil, NewOAuthError(common.NewMessage(msgInvalidCode))
|
||||
}
|
||||
|
||||
values := map[string]string{
|
||||
@@ -77,8 +76,8 @@ func (p *GitHubProvider) ExchangeToken(ctx context.Context, code string, c *gin.
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] ExchangeToken error: %s", err.Error()))
|
||||
return nil, NewOAuthErrorWithRaw(i18n.MsgOAuthConnectFailed, map[string]any{"Provider": "GitHub"}, err.Error())
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] ExchangeToken error: %s", err.Error()))
|
||||
return nil, NewOAuthErrorWithRaw(common.NewMessage(msgConnectFailed, map[string]any{"provider": "GitHub"}), err.Error())
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
@@ -87,13 +86,13 @@ func (p *GitHubProvider) ExchangeToken(ctx context.Context, code string, c *gin.
|
||||
var oAuthResponse gitHubOAuthResponse
|
||||
err = json.NewDecoder(res.Body).Decode(&oAuthResponse)
|
||||
if err != nil {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] ExchangeToken decode error: %s", err.Error()))
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] ExchangeToken decode error: %s", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if oAuthResponse.AccessToken == "" {
|
||||
logger.LogError(ctx, "[OAuth-GitHub] ExchangeToken failed: empty access token")
|
||||
return nil, NewOAuthError(i18n.MsgOAuthTokenFailed, map[string]any{"Provider": "GitHub"})
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] ExchangeToken failed: empty access token"))
|
||||
return nil, NewOAuthError(common.NewMessage(msgTokenFailed, map[string]any{"provider": "GitHub"}))
|
||||
}
|
||||
|
||||
logger.LogDebug(ctx, "[OAuth-GitHub] ExchangeToken success: scope=%s", oAuthResponse.Scope)
|
||||
@@ -119,8 +118,8 @@ func (p *GitHubProvider) GetUserInfo(ctx context.Context, token *OAuthToken) (*O
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] GetUserInfo error: %s", err.Error()))
|
||||
return nil, NewOAuthErrorWithRaw(i18n.MsgOAuthConnectFailed, map[string]any{"Provider": "GitHub"}, err.Error())
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetUserInfo error: %s", err.Error()))
|
||||
return nil, NewOAuthErrorWithRaw(common.NewMessage(msgConnectFailed, map[string]any{"provider": "GitHub"}), err.Error())
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
@@ -133,20 +132,20 @@ func (p *GitHubProvider) GetUserInfo(ctx context.Context, token *OAuthToken) (*O
|
||||
if len(bodyStr) > 500 {
|
||||
bodyStr = bodyStr[:500] + "..."
|
||||
}
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] GetUserInfo failed: status=%d, body=%s", res.StatusCode, bodyStr))
|
||||
return nil, NewOAuthErrorWithRaw(i18n.MsgOAuthGetUserErr, map[string]any{"Provider": "GitHub"}, fmt.Sprintf("status %d", res.StatusCode))
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetUserInfo failed: status=%d, body=%s", res.StatusCode, bodyStr))
|
||||
return nil, NewOAuthErrorWithRaw(common.NewMessage(msgGetUserFailed), fmt.Sprintf("status %d", res.StatusCode))
|
||||
}
|
||||
|
||||
var githubUser gitHubUser
|
||||
err = json.NewDecoder(res.Body).Decode(&githubUser)
|
||||
if err != nil {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] GetUserInfo decode error: %s", err.Error()))
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetUserInfo decode error: %s", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if githubUser.Id == 0 || githubUser.Login == "" {
|
||||
logger.LogError(ctx, "[OAuth-GitHub] GetUserInfo failed: empty id or login field")
|
||||
return nil, NewOAuthError(i18n.MsgOAuthUserInfoEmpty, map[string]any{"Provider": "GitHub"})
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetUserInfo failed: empty id or login field"))
|
||||
return nil, NewOAuthError(common.NewMessage(msgUserInfoEmpty, map[string]any{"provider": "GitHub"}))
|
||||
}
|
||||
|
||||
logger.LogDebug(ctx, "[OAuth-GitHub] GetUserInfo success: id=%d, login=%s, name=%s, email=%s",
|
||||
@@ -179,19 +178,19 @@ func (p *GitHubProvider) GetVerifiedEmails(ctx context.Context, token *OAuthToke
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] GetVerifiedEmails error: %s", err.Error()))
|
||||
return nil, NewOAuthErrorWithRaw(i18n.MsgOAuthConnectFailed, map[string]any{"Provider": "GitHub"}, err.Error())
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetVerifiedEmails error: %s", err.Error()))
|
||||
return nil, NewOAuthErrorWithRaw(common.NewMessage(msgConnectFailed, map[string]any{"provider": "GitHub"}), err.Error())
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] GetVerifiedEmails failed: status=%d", res.StatusCode))
|
||||
return nil, NewOAuthErrorWithRaw(i18n.MsgOAuthGetUserErr, map[string]any{"Provider": "GitHub"}, fmt.Sprintf("status %d", res.StatusCode))
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetVerifiedEmails failed: status=%d", res.StatusCode))
|
||||
return nil, NewOAuthErrorWithRaw(common.NewMessage(msgGetUserFailed), fmt.Sprintf("status %d", res.StatusCode))
|
||||
}
|
||||
|
||||
var emails []gitHubEmail
|
||||
if err := common.DecodeJson(res.Body, &emails); err != nil {
|
||||
logger.LogError(ctx, fmt.Sprintf("[OAuth-GitHub] GetVerifiedEmails decode error: %s", err.Error()))
|
||||
logger.LogError(ctx, common.LogText("[OAuth-GitHub] GetVerifiedEmails decode error: %s", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
verified := make([]string, 0, len(emails))
|
||||
|
||||
Reference in new issue
Block a user