diff --git a/backend/model/file.go b/backend/model/file.go index 1af3b851..a2ad34eb 100644 --- a/backend/model/file.go +++ b/backend/model/file.go @@ -20,12 +20,13 @@ type GridFs struct { } type File struct { - Name string `json:"name"` - Path string `json:"path"` - IsDir bool `json:"is_dir"` - Size int64 `json:"size"` - Children []File `json:"children"` - Label string `json:"label"` + Name string `json:"name"` + Path string `json:"path"` + RelativePath string `json:"relative_path"` + IsDir bool `json:"is_dir"` + Size int64 `json:"size"` + Children []File `json:"children"` + Label string `json:"label"` } func (f *GridFs) Remove() { diff --git a/backend/routes/spider.go b/backend/routes/spider.go index 2534a7da..4adfb707 100644 --- a/backend/routes/spider.go +++ b/backend/routes/spider.go @@ -708,7 +708,7 @@ func RenameSpiderFile(c *gin.Context) { // 原文件路径 filePath := path.Join(spider.Src, reqBody.Path) - newFilePath := path.Join(spider.Src, reqBody.NewPath) + newFilePath := path.Join(path.Join(path.Dir(filePath), reqBody.NewPath)) // 如果新文件已存在,则报错 if utils.Exists(newFilePath) { diff --git a/backend/services/file.go b/backend/services/file.go index 0b810209..d126fcab 100644 --- a/backend/services/file.go +++ b/backend/services/file.go @@ -6,9 +6,14 @@ import ( "os" "path" "runtime/debug" + "strings" ) func GetFileNodeTree(dstPath string, level int) (f model.File, err error) { + return getFileNodeTree(dstPath, level, dstPath) +} + +func getFileNodeTree(dstPath string, level int, rootPath string) (f model.File, err error) { dstF, err := os.Open(dstPath) if err != nil { log.Errorf(err.Error()) @@ -24,9 +29,9 @@ func GetFileNodeTree(dstPath string, level int) (f model.File, err error) { } if !fileInfo.IsDir() { //如果dstF是文件 return model.File{ - Label: fileInfo.Name(), + Label: fileInfo.Name(), Name: fileInfo.Name(), - Path: dstPath, + Path: strings.Replace(dstPath, rootPath, "", -1), IsDir: false, Size: fileInfo.Size(), Children: nil, @@ -41,13 +46,13 @@ func GetFileNodeTree(dstPath string, level int) (f model.File, err error) { f = model.File{ Label: path.Base(dstPath), Name: path.Base(dstPath), - Path: dstPath, + Path: strings.Replace(dstPath, rootPath, "", -1), IsDir: true, Size: 0, Children: nil, } for _, subFileInfo := range dir { - subFileNode, err := GetFileNodeTree(path.Join(dstPath, subFileInfo.Name()), level+1) + subFileNode, err := getFileNodeTree(path.Join(dstPath, subFileInfo.Name()), level+1, rootPath) if err != nil { log.Errorf(err.Error()) debug.PrintStack()