1Panel/backend/app/api/v1/dashboard.go

93 lines
2.8 KiB
Go
Raw Normal View History

2022-11-24 15:56:48 +00:00
package v1
import (
"errors"
2024-09-11 14:12:16 +00:00
"github.com/1Panel-dev/1Panel/backend/app/dto"
2022-11-24 15:56:48 +00:00
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
// @Tags Dashboard
// @Summary Load os info
// @Description 获取服务器基础数据
// @Accept json
// @Success 200 {object} dto.OsInfo
// @Security ApiKeyAuth
// @Router /dashboard/base/os [get]
func (b *BaseApi) LoadDashboardOsInfo(c *gin.Context) {
data, err := dashboardService.LoadOsInfo()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, data)
}
2023-01-04 14:31:51 +00:00
// @Tags Dashboard
// @Summary Load dashboard base info
// @Description 获取首页基础数据
// @Accept json
// @Param ioOption path string true "request"
// @Param netOption path string true "request"
// @Success 200 {object} dto.DashboardBase
// @Security ApiKeyAuth
// @Router /dashboard/base/:ioOption/:netOption [get]
2022-11-24 15:56:48 +00:00
func (b *BaseApi) LoadDashboardBaseInfo(c *gin.Context) {
ioOption, ok := c.Params.Get("ioOption")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error ioOption in path"))
return
}
netOption, ok := c.Params.Get("netOption")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error netOption in path"))
return
}
data, err := dashboardService.LoadBaseInfo(ioOption, netOption)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, data)
}
2023-01-04 14:31:51 +00:00
// @Tags Dashboard
// @Summary Load dashboard current info
// @Description 获取首页实时数据
2024-09-11 14:12:16 +00:00
// @Accept json、
// @Param request body dto.DashboardReq true "request"
2023-01-04 14:31:51 +00:00
// @Success 200 {object} dto.DashboardCurrent
// @Security ApiKeyAuth
2024-09-11 14:12:16 +00:00
// @Router /dashboard/current [post]
2022-11-24 15:56:48 +00:00
func (b *BaseApi) LoadDashboardCurrentInfo(c *gin.Context) {
2024-09-11 14:12:16 +00:00
var req dto.DashboardReq
if err := helper.CheckBindAndValidate(&req, c); err != nil {
2022-11-24 15:56:48 +00:00
return
}
2024-09-11 14:12:16 +00:00
data := dashboardService.LoadCurrentInfo(req)
2022-11-24 15:56:48 +00:00
helper.SuccessWithData(c, data)
}
// @Tags Dashboard
// @Summary System restart
// @Description 重启服务器/面板
// @Accept json
// @Param operation path string true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /dashboard/system/restart/:operation [post]
func (b *BaseApi) SystemRestart(c *gin.Context) {
operation, ok := c.Params.Get("operation")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error operation in path"))
return
}
if err := dashboardService.Restart(operation); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}