mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-20 06:40:50 +00:00
修改 客户端基本属性逻辑。 修改 最新上报key改为uuid 新增 客户端命名 新增 历史记录数据库压缩。 新增 在线节点信息。 新增 公开API /api/nodes 显示客户端基础属性
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/akizon77/komari/api"
|
|
"github.com/akizon77/komari/api/admin"
|
|
"github.com/akizon77/komari/api/client"
|
|
"github.com/akizon77/komari/cmd/flags"
|
|
"github.com/akizon77/komari/ws"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var ServerCmd = &cobra.Command{
|
|
Use: "server",
|
|
Short: "Start the server",
|
|
Long: `Start the server`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
r := gin.Default()
|
|
|
|
r.NoRoute(gin.WrapH(http.FileServer(gin.Dir("public", false))))
|
|
|
|
r.POST("/api/login", api.Login)
|
|
r.GET("/api/me", api.GetMe)
|
|
r.GET("/api/clients", ws.GetClients)
|
|
r.GET("/api/nodes", api.GetNodesInformation)
|
|
|
|
tokenAuthrized := r.Group("/api/clients", api.TokenAuthMiddleware())
|
|
{
|
|
tokenAuthrized.GET("/report", client.WebSocketReport) // websocket
|
|
tokenAuthrized.POST("/uploadBasicInfo", client.UploadBasicInfo)
|
|
tokenAuthrized.POST("/report", client.UploadReport)
|
|
}
|
|
|
|
adminAuthrized := r.Group("/api/admin", api.AdminAuthMiddleware())
|
|
{
|
|
// clients
|
|
adminAuthrized.POST("/addClient", admin.AddClient)
|
|
adminAuthrized.POST("/editClient", admin.EditClient)
|
|
adminAuthrized.GET("/listClients", admin.ListClients)
|
|
adminAuthrized.GET("/getClient", admin.GetClient)
|
|
adminAuthrized.POST("/clearHistory", admin.ClearHistory)
|
|
adminAuthrized.POST("/removeClient", admin.RemoveClient)
|
|
|
|
// settings
|
|
adminAuthrized.GET("/settings", admin.GetSettings)
|
|
adminAuthrized.POST("/settings", admin.EditSettings)
|
|
|
|
}
|
|
|
|
r.Run(flags.Listen)
|
|
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(ServerCmd)
|
|
}
|