mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 20:50:06 +00:00
feat: Token生成|存储|验证
This commit is contained in:
@@ -5,6 +5,11 @@ import (
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
ApiTokenList = make(map[string]*model.ApiToken)
|
||||
UserIDToApiTokenList = make(map[uint64][]string)
|
||||
)
|
||||
|
||||
type ServerAPI struct {
|
||||
Token string // 传入Token 后期可能会需要用于scope判定
|
||||
IDList []uint64
|
||||
@@ -45,6 +50,21 @@ type ServerInfoResponse struct {
|
||||
Result []*CommonServerInfo `json:"result"`
|
||||
}
|
||||
|
||||
func InitAPI() {
|
||||
ApiTokenList = make(map[string]*model.ApiToken)
|
||||
UserIDToApiTokenList = make(map[uint64][]string)
|
||||
}
|
||||
|
||||
func LoadAPI() {
|
||||
InitAPI()
|
||||
var tokenList []*model.ApiToken
|
||||
DB.Find(&tokenList)
|
||||
for _, token := range tokenList {
|
||||
ApiTokenList[token.Token] = token
|
||||
UserIDToApiTokenList[token.UserID] = append(UserIDToApiTokenList[token.UserID], token.Token)
|
||||
}
|
||||
}
|
||||
|
||||
// GetStatusByIDList 获取传入IDList的服务器状态信息
|
||||
func (s *ServerAPI) GetStatusByIDList() *ServerStatusResponse {
|
||||
res := &ServerStatusResponse{}
|
||||
|
||||
@@ -38,6 +38,7 @@ func LoadSingleton() {
|
||||
LoadNotifications() // 加载通知服务
|
||||
LoadServers() // 加载服务器列表
|
||||
LoadCronTasks() // 加载定时任务
|
||||
LoadAPI()
|
||||
}
|
||||
|
||||
// InitConfigFromPath 从给出的文件路径中加载配置
|
||||
|
||||
Reference in New Issue
Block a user