🐛 修复修改服务器导致 Agent 离线

This commit is contained in:
naiba
2021-07-25 23:50:08 +08:00
parent bcb95ba718
commit e24121bdf7
6 changed files with 28 additions and 12 deletions

View File

@@ -154,7 +154,7 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
s.ID = sf.ID
s.Tag = sf.Tag
s.Note = sf.Note
if sf.ID == 0 {
if s.ID == 0 {
s.Secret = utils.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, admin.ID))
s.Secret = s.Secret[:18]
err = dao.DB.Create(&s).Error
@@ -171,13 +171,17 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
return
}
if isEdit {
dao.ServerLock.RLock()
s.Host = dao.ServerList[s.ID].Host
s.State = dao.ServerList[s.ID].State
dao.SecretToID[s.Secret] = s.ID
delete(dao.SecretToID, dao.ServerList[s.ID].Secret)
dao.ServerLock.Lock()
s.CopyFromRunningServer(dao.ServerList[s.ID])
// 如果修改了 Secret
if s.Secret != dao.ServerList[s.ID].Secret {
// 删除旧 Secret-ID 绑定关系
dao.SecretToID[s.Secret] = s.ID
// 设置新的 Secret-ID 绑定关系
delete(dao.SecretToID, dao.ServerList[s.ID].Secret)
}
dao.ServerList[s.ID] = &s
dao.ServerLock.RUnlock()
dao.ServerLock.Unlock()
} else {
s.Host = &model.Host{}
s.State = &model.HostState{}

View File

@@ -8,7 +8,6 @@ import (
"strings"
"github.com/gin-gonic/gin"
"github.com/google/go-github/github"
GitHubAPI "github.com/google/go-github/github"
"golang.org/x/oauth2"
GitHubOauth2 "golang.org/x/oauth2/github"
@@ -87,7 +86,7 @@ func (oa *oauth2controller) callback(c *gin.Context) {
client = GitHubAPI.NewClient(oc)
}
}
var gu *github.User
var gu *GitHubAPI.User
if err == nil {
gu, _, err = client.Users.Get(ctx, "")
}