merge: 合并代码20241018
This commit is contained in:
@@ -1,31 +1,19 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"be.ems/lib/core/ctx"
|
||||
"be.ems/lib/dborm"
|
||||
"be.ems/lib/file"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/services"
|
||||
"be.ems/restagent/config"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
)
|
||||
|
||||
var (
|
||||
// parameter config management
|
||||
UriFile = config.DefaultUriPrefix + "/fileManagement/{apiVersion}/{location}/file"
|
||||
|
||||
UriFile = config.DefaultUriPrefix + "/fileManagement/{apiVersion}/{location}/file"
|
||||
CustomUriFile = config.UriPrefix + "/fileManagement/{apiVersion}/{location}/file"
|
||||
|
||||
// 获取磁盘列表
|
||||
UriDiskList = config.DefaultUriPrefix + "/fileManagement/{apiVersion}/files/diskList"
|
||||
|
||||
// 获取文件列表
|
||||
UriListFiles = config.DefaultUriPrefix + "/fileManagement/{apiVersion}/files/listFiles"
|
||||
)
|
||||
|
||||
// func init() {
|
||||
@@ -151,46 +139,3 @@ func DeleteFile(w http.ResponseWriter, r *http.Request) {
|
||||
services.ResponseStatusOK204NoContent(w)
|
||||
return
|
||||
}
|
||||
|
||||
// 磁盘列表
|
||||
func DiskList(w http.ResponseWriter, r *http.Request) {
|
||||
disks := make([]map[string]string, 0)
|
||||
|
||||
partitions, err := disk.Partitions(false)
|
||||
if err != nil {
|
||||
services.ResponseWithJson(w, 200, disks)
|
||||
}
|
||||
|
||||
for _, partition := range partitions {
|
||||
usage, err := disk.Usage(partition.Mountpoint)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
disks = append(disks, map[string]string{
|
||||
"size": file.FormatFileSize(float64(usage.Total)),
|
||||
"used": file.FormatFileSize(float64(usage.Used)),
|
||||
"avail": file.FormatFileSize(float64(usage.Free)),
|
||||
"pcent": fmt.Sprintf("%.1f%%", usage.UsedPercent),
|
||||
"target": partition.Device,
|
||||
})
|
||||
}
|
||||
services.ResponseWithJson(w, 200, disks)
|
||||
}
|
||||
|
||||
// 获取文件列表 /files/search
|
||||
func ListFiles(w http.ResponseWriter, r *http.Request) {
|
||||
// json 請求參數獲取
|
||||
var bodyArgs FileOption
|
||||
err := ctx.ShouldBindJSON(r, &bodyArgs)
|
||||
if err != nil || dborm.DbClient.XEngine == nil {
|
||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
files, err := GetFileList(bodyArgs)
|
||||
if err != nil {
|
||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
services.ResponseWithJson(w, 200, files)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user