i18n: Translate all Chinese to English across the codebase
Translate Chinese comments, log/error messages, validator labels and Swagger annotations to English throughout the source code, generated Swagger docs, config files and CI workflows. Make the English README primary: README.md now holds the English docs and README_EN.md holds the Chinese version, with cross-language links updated accordingly. Note: the generated docs/ swagger files were translated in place; run `go generate ./...` (swag init) to regenerate them from the now-English annotations when a Go toolchain is available. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+58
-58
@@ -20,9 +20,9 @@ type Ab struct {
|
||||
}
|
||||
|
||||
// Ab
|
||||
// @Tags 地址
|
||||
// @Summary 地址列表
|
||||
// @Description 地址列表
|
||||
// @Tags address
|
||||
// @Summary address list
|
||||
// @Description address list
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response
|
||||
@@ -36,7 +36,7 @@ func (a *Ab) Ab(c *gin.Context) {
|
||||
tags := service.AllService.TagService.ListByUserIdAndCollectionId(user.Id, 0)
|
||||
|
||||
tagColors := map[string]uint{}
|
||||
//将tags中的name转成一个以逗号分割的字符串
|
||||
// convert the name in tags into a comma-separated string
|
||||
var tagNames []string
|
||||
for _, tag := range tags.Tags {
|
||||
tagNames = append(tagNames, tag.Name)
|
||||
@@ -56,12 +56,12 @@ func (a *Ab) Ab(c *gin.Context) {
|
||||
}
|
||||
|
||||
// UpAb
|
||||
// @Tags 地址
|
||||
// @Summary 地址更新
|
||||
// @Description 地址更新
|
||||
// @Tags address
|
||||
// @Summary address update
|
||||
// @Description address update
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body requstform.AddressBookForm true "地址表单"
|
||||
// @Param body body requstform.AddressBookForm true "address form"
|
||||
// @Success 200 {string} string "null"
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /ab [post]
|
||||
@@ -99,9 +99,9 @@ func (a *Ab) UpAb(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PTags
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 标签
|
||||
// @Description 标签
|
||||
// @Tags address[Personal]
|
||||
// @Summary tag
|
||||
// @Description tag
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -128,9 +128,9 @@ func (a *Ab) PTags(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TagAdd
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 标签添加
|
||||
// @Description 标签
|
||||
// @Tags address[Personal]
|
||||
// @Summary add tag
|
||||
// @Description tag
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -177,9 +177,9 @@ func (a *Ab) TagAdd(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TagRename
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 标签重命名
|
||||
// @Description 标签
|
||||
// @Tags address[Personal]
|
||||
// @Summary rename tag
|
||||
// @Description tag
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -229,9 +229,9 @@ func (a *Ab) TagRename(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TagUpdate
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 标签修改颜色
|
||||
// @Description 标签
|
||||
// @Tags address[Personal]
|
||||
// @Summary change tag color
|
||||
// @Description tag
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -275,9 +275,9 @@ func (a *Ab) TagUpdate(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TagDel
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 标签删除
|
||||
// @Description 标签
|
||||
// @Tags address[Personal]
|
||||
// @Summary delete tag
|
||||
// @Description tag
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -324,9 +324,9 @@ func (a *Ab) TagDel(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Personal
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 个人地址
|
||||
// @Description 个人地址
|
||||
// @Tags address[Personal]
|
||||
// @Summary personal address
|
||||
// @Description personal address
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param string body string false "string valid"
|
||||
@@ -345,7 +345,7 @@ func (a *Ab) Personal(c *gin.Context) {
|
||||
*/
|
||||
if global.Config.Rustdesk.Personal == 1 {
|
||||
guid := a.ComposeGuid(user.GroupId, user.Id, 0)
|
||||
//如果返回了guid,后面的请求会有变化
|
||||
//if it returns guid, subsequent requests will change
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"guid": guid,
|
||||
"name": user.Username,
|
||||
@@ -358,9 +358,9 @@ func (a *Ab) Personal(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Settings
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 设置
|
||||
// @Description 设置
|
||||
// @Tags address[Personal]
|
||||
// @Summary settings
|
||||
// @Description settings
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param string body string false "string valid"
|
||||
@@ -370,18 +370,18 @@ func (a *Ab) Personal(c *gin.Context) {
|
||||
// @Security BearerAuth
|
||||
func (a *Ab) Settings(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"max_peer_one_ab": 0, //最大peer数,0表示不限制
|
||||
"max_peer_one_ab": 0, //max peer count, 0 means no limit
|
||||
})
|
||||
}
|
||||
|
||||
// SharedProfiles
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 共享地址簿
|
||||
// @Description 共享
|
||||
// @Tags address[Personal]
|
||||
// @Summary shared address book
|
||||
// @Description shared
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param current query int false "页码"
|
||||
// @Param pageSize query int false "每页数量"
|
||||
// @Param current query int false "page number"
|
||||
// @Param pageSize query int false "items per page"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 500 {object} response.Response
|
||||
// @Router /ab/shared/profiles [post]
|
||||
@@ -401,14 +401,14 @@ func (a *Ab) SharedProfiles(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
allAbIds := make(map[uint]int) //用map去重,并保留最大Rule
|
||||
allAbIds := make(map[uint]int) //use map to deduplicate and keep the maximum Rule
|
||||
allUserIds := make(map[uint]*model.User)
|
||||
rules := service.AllService.AddressBookService.CollectionReadRules(user)
|
||||
for _, rule := range rules {
|
||||
//先判断是否存在
|
||||
//first check whether it exists
|
||||
r, ok := allAbIds[rule.CollectionId]
|
||||
if ok {
|
||||
//再判断权限大小
|
||||
//then check the permission level
|
||||
if r < rule.Rule {
|
||||
allAbIds[rule.CollectionId] = rule.Rule
|
||||
}
|
||||
@@ -448,7 +448,7 @@ func (a *Ab) SharedProfiles(c *gin.Context) {
|
||||
|
||||
// ParseGuid
|
||||
func (a *Ab) ParseGuid(guid string) (gid, uid, cid uint) {
|
||||
//用-切割 guid
|
||||
// split guid by -
|
||||
guids := strings.Split(guid, "-")
|
||||
if len(guids) < 2 {
|
||||
return 0, 0, 0
|
||||
@@ -521,13 +521,13 @@ func (a *Ab) CheckGuid(cu *model.User, guid string) (gid, uid, cid uint, err err
|
||||
}
|
||||
|
||||
// Peers
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 地址列表
|
||||
// @Description 地址
|
||||
// @Tags address[Personal]
|
||||
// @Summary address list
|
||||
// @Description address
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param current query int false "页码"
|
||||
// @Param pageSize query int false "每页数量"
|
||||
// @Param current query int false "page number"
|
||||
// @Param pageSize query int false "items per page"
|
||||
// @Param ab query string false "guid"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 500 {object} response.Response
|
||||
@@ -557,9 +557,9 @@ func (a *Ab) Peers(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PeerAdd
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 添加地址
|
||||
// @Description 添加地址
|
||||
// @Tags address[Personal]
|
||||
// @Summary add address
|
||||
// @Description add address
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -568,7 +568,7 @@ func (a *Ab) Peers(c *gin.Context) {
|
||||
// @Router /ab/peer/add/{guid} [post]
|
||||
// @Security BearerAuth
|
||||
func (a *Ab) PeerAdd(c *gin.Context) {
|
||||
// forceAlwaysRelay永远是字符串"false"
|
||||
// forceAlwaysRelay is always the string "false"
|
||||
//f := &gin.H{}
|
||||
f := &requstform.PersonalAddressBookForm{}
|
||||
err := c.ShouldBindJSON(f)
|
||||
@@ -613,9 +613,9 @@ func (a *Ab) PeerAdd(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PeerDel
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 删除地址
|
||||
// @Description 删除地址
|
||||
// @Tags address[Personal]
|
||||
// @Summary delete address
|
||||
// @Description delete address
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -661,9 +661,9 @@ func (a *Ab) PeerDel(c *gin.Context) {
|
||||
}
|
||||
|
||||
// PeerUpdate
|
||||
// @Tags 地址[Personal]
|
||||
// @Summary 更新地址
|
||||
// @Description 更新地址
|
||||
// @Tags address[Personal]
|
||||
// @Summary update address
|
||||
// @Description update address
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param guid path string true "guid"
|
||||
@@ -693,7 +693,7 @@ func (a *Ab) PeerUpdate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
//fmt.Println(f)
|
||||
//判断f["Id"]是否存在
|
||||
// determine whether f["Id"] exists
|
||||
fid, ok := f["id"]
|
||||
if !ok {
|
||||
response.Error(c, response.TranslateMsg(c, "ParamsError"))
|
||||
@@ -706,9 +706,9 @@ func (a *Ab) PeerUpdate(c *gin.Context) {
|
||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||
return
|
||||
}
|
||||
//允许的字段
|
||||
//allowed fields
|
||||
allowUp := []string{"password", "hash", "tags", "alias"}
|
||||
//f中的字段如果不在allowUp中,就删除
|
||||
// if a field in f is not in allowUp, delete it
|
||||
for k := range f {
|
||||
if !utils.InArray(k, allowUp) {
|
||||
delete(f, k)
|
||||
|
||||
@@ -14,12 +14,12 @@ type Audit struct {
|
||||
}
|
||||
|
||||
// AuditConn
|
||||
// @Tags 审计
|
||||
// @Summary 审计连接
|
||||
// @Description 审计连接
|
||||
// @Tags audit
|
||||
// @Summary audit connection
|
||||
// @Description audit connection
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body request.AuditConnForm true "审计连接"
|
||||
// @Param body body request.AuditConnForm true "audit connection"
|
||||
// @Success 200 {string} string ""
|
||||
// @Failure 500 {object} response.Response
|
||||
// @Router /audit/conn [post]
|
||||
@@ -59,12 +59,12 @@ func (a *Audit) AuditConn(c *gin.Context) {
|
||||
}
|
||||
|
||||
// AuditFile
|
||||
// @Tags 审计
|
||||
// @Summary 审计文件
|
||||
// @Description 审计文件
|
||||
// @Tags audit
|
||||
// @Summary audit file
|
||||
// @Description audit file
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body request.AuditFileForm true "审计文件"
|
||||
// @Param body body request.AuditFileForm true "audit file"
|
||||
// @Success 200 {string} string ""
|
||||
// @Failure 500 {object} response.Response
|
||||
// @Router /audit/file [post]
|
||||
|
||||
@@ -13,15 +13,15 @@ import (
|
||||
type Group struct {
|
||||
}
|
||||
|
||||
// Users 用户列表
|
||||
// @Tags 群组
|
||||
// @Summary 用户列表
|
||||
// @Description 用户列表
|
||||
// Users user list
|
||||
// @Tags group
|
||||
// @Summary user list
|
||||
// @Description user list
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "页码"
|
||||
// @Param pageSize query int false "每页数量"
|
||||
// @Param status query int false "状态"
|
||||
// @Param page query int false "page number"
|
||||
// @Param pageSize query int false "items per page"
|
||||
// @Param status query int false "status"
|
||||
// @Param accessible query string false "accessible"
|
||||
// @Success 200 {object} response.DataResponse{data=[]apiResp.UserPayload}
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
@@ -38,7 +38,7 @@ func (g *Group) Users(c *gin.Context) {
|
||||
gr := service.AllService.GroupService.InfoById(u.GroupId)
|
||||
userList := &model.UserList{}
|
||||
if !*u.IsAdmin && gr.Type != model.GroupTypeShare {
|
||||
//仅能获取到自己
|
||||
//can only retrieve one's own
|
||||
userList.Users = append(userList.Users, u)
|
||||
userList.Total = 1
|
||||
} else {
|
||||
@@ -58,14 +58,14 @@ func (g *Group) Users(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Peers
|
||||
// @Tags 群组
|
||||
// @Summary 机器
|
||||
// @Description 机器
|
||||
// @Tags group
|
||||
// @Summary machine
|
||||
// @Description machine
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "页码"
|
||||
// @Param pageSize query int false "每页数量"
|
||||
// @Param status query int false "状态"
|
||||
// @Param page query int false "page number"
|
||||
// @Param pageSize query int false "items per page"
|
||||
// @Param status query int false "status"
|
||||
// @Param accessible query string false "accessible"
|
||||
// @Success 200 {object} response.DataResponse
|
||||
// @Failure 500 {object} response.Response
|
||||
@@ -82,7 +82,7 @@ func (g *Group) Peers(c *gin.Context) {
|
||||
gr := service.AllService.GroupService.InfoById(u.GroupId)
|
||||
users := make([]*model.User, 0, 1)
|
||||
if !*u.IsAdmin && gr.Type != model.GroupTypeShare {
|
||||
//仅能获取到自己
|
||||
//can only retrieve one's own
|
||||
users = append(users, u)
|
||||
} else {
|
||||
users = service.AllService.UserService.ListIdAndNameByGroupId(u.GroupId)
|
||||
@@ -122,14 +122,14 @@ func (g *Group) Peers(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Device
|
||||
// @Tags 群组
|
||||
// @Summary 设备
|
||||
// @Description 机器
|
||||
// @Tags group
|
||||
// @Summary device
|
||||
// @Description machine
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param page query int false "页码"
|
||||
// @Param pageSize query int false "每页数量"
|
||||
// @Param status query int false "状态"
|
||||
// @Param page query int false "page number"
|
||||
// @Param pageSize query int false "items per page"
|
||||
// @Param status query int false "status"
|
||||
// @Param accessible query string false "accessible"
|
||||
// @Success 200 {object} response.DataResponse
|
||||
// @Failure 500 {object} response.Response
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
type Index struct {
|
||||
}
|
||||
|
||||
// Index 首页
|
||||
// @Tags 首页
|
||||
// @Summary 首页
|
||||
// @Description 首页
|
||||
// Index home
|
||||
// @Tags home
|
||||
// @Summary home
|
||||
// @Description home
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response
|
||||
@@ -29,10 +29,10 @@ func (i *Index) Index(c *gin.Context) {
|
||||
)
|
||||
}
|
||||
|
||||
// Heartbeat 心跳
|
||||
// @Tags 首页
|
||||
// @Summary 心跳
|
||||
// @Description 心跳
|
||||
// Heartbeat heartbeat
|
||||
// @Tags home
|
||||
// @Summary heartbeat
|
||||
// @Description heartbeat
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} nil
|
||||
@@ -54,7 +54,7 @@ func (i *Index) Heartbeat(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
//如果在40s以内则不更新
|
||||
// do not update if within 40s
|
||||
if time.Now().Unix()-peer.LastOnlineTime >= 30 {
|
||||
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
|
||||
service.AllService.PeerService.Update(upp)
|
||||
@@ -62,17 +62,17 @@ func (i *Index) Heartbeat(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
}
|
||||
|
||||
// Version 版本
|
||||
// @Tags 首页
|
||||
// @Summary 版本
|
||||
// @Description 版本
|
||||
// Version version
|
||||
// @Tags home
|
||||
// @Summary version
|
||||
// @Description version
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response
|
||||
// @Failure 500 {object} response.Response
|
||||
// @Router /version [get]
|
||||
func (i *Index) Version(c *gin.Context) {
|
||||
//读取resources/version文件
|
||||
// read the resources/version file
|
||||
v := service.AllService.AppService.GetAppVersion()
|
||||
response.Success(
|
||||
c,
|
||||
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
type Login struct {
|
||||
}
|
||||
|
||||
// Login 登录
|
||||
// @Tags 登录
|
||||
// @Summary 登录
|
||||
// @Description 登录
|
||||
// Login login
|
||||
// @Tags login
|
||||
// @Summary login
|
||||
// @Description login
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body api.LoginForm true "登录表单"
|
||||
// @Param body body api.LoginForm true "login form"
|
||||
// @Success 200 {object} apiResp.LoginRes
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /login [post]
|
||||
@@ -32,7 +32,7 @@ func (l *Login) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查登录限制
|
||||
// check login limit
|
||||
loginLimiter := global.LoginLimiter
|
||||
clientIp := c.ClientIP()
|
||||
|
||||
@@ -68,7 +68,7 @@ func (l *Login) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
//根据refer判断是webclient还是app
|
||||
// determine whether it is webclient or app based on refer
|
||||
ref := c.GetHeader("referer")
|
||||
if ref != "" {
|
||||
f.DeviceInfo.Type = model.LoginLogClientWeb
|
||||
@@ -92,9 +92,9 @@ func (l *Login) Login(c *gin.Context) {
|
||||
}
|
||||
|
||||
// LoginOptions
|
||||
// @Tags 登录
|
||||
// @Summary 登录选项
|
||||
// @Description 登录选项
|
||||
// @Tags login
|
||||
// @Summary login options
|
||||
// @Description login options
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} []string
|
||||
@@ -123,9 +123,9 @@ func (l *Login) LoginOptions(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Logout
|
||||
// @Tags 登录
|
||||
// @Summary 登出
|
||||
// @Description 登出
|
||||
// @Tags login
|
||||
// @Summary logout
|
||||
// @Description logout
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} string
|
||||
|
||||
@@ -65,37 +65,37 @@ func (o *Oauth) OidcAuthQueryPre(c *gin.Context) (*model.User, *model.UserToken)
|
||||
var ut *model.UserToken
|
||||
q := &api.OidcAuthQuery{}
|
||||
|
||||
// 解析查询参数并处理错误
|
||||
// parse query parameters and handle errors
|
||||
if err := c.ShouldBindQuery(q); err != nil {
|
||||
response.Error(c, response.TranslateMsg(c, "ParamsError")+": "+err.Error())
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 获取 OAuth 缓存
|
||||
// get OAuth cache
|
||||
v := service.AllService.OauthService.GetOauthCache(q.Code)
|
||||
if v == nil {
|
||||
response.Error(c, response.TranslateMsg(c, "OauthExpired"))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 如果 UserId 为 0,说明还在授权中
|
||||
// if UserId is 0, authorization is still in progress
|
||||
if v.UserId == 0 {
|
||||
//fix: 1.4.2 webclient oidc
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Authorization in progress, please login and bind", "error": "No authed oidc is found"})
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
// get user info
|
||||
u = service.AllService.UserService.InfoById(v.UserId)
|
||||
if u == nil {
|
||||
response.Error(c, response.TranslateMsg(c, "UserNotFound"))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 删除 OAuth 缓存
|
||||
// delete OAuth cache
|
||||
service.AllService.OauthService.DeleteOauthCache(q.Code)
|
||||
|
||||
// 创建登录日志并生成用户令牌
|
||||
// create a login log and generate a user token
|
||||
ut = service.AllService.UserService.Login(u, &model.LoginLog{
|
||||
UserId: u.Id,
|
||||
Client: v.DeviceType,
|
||||
@@ -111,7 +111,7 @@ func (o *Oauth) OidcAuthQueryPre(c *gin.Context) (*model.User, *model.UserToken)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 返回用户令牌
|
||||
// return user token
|
||||
return u, ut
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func (o *Oauth) OidcAuthQuery(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// OauthCallback 回调
|
||||
// OauthCallback callback
|
||||
// @Tags Oauth
|
||||
// @Summary OauthCallback
|
||||
// @Description OauthCallback
|
||||
@@ -156,7 +156,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
}
|
||||
cacheKey := state
|
||||
oauthService := service.AllService.OauthService
|
||||
//从缓存中获取
|
||||
//get from cache
|
||||
oauthCache := oauthService.GetOauthCache(cacheKey)
|
||||
if oauthCache == nil {
|
||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||
@@ -169,7 +169,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
action := oauthCache.Action
|
||||
verifier := oauthCache.Verifier
|
||||
var user *model.User
|
||||
// 获取用户信息
|
||||
// get user info
|
||||
code := c.Query("code")
|
||||
err, oauthUser := oauthService.Callback(code, verifier, op, nonce)
|
||||
if err != nil {
|
||||
@@ -184,7 +184,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
if action == service.OauthActionTypeBind {
|
||||
|
||||
//fmt.Println("bind", ty, userData)
|
||||
// 检查此openid是否已经绑定过
|
||||
// check whether this openid has already been bound
|
||||
utr := oauthService.UserThirdInfo(op, openid)
|
||||
if utr.UserId > 0 {
|
||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||
@@ -192,7 +192,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
//绑定
|
||||
//bind
|
||||
user = service.AllService.UserService.InfoById(userId)
|
||||
if user == nil {
|
||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||
@@ -200,7 +200,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
//绑定
|
||||
//bind
|
||||
err := oauthService.BindOauthUser(userId, oauthUser, op)
|
||||
if err != nil {
|
||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||
@@ -214,7 +214,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
return
|
||||
|
||||
} else if action == service.OauthActionTypeLogin {
|
||||
//登录
|
||||
//login
|
||||
if userId != 0 {
|
||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||
"message": "OauthHasBeenSuccess",
|
||||
@@ -225,13 +225,13 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
if user == nil {
|
||||
oauthConfig := oauthService.InfoByOp(op)
|
||||
if !*oauthConfig.AutoRegister {
|
||||
//c.String(http.StatusInternalServerError, "还未绑定用户,请先绑定")
|
||||
//c.String(http.StatusInternalServerError, "not yet bound to a user, please bind first")
|
||||
oauthCache.UpdateFromOauthUser(oauthUser)
|
||||
c.Redirect(http.StatusFound, "/_admin/#/oauth/bind/"+cacheKey)
|
||||
return
|
||||
}
|
||||
|
||||
//自动注册
|
||||
//auto register
|
||||
err, user = service.AllService.UserService.RegisterByOauth(oauthUser, op)
|
||||
if err != nil {
|
||||
c.HTML(http.StatusOK, "oauth_fail.html", gin.H{
|
||||
@@ -242,7 +242,7 @@ func (o *Oauth) OauthCallback(c *gin.Context) {
|
||||
}
|
||||
oauthCache.UserId = user.Id
|
||||
oauthService.SetOauthCache(cacheKey, oauthCache, 0)
|
||||
// 如果是webadmin,登录成功后跳转到webadmin
|
||||
// if it is webadmin, after successful login redirect to webadmin
|
||||
if oauthCache.DeviceType == model.LoginLogClientWebAdmin {
|
||||
/*service.AllService.UserService.Login(u, &model.LoginLog{
|
||||
UserId: u.Id,
|
||||
@@ -299,7 +299,7 @@ func (o *Oauth) Message(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
//返回js内容
|
||||
//returnjscontent
|
||||
c.Header("Content-Type", "application/javascript")
|
||||
c.String(http.StatusOK, res)
|
||||
}
|
||||
|
||||
+10
-10
@@ -15,11 +15,11 @@ type Peer struct {
|
||||
|
||||
// SysInfo
|
||||
// @Tags System
|
||||
// @Summary 提交系统信息
|
||||
// @Description 提交系统信息
|
||||
// @Summary submit system info
|
||||
// @Description submit system info
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body requstform.PeerForm true "系统信息表单"
|
||||
// @Param body body requstform.PeerForm true "system info form"
|
||||
// @Success 200 {string} string "SYSINFO_UPDATED,ID_NOT_FOUND"
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /sysinfo [post]
|
||||
@@ -52,25 +52,25 @@ func (p *Peer) SysInfo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
//SYSINFO_UPDATED 上传成功
|
||||
//ID_NOT_FOUND 下次心跳会上传
|
||||
//直接响应文本
|
||||
//SYSINFO_UPDATED upload successful
|
||||
//ID_NOT_FOUND will be uploaded on the next heartbeat
|
||||
//respond with text directly
|
||||
c.String(http.StatusOK, "SYSINFO_UPDATED")
|
||||
}
|
||||
|
||||
// SysInfoVer
|
||||
// @Tags System
|
||||
// @Summary 获取系统版本信息
|
||||
// @Description 获取系统版本信息
|
||||
// @Summary get system version info
|
||||
// @Description get system version info
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} string ""
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /sysinfo_ver [post]
|
||||
func (p *Peer) SysInfoVer(c *gin.Context) {
|
||||
//读取resources/version文件
|
||||
// read the resources/version file
|
||||
v := service.AllService.AppService.GetAppVersion()
|
||||
// 加上启动时间,方便client上传信息
|
||||
// add the start time so the client can conveniently upload info
|
||||
v = fmt.Sprintf("%s\n%s", v, service.AllService.AppService.GetStartTime())
|
||||
c.String(http.StatusOK, v)
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
type User struct {
|
||||
}
|
||||
|
||||
// currentUser 当前用户
|
||||
// @Tags 用户
|
||||
// @Summary 用户信息
|
||||
// @Description 用户信息
|
||||
// currentUser current user
|
||||
// @Tags user
|
||||
// @Summary user info
|
||||
// @Description user info
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} apiResp.UserPayload
|
||||
@@ -26,10 +26,10 @@ type User struct {
|
||||
// c.JSON(http.StatusOK, up)
|
||||
//}
|
||||
|
||||
// Info 用户信息
|
||||
// @Tags 用户
|
||||
// @Summary 用户信息
|
||||
// @Description 用户信息
|
||||
// Info user info
|
||||
// @Tags user
|
||||
// @Summary user info
|
||||
// @Description user info
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} apiResp.UserPayload
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
type WebClient struct {
|
||||
}
|
||||
|
||||
// ServerConfig 服务配置
|
||||
// ServerConfig service config
|
||||
// @Tags WEBCLIENT
|
||||
// @Summary 服务配置
|
||||
// @Description 服务配置,给webclient提供api-server
|
||||
// @Summary service config
|
||||
// @Description service config, provides an api-server for the webclient
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response
|
||||
@@ -42,10 +42,10 @@ func (i *WebClient) ServerConfig(c *gin.Context) {
|
||||
)
|
||||
}
|
||||
|
||||
// SharedPeer 分享的peer
|
||||
// SharedPeer shared peer
|
||||
// @Tags WEBCLIENT
|
||||
// @Summary 分享的peer
|
||||
// @Description 分享的peer
|
||||
// @Summary shared peer
|
||||
// @Description shared peer
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response
|
||||
@@ -65,7 +65,7 @@ func (i *WebClient) SharedPeer(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if sr.Expire != 0 {
|
||||
//判断是否过期,created_at + expire > now
|
||||
//check whether expired,created_at + expire > now
|
||||
ca := time.Time(sr.CreatedAt)
|
||||
if ca.Add(time.Second * time.Duration(sr.Expire)).Before(time.Now()) {
|
||||
response.Fail(c, 101, "share expired")
|
||||
@@ -89,10 +89,10 @@ func (i *WebClient) SharedPeer(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// ServerConfigV2 服务配置
|
||||
// ServerConfigV2 service config
|
||||
// @Tags WEBCLIENT_V2
|
||||
// @Summary 服务配置
|
||||
// @Description 服务配置,给webclient提供api-server
|
||||
// @Summary service config
|
||||
// @Description service config, provides an api-server for the webclient
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response
|
||||
|
||||
Reference in New Issue
Block a user