update: 代码格式|前端入口移动至用户名下拉菜单

This commit is contained in:
Akkia 2022-05-18 23:37:39 +08:00
parent 1a3343d861
commit e341960223
No known key found for this signature in database
GPG Key ID: DABE9A4AB2DD7EF3
6 changed files with 28 additions and 57 deletions

View File

@ -32,14 +32,10 @@ func (v *apiV1) serve() {
// header: Authorization: Token
// query: tag (服务器分组)
func (v *apiV1) serverList(c *gin.Context) {
token, _ := c.Cookie("Authorization")
tag := c.Query("tag")
serverAPI := &singleton.ServerAPI{
Token: token,
Tag: tag,
}
serverAPI := &singleton.ServerAPI{}
if tag != "" {
c.JSON(200, serverAPI.GetListByTag())
c.JSON(200, serverAPI.GetListByTag(tag))
return
}
c.JSON(200, serverAPI.GetAllList())
@ -50,7 +46,6 @@ func (v *apiV1) serverList(c *gin.Context) {
// query: id (服务器ID逗号分隔优先级高于tag查询)
// query: tag (服务器分组)
func (v *apiV1) serverDetails(c *gin.Context) {
token, _ := c.Cookie("Authorization")
var idList []uint64
idListStr := strings.Split(c.Query("id"), ",")
if c.Query("id") != "" {
@ -61,17 +56,13 @@ func (v *apiV1) serverDetails(c *gin.Context) {
}
}
tag := c.Query("tag")
serverAPI := &singleton.ServerAPI{
Token: token,
IDList: idList,
Tag: tag,
}
serverAPI := &singleton.ServerAPI{}
if tag != "" {
c.JSON(200, serverAPI.GetStatusByTag())
c.JSON(200, serverAPI.GetStatusByTag(tag))
return
}
if len(idList) != 0 {
c.JSON(200, serverAPI.GetStatusByIDList())
c.JSON(200, serverAPI.GetStatusByIDList(idList))
return
}
c.JSON(200, serverAPI.GetAllStatus())

View File

@ -176,8 +176,21 @@ func (ma *memberAPI) delete(c *gin.Context) {
if err == nil {
// 删除服务器
singleton.ServerLock.Lock()
tag := singleton.ServerList[id].Tag
delete(singleton.SecretToID, singleton.ServerList[id].Secret)
delete(singleton.ServerList, id)
index := 0
for index < len(singleton.ServerTagToIDList[tag]) {
if singleton.ServerTagToIDList[tag][index] == id {
break
}
index++
}
// 删除旧 Tag-ID 绑定关系
singleton.ServerTagToIDList[tag] = append(singleton.ServerTagToIDList[tag][:index], singleton.ServerTagToIDList[tag][index+1:]...)
if len(singleton.ServerTagToIDList[tag]) == 0 {
delete(singleton.ServerTagToIDList, tag)
}
singleton.ServerLock.Unlock()
singleton.ReSortServer()
// 删除循环流量状态中的此服务器相关的记录

View File

@ -469,21 +469,6 @@ other = "Services"
[ScheduledTasks]
other = "Scheduled Tasks"
[ApiManagement]
other="API"
[IssueNewApiToken]
other="Create Token"
[Token]
other="Token"
[DeleteToken]
other="Delete Token"
[ConfirmToDeleteThisToken]
other="Confirm Delete?"
[YouAreNotAuthorized]
other = "You are not authorized"

View File

@ -469,21 +469,6 @@ other = "Monitorización del servicio"
[ScheduledTasks]
other = "Tareas programadas"
[ApiManagement]
other="API"
[IssueNewApiToken]
other="Create Token"
[Token]
other="Token"
[DeleteToken]
other="Delete Token"
[ConfirmToDeleteThisToken]
other="Confirm Delete?"
[YouAreNotAuthorized]
other = "Esta página requiere un acceso"

View File

@ -9,7 +9,6 @@
<a class='item{{if eq .MatchedPath "/monitor"}} active{{end}}' href="/monitor"><i class="rss icon"></i>{{tr "Services"}}</a>
<a class='item{{if eq .MatchedPath "/cron"}} active{{end}}' href="/cron"><i class="clock icon"></i>{{tr "Task"}}</a>
<a class='item{{if eq .MatchedPath "/notification"}} active{{end}}' href="/notification"><i class="bell icon"></i>{{tr "Notification"}}</a>
<a class='item{{if eq .MatchedPath "/api"}} active{{end}}' href="/api"><i class="key icon"></i>API</a>
<a class='item{{if eq .MatchedPath "/setting"}} active{{end}}' href="/setting">
<i class="settings icon"></i>{{tr "Settings"}}
</a>
@ -30,6 +29,9 @@
<a class="item" href="/">
<i class="chart area icon"></i>{{tr "BackToHomepage"}}
</a>
<a class="item" href="/api">
<i class="chart key icon"></i>API Token
</a>
{{else}}
<a class="item" href="/server">
<i class="terminal icon"></i>{{tr "AdminPanel"}}

View File

@ -12,11 +12,7 @@ var (
ApiLock sync.RWMutex
)
type ServerAPI struct {
Token string // 传入Token 后期可能会需要用于scope判定
IDList []uint64
Tag string
}
type ServerAPI struct{}
// CommonResponse 常规返回结构 包含状态码 和 状态信息
type CommonResponse struct {
@ -68,14 +64,14 @@ func LoadAPI() {
}
// GetStatusByIDList 获取传入IDList的服务器状态信息
func (s *ServerAPI) GetStatusByIDList() *ServerStatusResponse {
func (s *ServerAPI) GetStatusByIDList(idList []uint64) *ServerStatusResponse {
res := &ServerStatusResponse{}
res.Result = make([]*StatusResponse, 0)
ServerLock.RLock()
defer ServerLock.RUnlock()
for _, v := range s.IDList {
for _, v := range idList {
server := ServerList[v]
if server == nil {
continue
@ -103,9 +99,8 @@ func (s *ServerAPI) GetStatusByIDList() *ServerStatusResponse {
}
// GetStatusByTag 获取传入分组的所有服务器状态信息
func (s *ServerAPI) GetStatusByTag() *ServerStatusResponse {
s.IDList = ServerTagToIDList[s.Tag]
return s.GetStatusByIDList()
func (s *ServerAPI) GetStatusByTag(tag string) *ServerStatusResponse {
return s.GetStatusByIDList(ServerTagToIDList[tag])
}
// GetAllStatus 获取所有服务器状态信息
@ -143,13 +138,13 @@ func (s *ServerAPI) GetAllStatus() *ServerStatusResponse {
}
// GetListByTag 获取传入分组的所有服务器信息
func (s *ServerAPI) GetListByTag() *ServerInfoResponse {
func (s *ServerAPI) GetListByTag(tag string) *ServerInfoResponse {
res := &ServerInfoResponse{}
res.Result = make([]*CommonServerInfo, 0)
ServerLock.RLock()
defer ServerLock.RUnlock()
for _, v := range ServerTagToIDList[s.Tag] {
for _, v := range ServerTagToIDList[tag] {
host := ServerList[v].Host
if host == nil {
continue