fix: 调整网元日志文件列表返回信息
This commit is contained in:
@@ -6,11 +6,13 @@ import (
|
||||
|
||||
"ems.agt/src/framework/cmd"
|
||||
"ems.agt/src/framework/config"
|
||||
"ems.agt/src/framework/logger"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
)
|
||||
|
||||
// FileListRow 文件列表行数据
|
||||
type FileListRow struct {
|
||||
FileType string `json:"fileType"` // 文件类型
|
||||
FileMode string `json:"fileMode"` // 文件的权限
|
||||
LinkCount int64 `json:"linkCount"` // 硬链接数目
|
||||
Owner string `json:"owner"` // 所属用户
|
||||
@@ -26,7 +28,7 @@ type FileListRow struct {
|
||||
//
|
||||
// return 目录大小,行记录,异常
|
||||
func FileList(path, neIp, search string) (string, []FileListRow, error) {
|
||||
total := ""
|
||||
totalSize := ""
|
||||
var rows []FileListRow
|
||||
rowStr := ""
|
||||
|
||||
@@ -44,13 +46,15 @@ func FileList(path, neIp, search string) (string, []FileListRow, error) {
|
||||
sshHost := fmt.Sprintf("%s@%s", usernameNe, neIp)
|
||||
resultStr, err := cmd.ExecWithCheck("ssh", sshHost, pathStr, cmdStr)
|
||||
if err != nil {
|
||||
return total, rows, err
|
||||
logger.Errorf("Ne FileList Path: %s, Search: %s, Error:%s", path, search, err.Error())
|
||||
return totalSize, rows, err
|
||||
}
|
||||
rowStr = resultStr
|
||||
} else {
|
||||
resultStr, err := cmd.Execf(pathStr, cmdStr)
|
||||
if err != nil {
|
||||
return total, rows, err
|
||||
logger.Errorf("Ne FileList Path: %s, Search: %s, Error:%s", path, search, err.Error())
|
||||
return totalSize, rows, err
|
||||
}
|
||||
rowStr = resultStr
|
||||
}
|
||||
@@ -64,13 +68,24 @@ func FileList(path, neIp, search string) (string, []FileListRow, error) {
|
||||
// 使用空格对字符串进行切割
|
||||
fields := strings.Fields(rowStr)
|
||||
|
||||
if i == 0 {
|
||||
total = fields[1]
|
||||
if i == 0 && searchStr == "" {
|
||||
totalSize = fields[1]
|
||||
continue
|
||||
}
|
||||
|
||||
// 文件类型
|
||||
fileMode := fields[0]
|
||||
fileType := "file"
|
||||
if fileMode[0] == 'd' {
|
||||
fileType = "dir"
|
||||
} else if fileMode[0] == 'l' {
|
||||
fileType = "symlink"
|
||||
}
|
||||
|
||||
// 提取各个字段的值
|
||||
rows = append(rows, FileListRow{
|
||||
FileMode: fields[0],
|
||||
FileMode: fileMode,
|
||||
FileType: fileType,
|
||||
LinkCount: parse.Number(fields[1]),
|
||||
Owner: fields[2],
|
||||
Group: fields[3],
|
||||
@@ -79,5 +94,5 @@ func FileList(path, neIp, search string) (string, []FileListRow, error) {
|
||||
FileName: fields[6],
|
||||
})
|
||||
}
|
||||
return total, rows, nil
|
||||
return totalSize, rows, nil
|
||||
}
|
||||
|
||||
@@ -125,9 +125,14 @@ func (s *NeActionController) Files(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
total, rows, err := ssh.FileList(querys.Path, neInfo.IP, querys.Search)
|
||||
totalSize, rows, err := ssh.FileList(querys.Path, neInfo.IP, querys.Search)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"path": querys.Path,
|
||||
"totalSize": totalSize,
|
||||
"total": len(rows),
|
||||
"rows": []ssh.FileListRow{},
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -145,8 +150,9 @@ func (s *NeActionController) Files(c *gin.Context) {
|
||||
}
|
||||
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"path": querys.Path,
|
||||
"total": total,
|
||||
"rows": splitRows,
|
||||
"path": querys.Path,
|
||||
"totalSize": totalSize,
|
||||
"total": lenNum,
|
||||
"rows": splitRows,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user