mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 20:58:14 -05:00
🚸 improve: 优化修改服务器导致的主机信息丢失
This commit is contained in:
parent
a1e38051fc
commit
397a233074
@ -93,6 +93,7 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
|||||||
admin := c.MustGet(model.CtxKeyAuthorizedUser).(*model.User)
|
admin := c.MustGet(model.CtxKeyAuthorizedUser).(*model.User)
|
||||||
var sf serverForm
|
var sf serverForm
|
||||||
var s model.Server
|
var s model.Server
|
||||||
|
var isEdit bool
|
||||||
err := c.ShouldBindJSON(&sf)
|
err := c.ShouldBindJSON(&sf)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dao.ServerLock.Lock()
|
dao.ServerLock.Lock()
|
||||||
@ -106,6 +107,7 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
|||||||
s.Secret = s.Secret[:10]
|
s.Secret = s.Secret[:10]
|
||||||
err = dao.DB.Create(&s).Error
|
err = dao.DB.Create(&s).Error
|
||||||
} else {
|
} else {
|
||||||
|
isEdit = true
|
||||||
err = dao.DB.Save(&s).Error
|
err = dao.DB.Save(&s).Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,8 +118,13 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if isEdit {
|
||||||
|
s.Host = dao.ServerList[s.ID].Host
|
||||||
|
s.State = dao.ServerList[s.ID].State
|
||||||
|
} else {
|
||||||
s.Host = &model.Host{}
|
s.Host = &model.Host{}
|
||||||
s.State = &model.State{}
|
s.State = &model.State{}
|
||||||
|
}
|
||||||
dao.ServerList[s.ID] = &s
|
dao.ServerList[s.ID] = &s
|
||||||
dao.ReSortServer()
|
dao.ReSortServer()
|
||||||
c.JSON(http.StatusOK, model.Response{
|
c.JSON(http.StatusOK, model.Response{
|
||||||
|
Loading…
Reference in New Issue
Block a user