feat: 新增网元端文件列表获取和下载

This commit is contained in:
TsMask
2023-12-12 19:37:48 +08:00
parent 4405c5bed6
commit 97042b846d
4 changed files with 171 additions and 16 deletions

View File

@@ -66,3 +66,73 @@ func (s *NeActionController) PushFile(c *gin.Context) {
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
}
// 从网元端获取文件
//
// GET /pullFile
func (s *NeActionController) PullFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
Path string `form:"path" binding:"required"`
FileName string `form:"fileName" binding:"required"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
nePath := fmt.Sprintf("%s/%s", querys.Path, querys.FileName)
localPath := fmt.Sprintf("/tmp/omc/pullFile/%s", querys.FileName)
err := ssh.FileSCPNeToLocal(neInfo.IP, nePath, localPath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
c.FileAttachment(localPath, querys.FileName)
}
// 网元端文件列表
//
// GET /files
func (s *NeActionController) Files(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var querys struct {
NeType string `form:"neType" binding:"required"`
NeID string `form:"neId" binding:"required"`
Path string `form:"path" binding:"required"`
PageNum int64 `form:"pageNum" binding:"required"`
PageSize int64 `form:"pageSize" binding:"required"`
Search string `form:"search"`
}
if err := c.ShouldBindQuery(&querys); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(querys.NeType, querys.NeID)
if neInfo.NeId != querys.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
total, rows, err := ssh.FileList(querys.Path, neInfo.IP, querys.Search)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
c.JSON(200, result.OkData(map[string]any{
"path": querys.Path,
"total": total,
"rows": rows,
}))
}