This commit is contained in:
Tiger Wang 2022-07-10 19:04:50 -04:00
parent dfac179760
commit c78b632040
7 changed files with 34 additions and 8 deletions

View File

@ -51,17 +51,17 @@ type Drive struct {
type DriveUSB struct { type DriveUSB struct {
Name string `json:"name"` Name string `json:"name"`
Size uint64 `json:"size"` Size uint64 `json:"size"`
Used uint64 `json:"use"` Used uint64 `json:"use"` // @tiger - 改成 used_space
Model string `json:"model"` Model string `json:"model"`
Mount bool `json:"mount"` //是否完全挂载 Mount bool `json:"mount"` //是否完全挂载
Avail uint64 `json:"avail"` //可用空间 Avail uint64 `json:"avail"` //可用空间 // @tiger - 改成 available_space
} }
type Storage struct { type Storage struct {
Name string `json:"name"` Name string `json:"name"`
MountPoint string `json:"mountpoint"` MountPoint string `json:"mountpoint"`
Size string `json:"size"` Size string `json:"size"`
Avail string `json:"avail"` //可用空间 Avail string `json:"avail"` //可用空间 // @tiger - 改成 available_space
Type string `json:"type"` Type string `json:"type"`
CreatedAt int64 `json:"create_at"` CreatedAt int64 `json:"create_at"`
Path string `json:"path"` Path string `json:"path"`
@ -70,7 +70,7 @@ type Storage struct {
type Summary struct { type Summary struct {
Size uint64 `json:"size"` Size uint64 `json:"size"`
Avail uint64 `json:"avail"` //可用空间 Avail uint64 `json:"avail"` //可用空间 // @tiger - 改成 available_space
Health bool `json:"health"` Health bool `json:"health"`
Used uint64 `json:"used"` Used uint64 `json:"used"` // @tiger - 改成 used_space
} }

View File

@ -1,6 +1,7 @@
package model package model
type IOCountersStat struct { type IOCountersStat struct {
// @tiger - 应该统一用 snake_case不是 snakeCase
Name string `json:"name"` // interface name Name string `json:"name"` // interface name
BytesSent uint64 `json:"bytesSent"` // number of bytes sent BytesSent uint64 `json:"bytesSent"` // number of bytes sent
BytesRecv uint64 `json:"bytesRecv"` // number of bytes received BytesRecv uint64 `json:"bytesRecv"` // number of bytes received

View File

@ -175,21 +175,44 @@ func InitRouter() *gin.Engine {
v1SysGroup := v1Group.Group("/sys") v1SysGroup := v1Group.Group("/sys")
v1SysGroup.Use() v1SysGroup.Use()
{ {
// @tiger - 这里改成 GET /v1/sys/update和下面的 POST /v1/sys/update 对齐
v1SysGroup.GET("/version/check", v1.GetSystemCheckVersion) v1SysGroup.GET("/version/check", v1.GetSystemCheckVersion)
// @tiger - 这里改成 /v1/sys/hardware_info
v1SysGroup.GET("/hardware/info", v1.GetSystemHardwareInfo) v1SysGroup.GET("/hardware/info", v1.GetSystemHardwareInfo)
v1SysGroup.POST("/update", v1.SystemUpdate) v1SysGroup.POST("/update", v1.SystemUpdate)
// @tiger - 应该直接提供一个 wss://... 的地址给客户端,而不是和 API 混在一起
v1SysGroup.GET("/wsssh", v1.WsSsh) v1SysGroup.GET("/wsssh", v1.WsSsh)
// @tiger - 这个永远返回空值 - 可以删了?
v1SysGroup.GET("/config", v1.GetSystemConfig) v1SysGroup.GET("/config", v1.GetSystemConfig)
//v1SysGroup.POST("/config", v1.PostSetSystemConfig) //v1SysGroup.POST("/config", v1.PostSetSystemConfig)
// @tiger - 这里改成 /v1/sys/error_log
v1SysGroup.GET("/error/logs", v1.GetCasaOSErrorLogs) v1SysGroup.GET("/error/logs", v1.GetCasaOSErrorLogs)
// @tiger - 这里改成 /v1/sys/widget_config
v1SysGroup.GET("/widget/config", v1.GetWidgetConfig) v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig) v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
// @tiger - port 是 server_info 的属性,应该有一个 /v1/sys/server_info 的 API
// 然后这个 port 信息是包含在 server_info 中的
v1SysGroup.GET("/port", v1.GetCasaOSPort) v1SysGroup.GET("/port", v1.GetCasaOSPort)
v1SysGroup.PUT("/port", v1.PutCasaOSPort) v1SysGroup.PUT("/port", v1.PutCasaOSPort)
// @tiger - 不应该有这个 API
v1SysGroup.POST("/stop", v1.PostKillCasaOS) v1SysGroup.POST("/stop", v1.PostKillCasaOS)
v1SysGroup.GET("/utilization", v1.GetSystemUtilization) v1SysGroup.GET("/utilization", v1.GetSystemUtilization)
// @tiger - 下面两个统一用 /v1/sys/usb_automount然后 status 封装到入参和出参里
v1SysGroup.PUT("/usb/:status", v1.PutSystemUSBAutoMount) v1SysGroup.PUT("/usb/:status", v1.PutSystemUSBAutoMount)
v1SysGroup.GET("/usb/status", v1.GetSystemUSBAutoMount) v1SysGroup.GET("/usb/status", v1.GetSystemUSBAutoMount)
// @tiger - 下面四个和 /utilization 重复了,应该去重。
v1SysGroup.GET("/cpu", v1.GetSystemCupInfo) v1SysGroup.GET("/cpu", v1.GetSystemCupInfo)
v1SysGroup.GET("/mem", v1.GetSystemMemInfo) v1SysGroup.GET("/mem", v1.GetSystemMemInfo)
v1SysGroup.GET("/disk", v1.GetSystemDiskInfo) v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)

View File

@ -67,7 +67,7 @@ func DockerTerminal(c *gin.Context) {
func WsSsh(c *gin.Context) { func WsSsh(c *gin.Context) {
j := make(map[string]string) j := make(map[string]string)
c.BindJSON(j) c.BindJSON(j)
userName := j["user_name"] userName := j["user_name"] // @tiger - 改成 username
password := j["password"] password := j["password"]
port := j["port"] port := j["port"]
wsConn, _ := upgrader.Upgrade(c.Writer, c.Request, nil) wsConn, _ := upgrader.Upgrade(c.Writer, c.Request, nil)

View File

@ -319,6 +319,8 @@ func RenamePath(c *gin.Context) {
return return
} }
success, err := service.MyService.System().RenameFile(op, np) success, err := service.MyService.System().RenameFile(op, np)
// @tiger - err 应该放到 Message 里
c.JSON(http.StatusOK, model.Result{Success: success, Message: common_err.GetMsg(success), Data: err}) c.JSON(http.StatusOK, model.Result{Success: success, Message: common_err.GetMsg(success), Data: err})
} }

View File

@ -434,7 +434,7 @@ func GetSystemUtilization(c *gin.Context) {
cpuData["percent"] = cpu cpuData["percent"] = cpu
cpuData["num"] = num cpuData["num"] = num
data["cpu"] = cpuData data["cpu"] = cpuData
data["mem"] = service.MyService.System().GetMemInfo() data["mem"] = service.MyService.System().GetMemInfo() // @tiger - 改成 memory
//拼装网络信息 //拼装网络信息
netList := service.MyService.System().GetNetInfo() netList := service.MyService.System().GetNetInfo()

View File

@ -180,7 +180,7 @@ func (c *systemService) GetMemInfo() map[string]interface{} {
memData["available"] = memInfo.Available memData["available"] = memInfo.Available
memData["used"] = memInfo.Used memData["used"] = memInfo.Used
memData["free"] = memInfo.Free memData["free"] = memInfo.Free
memData["usedPercent"] = memInfo.UsedPercent memData["usedPercent"] = memInfo.UsedPercent // @tiger - 改成 used_percent - 如果统一用 snake_case 就不要用 camelCase
return memData return memData
} }