diff --git a/internal/service/file.go b/internal/service/file.go index cb57ed90..d3d018a8 100644 --- a/internal/service/file.go +++ b/internal/service/file.go @@ -480,42 +480,6 @@ func (s *FileService) formatDir(base string, entries []stdos.DirEntry) []any { return paths } -// formatInfo 格式化文件信息 -func (s *FileService) formatInfo(infos map[string]stdos.FileInfo) []map[string]any { - var paths []map[string]any - for path, info := range infos { - stat := info.Sys().(*syscall.Stat_t) - paths = append(paths, map[string]any{ - "name": info.Name(), - "full": path, - "size": tools.FormatBytes(float64(info.Size())), - "mode_str": info.Mode().String(), - "mode": fmt.Sprintf("%04o", info.Mode().Perm()), - "owner": os.GetUser(stat.Uid), - "group": os.GetGroup(stat.Gid), - "uid": stat.Uid, - "gid": stat.Gid, - "hidden": io.IsHidden(info.Name()), - "symlink": io.IsSymlink(info.Mode()), - "link": io.GetSymlink(path), - "dir": info.IsDir(), - "modify": info.ModTime().Format(time.DateTime), - }) - } - - slices.SortFunc(paths, func(a, b map[string]any) int { - if cast.ToBool(a["dir"]) && !cast.ToBool(b["dir"]) { - return -1 - } - if !cast.ToBool(a["dir"]) && cast.ToBool(b["dir"]) { - return 1 - } - return strings.Compare(strings.ToLower(cast.ToString(a["name"])), strings.ToLower(cast.ToString(b["name"]))) - }) - - return paths -} - // setPermission 设置权限 func (s *FileService) setPermission(path string, mode stdos.FileMode, owner, group string) { _ = io.Chmod(path, mode) diff --git a/pkg/io/search.go b/pkg/io/search.go index 7c5fe2bc..74d07c5c 100644 --- a/pkg/io/search.go +++ b/pkg/io/search.go @@ -49,7 +49,7 @@ func SearchX(path, keyword string, sub bool) ([]os.DirEntry, error) { if line == "" || line == path { continue } - entry, err := newDirEntryFromPath(line) + entry, err := newSearchEntryFromPath(line) if err != nil { continue // 直接跳过,不返回错误,不然很烦人的 } @@ -65,9 +65,9 @@ type SearchEntry struct { info os.FileInfo } -// newDirEntryFromPath 根据文件路径创建 SearchEntry -func newDirEntryFromPath(path string) (*SearchEntry, error) { - info, err := os.Stat(path) +// newSearchEntryFromPath 根据文件路径创建 SearchEntry +func newSearchEntryFromPath(path string) (*SearchEntry, error) { + info, err := os.Lstat(path) // 不跟随符号链接 if err != nil { return nil, err } diff --git a/web/src/api/panel/file/index.ts b/web/src/api/panel/file/index.ts index edafe824..cf5ba67c 100644 --- a/web/src/api/panel/file/index.ts +++ b/web/src/api/panel/file/index.ts @@ -30,9 +30,6 @@ export default { http.Post('/file/compress', { dir, paths, file }), // 解压文件 unCompress: (file: string, path: string): any => http.Post('/file/un_compress', { file, path }), - // 搜索文件 - search: (path: string, keyword: string, sub: boolean, page: number, limit: number): any => - http.Get('/file/search', { params: { path, keyword, sub, page, limit } }), // 获取文件列表 list: ( path: string, diff --git a/web/src/components/common/CodeEditor.vue b/web/src/components/common/CodeEditor.vue index 432c117f..1ae44212 100644 --- a/web/src/components/common/CodeEditor.vue +++ b/web/src/components/common/CodeEditor.vue @@ -21,7 +21,7 @@ const disabled = ref(false) // 在出现错误的情况下禁用保存 const content = ref('') const get = () => { - useRequest(file.content(props.path)) + useRequest(file.content(encodeURIComponent(props.path))) .onSuccess(({ data }) => { content.value = decodeBase64(data.content) window.$message.success($gettext('Retrieved successfully')) diff --git a/web/src/views/file/ListTable.vue b/web/src/views/file/ListTable.vue index 6da3c4df..1d347103 100644 --- a/web/src/views/file/ListTable.vue +++ b/web/src/views/file/ListTable.vue @@ -391,7 +391,8 @@ const rowProps = (row: any) => { } const { loading, data, page, total, pageSize, pageCount, refresh } = usePagination( - (page, pageSize) => file.list(path.value, keyword.value, sub.value, sort.value, page, pageSize), + (page, pageSize) => + file.list(encodeURIComponent(path.value), keyword.value, sub.value, sort.value, page, pageSize), { initialData: { total: 0, list: [] }, initialPageSize: 100, diff --git a/web/src/views/file/PreviewModal.vue b/web/src/views/file/PreviewModal.vue index 8d20b4bc..c387eacb 100644 --- a/web/src/views/file/PreviewModal.vue +++ b/web/src/views/file/PreviewModal.vue @@ -16,7 +16,7 @@ watch( () => path.value, () => { content.value = '' - useRequest(file.content(path.value)).onSuccess(({ data }) => { + useRequest(file.content(encodeURIComponent(path.value))).onSuccess(({ data }) => { mime.value = data.mime content.value = data.content }) diff --git a/web/src/views/task/CronView.vue b/web/src/views/task/CronView.vue index 37f54bdf..dc156af1 100644 --- a/web/src/views/task/CronView.vue +++ b/web/src/views/task/CronView.vue @@ -180,7 +180,7 @@ const handleStatusChange = (row: any) => { const handleEdit = (row: any) => { useRequest(cron.get(row.id)).onSuccess(({ data }) => { - useRequest(file.content(data.shell)).onSuccess(({ data }) => { + useRequest(file.content(encodeURIComponent(data.shell))).onSuccess(({ data }) => { editTask.value.id = row.id editTask.value.name = row.name editTask.value.time = row.time