From e7a26dc60c585dce254634b89bf437b30b730bb0 Mon Sep 17 00:00:00 2001 From: LinkLeong Date: Tue, 20 Dec 2022 06:03:05 +0000 Subject: [PATCH] done --- route/periodical.go | 4 ++-- route/route.go | 1 + route/v1/file.go | 11 +++++++++++ route/v1/system.go | 5 ++--- service/system.go | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/route/periodical.go b/route/periodical.go index 4ebde98..588660b 100644 --- a/route/periodical.go +++ b/route/periodical.go @@ -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 diff --git a/route/route.go b/route/route.go index 2084e80..0fd234b 100644 --- a/route/route.go +++ b/route/route.go @@ -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() diff --git a/route/v1/file.go b/route/v1/file.go index 05079d6..0fcdf96 100644 --- a/route/v1/file.go +++ b/route/v1/file.go @@ -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}) +} diff --git a/route/v1/system.go b/route/v1/system.go index e8bfd68..e2476c8 100644 --- a/route/v1/system.go +++ b/route/v1/system.go @@ -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."}) } diff --git a/service/system.go b/service/system.go index cc83299..c7256cd 100644 --- a/service/system.go +++ b/service/system.go @@ -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()