Skip to content

Commit

Permalink
add function
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Oct 10, 2023
1 parent 3404bc4 commit a9c2ff3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions route/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func InitV1Router() *gin.Engine {
v1DisksGroup.GET("/usb", v1.GetDisksUSBList)
v1DisksGroup.DELETE("/usb", v1.DeleteDiskUSB)
v1DisksGroup.DELETE("", v1.DeleteDisksUmount)
v1DisksGroup.GET("/size", v1.GetDiskSize)
}

v1StorageGroup := v1Group.Group("/storage")
Expand Down
19 changes: 19 additions & 0 deletions route/v1/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
model1 "github.com/IceWhaleTech/CasaOS-LocalStorage/model"
"github.com/IceWhaleTech/CasaOS-LocalStorage/service"
"github.com/gin-gonic/gin"
"github.com/shirou/gopsutil/v3/disk"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -231,3 +232,21 @@ func DeleteDisksUmount(c *gin.Context) {

c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: path})
}
func GetDiskSize(c *gin.Context) {
path := c.Query("path")
if len(path) == 0 {
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
p, err := disk.Usage(path)
if err != nil {
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: err.Error()})
return
}
data := map[string]interface{}{
"path": path,
"free": p.Free,
"used": p.Used,
}
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
}

0 comments on commit a9c2ff3

Please sign in to comment.