This commit is contained in:
LinkLeong 2022-12-20 06:03:05 +00:00
parent 287445fdb0
commit e7a26dc60c
5 changed files with 17 additions and 5 deletions

View File

@ -62,9 +62,9 @@ func SendAllHardwareStatusBySocket() {
body["sys_mem"] = memInfo
body["sys_cpu"] = cpu
body["sys_cpu"] = cpuData
body["sys_net"] = netList
body["sys_net"] = newNet
systemTempMap := service.MyService.Notify().GetSystemTempMap()
for k, v := range systemTempMap {
body[k] = v

View File

@ -119,6 +119,7 @@ func InitRouter() *gin.Engine {
v1FolderGroup.PUT("/name", v1.RenamePath)
v1FolderGroup.GET("", v1.DirPath) ///file/dirpath
v1FolderGroup.POST("", v1.MkdirAll) ///file/mkdir
v1FolderGroup.GET("/size", v1.GetSize)
}
v1BatchGroup := v1Group.Group("/batch")
v1BatchGroup.Use()

View File

@ -649,3 +649,14 @@ func DeleteOperateFileOrDir(c *gin.Context) {
go service.MyService.Notify().SendFileOperateNotify(true)
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
}
func GetSize(c *gin.Context) {
json := make(map[string]string)
c.ShouldBind(&json)
path := json["path"]
size, err := file.GetFileOrDirSize(path)
if err != nil {
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
return
}
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: size})
}

View File

@ -336,11 +336,10 @@ func GetSystemProxy(c *gin.Context) {
func PutSystemState(c *gin.Context) {
state := c.Param("state")
if state == "off" {
if strings.ToLower(state) == "off" {
service.MyService.System().SystemShutdown()
} else if state == "restart" {
} else if strings.ToLower(state) == "restart" {
service.MyService.System().SystemReboot()
}
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: "The operation will be completed shortly."})
}

View File

@ -376,6 +376,7 @@ func (s *systemService) GetCPUPower() map[string]string {
}
func (s *systemService) SystemReboot() error {
//cmd := exec.Command("/bin/bash", "-c", "reboot")
arg := []string{"6"}
cmd := exec.Command("init", arg...)
_, err := cmd.CombinedOutput()