1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-08 09:30:06 +08:00
1Panel/agent/app/api/v2/dashboard.go

148 lines
3.8 KiB
Go
Raw Normal View History

package v2
2024-07-23 14:48:37 +08:00
import (
"errors"
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
"github.com/1Panel-dev/1Panel/agent/app/dto"
2024-07-23 14:48:37 +08:00
"github.com/gin-gonic/gin"
)
// @Tags Dashboard
// @Summary Load os info
// @Accept json
// @Success 200 {object} dto.OsInfo
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-07-23 14:48:37 +08:00
// @Router /dashboard/base/os [get]
func (b *BaseApi) LoadDashboardOsInfo(c *gin.Context) {
data, err := dashboardService.LoadOsInfo()
if err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-07-23 14:48:37 +08:00
return
}
helper.SuccessWithData(c, data)
}
// @Tags Dashboard
// @Summary Load app launcher
// @Accept json
2025-01-21 18:32:14 +08:00
// @Success 200 {Array} dto.AppLauncher
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
// @Router /dashboard/app/launcher [get]
func (b *BaseApi) LoadAppLauncher(c *gin.Context) {
data, err := dashboardService.LoadAppLauncher()
if err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, data)
}
// @Tags Dashboard
// @Summary Load app launcher options
// @Accept json
// @Param request body dto.SearchByFilter true "request"
// @Success 200 {Array} dto.LauncherOption
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
// @Router /dashboard/app/launcher/option [post]
func (b *BaseApi) LoadAppLauncherOption(c *gin.Context) {
var req dto.SearchByFilter
if err := helper.CheckBind(&req, c); err != nil {
return
}
data, err := dashboardService.ListLauncherOption(req.Filter)
if err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, data)
}
2024-07-23 14:48:37 +08:00
// @Tags Dashboard
// @Summary Load dashboard base info
// @Accept json
// @Param ioOption path string true "request"
// @Param netOption path string true "request"
// @Success 200 {object} dto.DashboardBase
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-07-23 14:48:37 +08:00
// @Router /dashboard/base/:ioOption/:netOption [get]
func (b *BaseApi) LoadDashboardBaseInfo(c *gin.Context) {
ioOption, ok := c.Params.Get("ioOption")
if !ok {
2024-10-29 18:42:12 +08:00
helper.BadRequest(c, errors.New("error ioOption in path"))
2024-07-23 14:48:37 +08:00
return
}
netOption, ok := c.Params.Get("netOption")
if !ok {
2024-10-29 18:42:12 +08:00
helper.BadRequest(c, errors.New("error ioOption in path"))
2024-07-23 14:48:37 +08:00
return
}
data, err := dashboardService.LoadBaseInfo(ioOption, netOption)
if err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-07-23 14:48:37 +08:00
return
}
helper.SuccessWithData(c, data)
}
2024-08-15 17:06:50 +08:00
// @Tags Dashboard
// @Summary Load dashboard current info for node
// @Success 200 {object} dto.NodeCurrent
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-08-15 17:06:50 +08:00
// @Router /dashboard/current/node [get]
func (b *BaseApi) LoadCurrentInfoForNode(c *gin.Context) {
data := dashboardService.LoadCurrentInfoForNode()
helper.SuccessWithData(c, data)
}
2024-07-23 14:48:37 +08:00
// @Tags Dashboard
// @Summary Load dashboard current info
// @Accept json
// @Param ioOption path string true "request"
// @Param netOption path string true "request"
// @Success 200 {object} dto.DashboardCurrent
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-07-23 14:48:37 +08:00
// @Router /dashboard/current/:ioOption/:netOption [get]
func (b *BaseApi) LoadDashboardCurrentInfo(c *gin.Context) {
ioOption, ok := c.Params.Get("ioOption")
if !ok {
2024-10-29 18:42:12 +08:00
helper.BadRequest(c, errors.New("error ioOption in path"))
2024-07-23 14:48:37 +08:00
return
}
netOption, ok := c.Params.Get("netOption")
if !ok {
2024-10-29 18:42:12 +08:00
helper.BadRequest(c, errors.New("error netOption in path"))
2024-07-23 14:48:37 +08:00
return
}
data := dashboardService.LoadCurrentInfo(ioOption, netOption)
helper.SuccessWithData(c, data)
}
// @Tags Dashboard
// @Summary System restart
// @Accept json
// @Param operation path string true "request"
// @Success 200
// @Security ApiKeyAuth
2025-01-21 18:32:14 +08:00
// @Security Timestamp
2024-07-23 14:48:37 +08:00
// @Router /dashboard/system/restart/:operation [post]
func (b *BaseApi) SystemRestart(c *gin.Context) {
operation, ok := c.Params.Get("operation")
if !ok {
2024-10-29 18:42:12 +08:00
helper.BadRequest(c, errors.New("error operation in path"))
2024-07-23 14:48:37 +08:00
return
}
if err := dashboardService.Restart(operation); err != nil {
2024-10-29 18:42:12 +08:00
helper.InternalServer(c, err)
2024-07-23 14:48:37 +08:00
return
}
2025-01-21 18:32:14 +08:00
helper.SuccessWithOutData(c)
2024-07-23 14:48:37 +08:00
}