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

View File

@ -176,8 +176,21 @@ func (ma *memberAPI) delete(c *gin.Context) {
if err == nil { if err == nil {
// 删除服务器 // 删除服务器
singleton.ServerLock.Lock() singleton.ServerLock.Lock()
tag := singleton.ServerList[id].Tag
delete(singleton.SecretToID, singleton.ServerList[id].Secret) delete(singleton.SecretToID, singleton.ServerList[id].Secret)
delete(singleton.ServerList, id) 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.ServerLock.Unlock()
singleton.ReSortServer() singleton.ReSortServer()
// 删除循环流量状态中的此服务器相关的记录 // 删除循环流量状态中的此服务器相关的记录

View File

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

View File

@ -469,21 +469,6 @@ other = "Monitorización del servicio"
[ScheduledTasks] [ScheduledTasks]
other = "Tareas programadas" other = "Tareas programadas"
[ApiManagement]
other="API"
[IssueNewApiToken]
other="Create Token"
[Token]
other="Token"
[DeleteToken]
other="Delete Token"
[ConfirmToDeleteThisToken]
other="Confirm Delete?"
[YouAreNotAuthorized] [YouAreNotAuthorized]
other = "Esta página requiere un acceso" 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 "/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 "/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 "/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"> <a class='item{{if eq .MatchedPath "/setting"}} active{{end}}' href="/setting">
<i class="settings icon"></i>{{tr "Settings"}} <i class="settings icon"></i>{{tr "Settings"}}
</a> </a>
@ -30,6 +29,9 @@
<a class="item" href="/"> <a class="item" href="/">
<i class="chart area icon"></i>{{tr "BackToHomepage"}} <i class="chart area icon"></i>{{tr "BackToHomepage"}}
</a> </a>
<a class="item" href="/api">
<i class="chart key icon"></i>API Token
</a>
{{else}} {{else}}
<a class="item" href="/server"> <a class="item" href="/server">
<i class="terminal icon"></i>{{tr "AdminPanel"}} <i class="terminal icon"></i>{{tr "AdminPanel"}}

View File

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