mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-08 09:43:42 +08:00
refactor: update UI text and error messages to English for better accessibility
This commit is contained in:
@@ -31,7 +31,7 @@ type GitHubUser struct {
|
||||
|
||||
func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
||||
if code == "" {
|
||||
return nil, errors.New("无效的参数")
|
||||
return nil, errors.New("Invalid parameter")
|
||||
}
|
||||
values := map[string]string{"client_id": config.GitHubClientId, "client_secret": config.GitHubClientSecret, "code": code}
|
||||
jsonData, err := json.Marshal(values)
|
||||
@@ -50,7 +50,7 @@ func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.SysLog(err.Error())
|
||||
return nil, errors.New("无法连接至 GitHub 服务器,请稍后重试!")
|
||||
return nil, errors.New("Unable to connect to GitHub server, please try again later!")
|
||||
}
|
||||
defer res.Body.Close()
|
||||
var oAuthResponse GitHubOAuthResponse
|
||||
@@ -66,7 +66,7 @@ func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
||||
res2, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.SysLog(err.Error())
|
||||
return nil, errors.New("无法连接至 GitHub 服务器,请稍后重试!")
|
||||
return nil, errors.New("Unable to connect to GitHub server, please try again later!")
|
||||
}
|
||||
defer res2.Body.Close()
|
||||
var githubUser GitHubUser
|
||||
@@ -75,7 +75,7 @@ func getGitHubUserInfoByCode(code string) (*GitHubUser, error) {
|
||||
return nil, err
|
||||
}
|
||||
if githubUser.Login == "" {
|
||||
return nil, errors.New("返回值非法,用户字段为空,请稍后重试!")
|
||||
return nil, errors.New("The return value is illegal, the user field is empty, please try again later!")
|
||||
}
|
||||
return &githubUser, nil
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func GitHubOAuth(c *gin.Context) {
|
||||
if !config.GitHubOAuthEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员未开启通过 GitHub 登录以及注册",
|
||||
"message": "The administrator did not turn on login and registration via GitHub",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func GitHubOAuth(c *gin.Context) {
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员关闭了新用户注册",
|
||||
"message": "The administrator has turned off new user registration",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func GitHubOAuth(c *gin.Context) {
|
||||
|
||||
if user.Status != model.UserStatusEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "用户已被封禁",
|
||||
"message": "User has been banned",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -166,7 +166,7 @@ func GitHubBind(c *gin.Context) {
|
||||
if !config.GitHubOAuthEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员未开启通过 GitHub 登录以及注册",
|
||||
"message": "The administrator did not turn on login and registration via GitHub",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func GitHubBind(c *gin.Context) {
|
||||
if model.IsGitHubIdAlreadyTaken(user.GitHubId) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该 GitHub 账户已被绑定",
|
||||
"message": "The GitHub account has been bound",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ type LarkUser struct {
|
||||
|
||||
func getLarkUserInfoByCode(code string) (*LarkUser, error) {
|
||||
if code == "" {
|
||||
return nil, errors.New("无效的参数")
|
||||
return nil, errors.New("Invalid parameter")
|
||||
}
|
||||
values := map[string]string{
|
||||
"client_id": config.LarkClientId,
|
||||
@@ -53,7 +53,7 @@ func getLarkUserInfoByCode(code string) (*LarkUser, error) {
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.SysLog(err.Error())
|
||||
return nil, errors.New("无法连接至飞书服务器,请稍后重试!")
|
||||
return nil, errors.New("None法连接至飞书服务器,请稍后Retry!")
|
||||
}
|
||||
defer res.Body.Close()
|
||||
var oAuthResponse LarkOAuthResponse
|
||||
@@ -69,7 +69,7 @@ func getLarkUserInfoByCode(code string) (*LarkUser, error) {
|
||||
res2, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.SysLog(err.Error())
|
||||
return nil, errors.New("无法连接至飞书服务器,请稍后重试!")
|
||||
return nil, errors.New("None法连接至飞书服务器,请稍后Retry!")
|
||||
}
|
||||
var larkUser LarkUser
|
||||
err = json.NewDecoder(res2.Body).Decode(&larkUser)
|
||||
@@ -136,7 +136,7 @@ func LarkOAuth(c *gin.Context) {
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员关闭了新用户注册",
|
||||
"message": "The administrator has turned off new user registration",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func LarkOAuth(c *gin.Context) {
|
||||
|
||||
if user.Status != model.UserStatusEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "用户已被封禁",
|
||||
"message": "User has been banned",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -168,7 +168,7 @@ func LarkBind(c *gin.Context) {
|
||||
if model.IsLarkIdAlreadyTaken(user.LarkId) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该飞书账户已被绑定",
|
||||
"message": "该飞书账户已被Bind",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ type OidcUser struct {
|
||||
|
||||
func getOidcUserInfoByCode(code string) (*OidcUser, error) {
|
||||
if code == "" {
|
||||
return nil, errors.New("无效的参数")
|
||||
return nil, errors.New("Invalid parameter")
|
||||
}
|
||||
values := map[string]string{
|
||||
"client_id": config.OidcClientId,
|
||||
@@ -60,7 +60,7 @@ func getOidcUserInfoByCode(code string) (*OidcUser, error) {
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.SysLog(err.Error())
|
||||
return nil, errors.New("无法连接至 OIDC 服务器,请稍后重试!")
|
||||
return nil, errors.New("None法连接至 OIDC 服务器,请稍后Retry!")
|
||||
}
|
||||
defer res.Body.Close()
|
||||
var oidcResponse OidcResponse
|
||||
@@ -76,7 +76,7 @@ func getOidcUserInfoByCode(code string) (*OidcUser, error) {
|
||||
res2, err := client.Do(req)
|
||||
if err != nil {
|
||||
logger.SysLog(err.Error())
|
||||
return nil, errors.New("无法连接至 OIDC 服务器,请稍后重试!")
|
||||
return nil, errors.New("None法连接至 OIDC 服务器,请稍后Retry!")
|
||||
}
|
||||
var oidcUser OidcUser
|
||||
err = json.NewDecoder(res2.Body).Decode(&oidcUser)
|
||||
@@ -104,7 +104,7 @@ func OidcAuth(c *gin.Context) {
|
||||
if !config.OidcEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员未开启通过 OIDC 登录以及注册",
|
||||
"message": "Administrator未开启通过 OIDC Log in以及Sign up",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func OidcAuth(c *gin.Context) {
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员关闭了新用户注册",
|
||||
"message": "The administrator has turned off new user registration",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -161,7 +161,7 @@ func OidcAuth(c *gin.Context) {
|
||||
|
||||
if user.Status != model.UserStatusEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "用户已被封禁",
|
||||
"message": "User has been banned",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -173,7 +173,7 @@ func OidcBind(c *gin.Context) {
|
||||
if !config.OidcEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员未开启通过 OIDC 登录以及注册",
|
||||
"message": "Administrator未开启通过 OIDC Log in以及Sign up",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func OidcBind(c *gin.Context) {
|
||||
if model.IsOidcIdAlreadyTaken(user.OidcId) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该 OIDC 账户已被绑定",
|
||||
"message": "该 OIDC 账户已被Bind",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ type wechatLoginResponse struct {
|
||||
|
||||
func getWeChatIdByCode(code string) (string, error) {
|
||||
if code == "" {
|
||||
return "", errors.New("无效的参数")
|
||||
return "", errors.New("Invalid parameter")
|
||||
}
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/wechat/user?code=%s", config.WeChatServerAddress, code), nil)
|
||||
if err != nil {
|
||||
@@ -47,7 +47,7 @@ func getWeChatIdByCode(code string) (string, error) {
|
||||
return "", errors.New(res.Message)
|
||||
}
|
||||
if res.Data == "" {
|
||||
return "", errors.New("验证码错误或已过期")
|
||||
return "", errors.New("Verification code error or expired")
|
||||
}
|
||||
return res.Data, nil
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func getWeChatIdByCode(code string) (string, error) {
|
||||
func WeChatAuth(c *gin.Context) {
|
||||
if !config.WeChatAuthEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "管理员未开启通过微信登录以及注册",
|
||||
"message": "The administrator has not enabled login and registration via WeChat",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -98,7 +98,7 @@ func WeChatAuth(c *gin.Context) {
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员关闭了新用户注册",
|
||||
"message": "The administrator has turned off new user registration",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func WeChatAuth(c *gin.Context) {
|
||||
|
||||
if user.Status != model.UserStatusEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "用户已被封禁",
|
||||
"message": "User has been banned",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -117,7 +117,7 @@ func WeChatAuth(c *gin.Context) {
|
||||
func WeChatBind(c *gin.Context) {
|
||||
if !config.WeChatAuthEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "管理员未开启通过微信登录以及注册",
|
||||
"message": "The administrator has not enabled login and registration via WeChat",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -134,7 +134,7 @@ func WeChatBind(c *gin.Context) {
|
||||
if model.IsWeChatIdAlreadyTaken(wechatId) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该微信账号已被绑定",
|
||||
"message": "The WeChat account has been bound",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
|
||||
baseURL = channel.GetBaseURL()
|
||||
}
|
||||
case channeltype.Azure:
|
||||
return 0, errors.New("尚未实现")
|
||||
return 0, errors.New("Not yet implemented")
|
||||
case channeltype.Custom:
|
||||
baseURL = channel.GetBaseURL()
|
||||
case channeltype.CloseAI:
|
||||
@@ -313,7 +313,7 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
|
||||
case channeltype.DeepSeek:
|
||||
return updateChannelDeepSeekBalance(channel)
|
||||
default:
|
||||
return 0, errors.New("尚未实现")
|
||||
return 0, errors.New("Not yet implemented")
|
||||
}
|
||||
url := fmt.Sprintf("%s/v1/dashboard/billing/subscription", baseURL)
|
||||
|
||||
@@ -399,7 +399,7 @@ func updateAllChannelsBalance() error {
|
||||
} else {
|
||||
// err is nil & balance <= 0 means quota is used up
|
||||
if balance <= 0 {
|
||||
monitor.DisableChannel(channel.Id, channel.Name, "余额不足")
|
||||
monitor.DisableChannel(channel.Id, channel.Name, "Insufficient balance")
|
||||
}
|
||||
}
|
||||
time.Sleep(config.RequestInterval)
|
||||
|
||||
@@ -173,7 +173,7 @@ func testChannels(notify bool, scope string) error {
|
||||
testAllChannelsLock.Lock()
|
||||
if testAllChannelsRunning {
|
||||
testAllChannelsLock.Unlock()
|
||||
return errors.New("测试已在运行中")
|
||||
return errors.New("Test is already running")
|
||||
}
|
||||
testAllChannelsRunning = true
|
||||
testAllChannelsLock.Unlock()
|
||||
@@ -194,11 +194,11 @@ func testChannels(notify bool, scope string) error {
|
||||
tok := time.Now()
|
||||
milliseconds := tok.Sub(tik).Milliseconds()
|
||||
if isChannelEnabled && milliseconds > disableThreshold {
|
||||
err = fmt.Errorf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0)
|
||||
err = fmt.Errorf("Response time %.2fs exceeds threshold %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0)
|
||||
if config.AutomaticDisableChannelEnabled {
|
||||
monitor.DisableChannel(channel.Id, channel.Name, err.Error())
|
||||
} else {
|
||||
_ = message.Notify(message.ByAll, fmt.Sprintf("渠道 %s (%d)测试超时", channel.Name, channel.Id), "", err.Error())
|
||||
_ = message.Notify(message.ByAll, fmt.Sprintf("Channel %s (%d)Test超时", channel.Name, channel.Id), "", err.Error())
|
||||
}
|
||||
}
|
||||
if isChannelEnabled && monitor.ShouldDisableChannel(openaiErr, -1) {
|
||||
@@ -214,7 +214,7 @@ func testChannels(notify bool, scope string) error {
|
||||
testAllChannelsRunning = false
|
||||
testAllChannelsLock.Unlock()
|
||||
if notify {
|
||||
err := message.Notify(message.ByAll, "渠道测试完成", "", "渠道测试完成,如果没有收到禁用通知,说明所有渠道都正常")
|
||||
err := message.Notify(message.ByAll, "Channel test completed", "", "Channel test completed, if you have not received the disable notification, it means that all channels are normal")
|
||||
if err != nil {
|
||||
logger.SysError(fmt.Sprintf("failed to send email: %s", err.Error()))
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func SendEmailVerification(c *gin.Context) {
|
||||
if err := common.Validate.Var(email, "required,email"); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func SendEmailVerification(c *gin.Context) {
|
||||
if !allowed {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员启用了邮箱域名白名单,您的邮箱地址的域名不在白名单中",
|
||||
"message": "AdministratorEnable了邮箱域名白名单,您的Email address的域名不在白名单中",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -108,16 +108,16 @@ func SendEmailVerification(c *gin.Context) {
|
||||
if model.IsEmailAlreadyTaken(email) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "邮箱地址已被占用",
|
||||
"message": "Email address is occupied",
|
||||
})
|
||||
return
|
||||
}
|
||||
code := common.GenerateVerificationCode(6)
|
||||
common.RegisterVerificationCodeWithKey(email, code, common.EmailVerificationPurpose)
|
||||
subject := fmt.Sprintf("%s邮箱验证邮件", config.SystemName)
|
||||
content := fmt.Sprintf("<p>您好,你正在进行%s邮箱验证。</p>"+
|
||||
"<p>您的验证码为: <strong>%s</strong></p>"+
|
||||
"<p>验证码 %d 分钟内有效,如果不是本人操作,请忽略。</p>", config.SystemName, code, common.VerificationValidMinutes)
|
||||
subject := fmt.Sprintf("%s Email verification email", config.SystemName)
|
||||
content := fmt.Sprintf("<p>Hello, you are verifying %s email.</p>"+
|
||||
"<p>Your verification code is: <strong>%s</strong></p>"+
|
||||
"<p>The verification code is valid within %d minutes. If it is not your operation, please ignore it.</p>", config.SystemName, code, common.VerificationValidMinutes)
|
||||
err := message.SendEmail(subject, email, content)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -138,25 +138,25 @@ func SendPasswordResetEmail(c *gin.Context) {
|
||||
if err := common.Validate.Var(email, "required,email"); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
if !model.IsEmailAlreadyTaken(email) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该邮箱地址未注册",
|
||||
"message": "The email address is not registered",
|
||||
})
|
||||
return
|
||||
}
|
||||
code := common.GenerateVerificationCode(0)
|
||||
common.RegisterVerificationCodeWithKey(email, code, common.PasswordResetPurpose)
|
||||
link := fmt.Sprintf("%s/user/reset?email=%s&token=%s", config.ServerAddress, email, code)
|
||||
subject := fmt.Sprintf("%s密码重置", config.SystemName)
|
||||
content := fmt.Sprintf("<p>您好,你正在进行%s密码重置。</p>"+
|
||||
"<p>点击 <a href='%s'>此处</a> 进行密码重置。</p>"+
|
||||
"<p>如果链接无法点击,请尝试点击下面的链接或将其复制到浏览器中打开:<br> %s </p>"+
|
||||
"<p>重置链接 %d 分钟内有效,如果不是本人操作,请忽略。</p>", config.SystemName, link, link, common.VerificationValidMinutes)
|
||||
subject := fmt.Sprintf("%s Password reset", config.SystemName)
|
||||
content := fmt.Sprintf("<p>Hello, you are resetting %s password.</p>"+
|
||||
"<p>点击 <a href='%s'>此处</a> 进行Password reset。</p>"+
|
||||
"<p>如果链接None法点击,请尝试点击下面的链接或将其Copy到浏览器中打开:<br> %s </p>"+
|
||||
"<p>The reset link is valid within %d minutes. If it is not your operation, please ignore it.</p>", config.SystemName, link, link, common.VerificationValidMinutes)
|
||||
err := message.SendEmail(subject, email, content)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@@ -183,14 +183,14 @@ func ResetPassword(c *gin.Context) {
|
||||
if req.Email == "" || req.Token == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
if !common.VerifyCodeWithKey(req.Email, req.Token, common.PasswordResetPurpose) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "重置链接非法或已过期",
|
||||
"message": "Reset link is illegal or expired",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if !config.ValidThemes[option.Value] {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的主题",
|
||||
"message": "None效的主题",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if option.Value == "true" && config.GitHubClientId == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法启用 GitHub OAuth,请先填入 GitHub Client Id 以及 GitHub Client Secret!",
|
||||
"message": "None法Enable GitHub OAuth,请先填入 GitHub Client Id 以及 GitHub Client Secret!",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if option.Value == "true" && len(config.EmailDomainWhitelist) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法启用邮箱域名限制,请先填入限制的邮箱域名!",
|
||||
"message": "None法Enable邮箱域名限制,请先填入限制的邮箱域名!",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if option.Value == "true" && config.WeChatServerAddress == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法启用微信登录,请先填入微信登录相关配置信息!",
|
||||
"message": "Unable to enable WeChat login, please fill in the relevant configuration information for WeChat login first!",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func UpdateOption(c *gin.Context) {
|
||||
if option.Value == "true" && config.TurnstileSiteKey == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法启用 Turnstile 校验,请先填入 Turnstile 校验相关配置信息!",
|
||||
"message": "Unable to enable Turnstile verification, please fill in the relevant configuration information for Turnstile verification first!",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,21 +89,21 @@ func AddRedemption(c *gin.Context) {
|
||||
if len(redemption.Name) == 0 || len(redemption.Name) > 20 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "兑换码名称长度必须在1-20之间",
|
||||
"message": "The length of the redemption code name must be between 1-20",
|
||||
})
|
||||
return
|
||||
}
|
||||
if redemption.Count <= 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "兑换码个数必须大于0",
|
||||
"message": "The number of redemption codes must be greater than 0",
|
||||
})
|
||||
return
|
||||
}
|
||||
if redemption.Count > 100 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "一次兑换码批量生成的个数不能大于 100",
|
||||
"message": "The number of redemption codes generated in a batch cannot be greater than 100",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func Relay(c *gin.Context) {
|
||||
|
||||
if bizErr != nil {
|
||||
if bizErr.StatusCode == http.StatusTooManyRequests {
|
||||
bizErr.Error.Message = "当前分组上游负载已饱和,请稍后再试"
|
||||
bizErr.Error.Message = "The current group load is saturated, please try again later"
|
||||
}
|
||||
|
||||
// BUG: bizErr is in race condition
|
||||
|
||||
@@ -134,13 +134,13 @@ func GetTokenStatus(c *gin.Context) {
|
||||
|
||||
func validateToken(c *gin.Context, token *model.Token) error {
|
||||
if len(token.Name) > 30 {
|
||||
return fmt.Errorf("令牌名称过长")
|
||||
return fmt.Errorf("Token name is too long")
|
||||
}
|
||||
|
||||
if token.Subnet != nil && *token.Subnet != "" {
|
||||
err := network.IsValidSubnets(*token.Subnet)
|
||||
if err != nil {
|
||||
return fmt.Errorf("无效的网段:%s", err.Error())
|
||||
return fmt.Errorf("None效的网段:%s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ func AddToken(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": fmt.Sprintf("参数错误:%s", err.Error()),
|
||||
"message": fmt.Sprintf("参数Error:%s", err.Error()),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -247,7 +247,7 @@ func ConsumeToken(c *gin.Context) {
|
||||
if cleanToken.Status != model.TokenStatusEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "令牌未启用",
|
||||
"message": "API KeysNot enabled",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func ConsumeToken(c *gin.Context) {
|
||||
cleanToken.ExpiredTime <= helper.GetTimestamp() && cleanToken.ExpiredTime != -1 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "令牌已过期,无法启用,请先修改令牌过期时间,或者设置为永不过期",
|
||||
"message": "The token has expired and cannot be enabled. Please modify the expiration time of the token, or set it to never expire.",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -264,7 +264,7 @@ func ConsumeToken(c *gin.Context) {
|
||||
cleanToken.RemainQuota <= 0 && !cleanToken.UnlimitedQuota {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "令牌可用额度已用尽,无法启用,请先修改令牌剩余额度,或者设置为无限额度",
|
||||
"message": "The available quota of the token has been used up and cannot be enabled. Please modify the remaining quota of the token, or set it to unlimited quota",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -274,7 +274,7 @@ func ConsumeToken(c *gin.Context) {
|
||||
if cleanToken.RemainQuota < int64(tokenPatch.AddUsedQuota) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "剩余额度不足",
|
||||
"message": "Remaining quota不足",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func UpdateToken(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": fmt.Sprintf("参数错误:%s", err.Error()),
|
||||
"message": fmt.Sprintf("参数Error:%s", err.Error()),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func UpdateToken(c *gin.Context) {
|
||||
token.ExpiredTime != -1 && token.ExpiredTime < helper.GetTimestamp() {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "令牌已过期,无法启用,请先修改令牌过期时间,或者设置为永不过期",
|
||||
"message": "The token has expired and cannot be enabled. Please modify the expiration time of the token, or set it to never expire.",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -366,7 +366,7 @@ func UpdateToken(c *gin.Context) {
|
||||
token.RemainQuota <= 0 && !token.UnlimitedQuota {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "令牌可用额度已用尽,无法启用,请先修改令牌剩余额度,或者设置为无限额度",
|
||||
"message": "The available quota of the token has been used up and cannot be enabled. Please modify the remaining quota of the token, or set it to unlimited quota",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type LoginRequest struct {
|
||||
func Login(c *gin.Context) {
|
||||
if !config.PasswordLoginEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "管理员关闭了密码登录",
|
||||
"message": "The administrator has turned off password login",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -33,7 +33,7 @@ func Login(c *gin.Context) {
|
||||
err := json.NewDecoder(c.Request.Body).Decode(&loginRequest)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -42,7 +42,7 @@ func Login(c *gin.Context) {
|
||||
password := loginRequest.Password
|
||||
if username == "" || password == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -72,7 +72,7 @@ func SetupLogin(user *model.User, c *gin.Context) {
|
||||
err := session.Save()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "无法保存会话信息,请重试",
|
||||
"message": "Unable to save session information, please try again",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -117,14 +117,14 @@ func Logout(c *gin.Context) {
|
||||
func Register(c *gin.Context) {
|
||||
if !config.RegisterEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "管理员关闭了新用户注册",
|
||||
"message": "The administrator has turned off new user registration",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
if !config.PasswordRegisterEnabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "管理员关闭了通过密码进行注册,请使用第三方账户验证的形式进行注册",
|
||||
"message": "The administrator has turned off registration via password. Please use the form of third-party account verification to register",
|
||||
"success": false,
|
||||
})
|
||||
return
|
||||
@@ -134,14 +134,14 @@ func Register(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
if err := common.Validate.Struct(&user); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "输入不合法 " + err.Error(),
|
||||
"message": "Input is illegal " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -149,14 +149,14 @@ func Register(c *gin.Context) {
|
||||
if user.Email == "" || user.VerificationCode == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "管理员开启了邮箱验证,请输入邮箱地址和验证码",
|
||||
"message": "The administrator has turned on email verification, please enter the email address and verification code",
|
||||
})
|
||||
return
|
||||
}
|
||||
if !common.VerifyCodeWithKey(user.Email, user.VerificationCode, common.EmailVerificationPurpose) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "验证码错误或已过期",
|
||||
"message": "Verification code error or expired",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func GetUser(c *gin.Context) {
|
||||
if myRole <= user.Role && myRole != model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无权获取同级或更高等级用户的信息",
|
||||
"message": "No permission to get information of users at the same level or higher",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -271,7 +271,7 @@ func GetUserDashboard(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法获取统计信息",
|
||||
"message": "None法获取Statistics",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
@@ -299,7 +299,7 @@ func GenerateAccessToken(c *gin.Context) {
|
||||
if model.DB.Where("access_token = ?", user.AccessToken).First(user).RowsAffected != 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "请重试,系统生成的 UUID 竟然重复了!",
|
||||
"message": "Please try again, the system-generated UUID is actually duplicated!",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -382,7 +382,7 @@ func UpdateUser(c *gin.Context) {
|
||||
if err != nil || updatedUser.Id == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -392,7 +392,7 @@ func UpdateUser(c *gin.Context) {
|
||||
if err := common.Validate.Struct(&updatedUser); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "输入不合法 " + err.Error(),
|
||||
"message": "Input is illegal " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -408,14 +408,14 @@ func UpdateUser(c *gin.Context) {
|
||||
if myRole <= originUser.Role && myRole != model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无权更新同权限等级或更高权限等级的用户信息",
|
||||
"message": "No permission to update user information with the same permission level or higher permission level",
|
||||
})
|
||||
return
|
||||
}
|
||||
if myRole <= updatedUser.Role && myRole != model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无权将其他用户权限等级提升到大于等于自己的权限等级",
|
||||
"message": "None权将其他Users权限等级Promote到大于Equals自己的权限等级",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -431,7 +431,7 @@ func UpdateUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if originUser.Quota != updatedUser.Quota {
|
||||
model.RecordLog(originUser.Id, model.LogTypeManage, fmt.Sprintf("管理员将用户额度从 %s修改为 %s", common.LogQuota(originUser.Quota), common.LogQuota(updatedUser.Quota)))
|
||||
model.RecordLog(originUser.Id, model.LogTypeManage, fmt.Sprintf("The administrator changed the user quota from %s to %s", common.LogQuota(originUser.Quota), common.LogQuota(updatedUser.Quota)))
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
@@ -446,7 +446,7 @@ func UpdateSelf(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func UpdateSelf(c *gin.Context) {
|
||||
if err := common.Validate.Struct(&user); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "输入不合法 " + err.Error(),
|
||||
"message": "Input is illegal " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -508,7 +508,7 @@ func DeleteUser(c *gin.Context) {
|
||||
if myRole <= originUser.Role {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无权删除同权限等级或更高权限等级的用户",
|
||||
"message": "No permission to delete users with the same permission level or higher permission level",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -529,7 +529,7 @@ func DeleteSelf(c *gin.Context) {
|
||||
if user.Role == model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "不能删除超级管理员账户",
|
||||
"message": "不能DeleteSuper administrator账户",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -555,14 +555,14 @@ func CreateUser(c *gin.Context) {
|
||||
if err != nil || user.Username == "" || user.Password == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
if err := common.Validate.Struct(&user); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "输入不合法 " + err.Error(),
|
||||
"message": "Input is illegal " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -573,7 +573,7 @@ func CreateUser(c *gin.Context) {
|
||||
if user.Role >= myRole {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法创建权限大于等于自己的用户",
|
||||
"message": "Unable to create users with permissions greater than or equal to your own",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -611,7 +611,7 @@ func ManageUser(c *gin.Context) {
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无效的参数",
|
||||
"message": "Invalid parameter",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -623,7 +623,7 @@ func ManageUser(c *gin.Context) {
|
||||
if user.Id == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "用户不存在",
|
||||
"message": "User does not exist",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -631,7 +631,7 @@ func ManageUser(c *gin.Context) {
|
||||
if myRole <= user.Role && myRole != model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无权更新同权限等级或更高权限等级的用户信息",
|
||||
"message": "No permission to update user information with the same permission level or higher permission level",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -641,7 +641,7 @@ func ManageUser(c *gin.Context) {
|
||||
if user.Role == model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法禁用超级管理员用户",
|
||||
"message": "Unable to disable super administrator user",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -651,7 +651,7 @@ func ManageUser(c *gin.Context) {
|
||||
if user.Role == model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法删除超级管理员用户",
|
||||
"message": "Unable to delete super administrator user",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -666,14 +666,14 @@ func ManageUser(c *gin.Context) {
|
||||
if myRole != model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "普通管理员用户无法提升其他用户为管理员",
|
||||
"message": "Ordinary administrator users cannot promote other users to administrators",
|
||||
})
|
||||
return
|
||||
}
|
||||
if user.Role >= model.RoleAdminUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该用户已经是管理员",
|
||||
"message": "The user is already an administrator",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -682,14 +682,14 @@ func ManageUser(c *gin.Context) {
|
||||
if user.Role == model.RoleRootUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "无法降级超级管理员用户",
|
||||
"message": "Unable to downgrade super administrator user",
|
||||
})
|
||||
return
|
||||
}
|
||||
if user.Role == model.RoleCommonUser {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "该用户已经是普通用户",
|
||||
"message": "The user is already an ordinary user",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -721,7 +721,7 @@ func EmailBind(c *gin.Context) {
|
||||
if !common.VerifyCodeWithKey(email, code, common.EmailVerificationPurpose) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "验证码错误或已过期",
|
||||
"message": "Verification code error or expired",
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -813,7 +813,7 @@ func AdminTopUp(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if req.Remark == "" {
|
||||
req.Remark = fmt.Sprintf("通过 API 充值 %s", common.LogQuota(int64(req.Quota)))
|
||||
req.Remark = fmt.Sprintf("通过 API Recharge %s", common.LogQuota(int64(req.Quota)))
|
||||
}
|
||||
model.RecordTopupLog(req.UserId, req.Remark, req.Quota)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
||||
Reference in New Issue
Block a user