diff --git a/backend/utils/files/fileinfo.go b/backend/utils/files/fileinfo.go
index 8e7f7c8f1..ecda89753 100644
--- a/backend/utils/files/fileinfo.go
+++ b/backend/utils/files/fileinfo.go
@@ -4,9 +4,11 @@ import (
"fmt"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
+ "io/fs"
"os"
"path"
"path/filepath"
+ "strings"
"syscall"
"time"
@@ -39,6 +41,7 @@ type FileInfo struct {
type FileOption struct {
Path string `json:"path"`
Search string `json:"search"`
+ ContainSub bool `json:"containSub"`
Expand bool `json:"expand"`
Dir bool `json:"dir"`
ShowHidden bool `json:"showHidden"`
@@ -46,6 +49,11 @@ type FileOption struct {
PageSize int `json:"pageSize"`
}
+type FileSearchInfo struct {
+ Path string `json:"path"`
+ fs.FileInfo
+}
+
func NewFileInfo(op FileOption) (*FileInfo, error) {
var appFs = afero.NewOsFs()
@@ -75,7 +83,7 @@ func NewFileInfo(op FileOption) (*FileInfo, error) {
}
if op.Expand {
if file.IsDir {
- if err := file.listChildren(op.Dir, op.ShowHidden, op.Page, op.PageSize); err != nil {
+ if err := file.listChildren(op.Dir, op.ShowHidden, op.ContainSub, op.Search, op.Page, op.PageSize); err != nil {
return nil, err
}
return file, nil
@@ -88,12 +96,59 @@ func NewFileInfo(op FileOption) (*FileInfo, error) {
return file, nil
}
-func (f *FileInfo) listChildren(dir, showHidden bool, page, pageSize int) error {
- afs := &afero.Afero{Fs: f.Fs}
- files, err := afs.ReadDir(f.Path)
- if err != nil {
- return err
+func (f *FileInfo) search(dir, showHidden bool, af afero.Afero, search string, count int) ([]FileSearchInfo, error) {
+ var files []FileSearchInfo
+ if err := afero.Walk(af, f.Path, func(path string, info fs.FileInfo, err error) error {
+ if info != nil {
+
+ if dir && !info.IsDir() {
+ return nil
+ }
+ if !showHidden && IsHidden(info.Name()) {
+ return nil
+ }
+
+ lowerName := strings.ToLower(info.Name())
+ lowerSearch := strings.ToLower(search)
+ if strings.Contains(lowerName, lowerSearch) {
+ files = append(files, FileSearchInfo{
+ Path: path,
+ FileInfo: info,
+ })
+ }
+ }
+ return nil
+ }); err != nil {
+ return nil, err
}
+ return files, nil
+}
+
+func (f *FileInfo) listChildren(dir, showHidden, containSub bool, search string, page, pageSize int) error {
+ afs := &afero.Afero{Fs: f.Fs}
+ var (
+ files []FileSearchInfo
+ err error
+ )
+
+ if search != "" && containSub {
+ files, err = f.search(dir, showHidden, *afs, search, page*pageSize)
+ if err != nil {
+ return err
+ }
+ } else {
+ dirFiles, err := afs.ReadDir(f.Path)
+ if err != nil {
+ return err
+ }
+ for _, file := range dirFiles {
+ files = append(files, FileSearchInfo{
+ Path: f.Path,
+ FileInfo: file,
+ })
+ }
+ }
+
f.ItemTotal = 0
var items []*FileInfo
@@ -103,7 +158,20 @@ func (f *FileInfo) listChildren(dir, showHidden bool, page, pageSize int) error
}
name := df.Name()
- fPath := path.Join(f.Path, df.Name())
+ fPath := path.Join(df.Path, df.Name())
+
+ if search != "" {
+ if containSub {
+ fPath = df.Path
+ name = strings.TrimPrefix(strings.TrimPrefix(fPath, f.Path), "/")
+ } else {
+ lowerName := strings.ToLower(name)
+ lowerSearch := strings.ToLower(search)
+ if !strings.Contains(lowerName, lowerSearch) {
+ continue
+ }
+ }
+ }
if !showHidden && IsHidden(name) {
continue
@@ -115,7 +183,7 @@ func (f *FileInfo) listChildren(dir, showHidden bool, page, pageSize int) error
isSymlink = true
info, err := f.Fs.Stat(fPath)
if err == nil {
- df = info
+ df.FileInfo = info
} else {
isInvalidLink = true
}
@@ -137,6 +205,7 @@ func (f *FileInfo) listChildren(dir, showHidden bool, page, pageSize int) error
Group: GetGroup(df.Sys().(*syscall.Stat_t).Gid),
MimeType: GetMimeType(fPath),
}
+
if isSymlink {
file.LinkPath = GetSymlink(fPath)
}
diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts
index 4fb4f2f1a..8724c9d2c 100644
--- a/frontend/src/api/interface/file.ts
+++ b/frontend/src/api/interface/file.ts
@@ -27,6 +27,7 @@ export namespace File {
expand: boolean;
dir?: boolean;
showHidden?: boolean;
+ containSub?: boolean;
}
export interface FileTree {
diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts
index 1eb8aac26..de2d9805a 100644
--- a/frontend/src/lang/modules/zh.ts
+++ b/frontend/src/lang/modules/zh.ts
@@ -652,7 +652,7 @@ export default {
upload: '上传',
download: '下载',
fileName: '文件名',
- search: '查找',
+ search: '在当前目录下查找',
mode: '权限',
owner: '所有者',
file: '文件',
diff --git a/frontend/src/styles/common.scss b/frontend/src/styles/common.scss
index f6e5db8a3..73cd16cd4 100644
--- a/frontend/src/styles/common.scss
+++ b/frontend/src/styles/common.scss
@@ -231,6 +231,10 @@
.el-input__wrapper {
border-radius: 50px;
}
+ .el-input-group__prepend {
+ border-top-left-radius: 50px;
+ border-bottom-left-radius: 50px;
+ }
}
// drawer头部增加按钮
diff --git a/frontend/src/views/host/file-management/index.vue b/frontend/src/views/host/file-management/index.vue
index 61497500e..44dae4bf6 100644
--- a/frontend/src/views/host/file-management/index.vue
+++ b/frontend/src/views/host/file-management/index.vue
@@ -60,16 +60,18 @@