diff --git a/backend/app/service/file.go b/backend/app/service/file.go index 7ae96bedb..9c401a4ef 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -62,9 +62,13 @@ func NewIFileService() IFileService { func (f *FileService) GetFileList(op request.FileOption) (response.FileInfo, error) { var fileInfo response.FileInfo - if _, err := os.Stat(op.Path); err != nil && os.IsNotExist(err) { + data, err := os.Stat(op.Path) + if err != nil && os.IsNotExist(err) { return fileInfo, nil } + if !data.IsDir() { + op.FileOption.Path = filepath.Dir(op.FileOption.Path) + } info, err := files.NewFileInfo(op.FileOption) if err != nil { return fileInfo, err diff --git a/frontend/src/views/host/file-management/index.vue b/frontend/src/views/host/file-management/index.vue index 0cd687f8f..5ddc38298 100644 --- a/frontend/src/views/host/file-management/index.vue +++ b/frontend/src/views/host/file-management/index.vue @@ -724,40 +724,22 @@ const top = () => { }; const jump = async (url: string) => { - const fileName = url.substring(url.lastIndexOf('/') + 1); - let filePath = url.substring(0, url.lastIndexOf('/') + 1); - if (!url.includes('.')) { - filePath = url; - } history.splice(pointer + 1); history.push(url); pointer = history.length - 1; - const oldUrl = req.path; - const oldPageSize = req.pageSize; - // reset search params before exec jump - Object.assign(req, initData()); - req.path = filePath; - req.containSub = false; - req.search = ''; - req.pageSize = oldPageSize; + const { path: oldUrl, pageSize: oldPageSize } = req; + Object.assign(req, initData(), { path: url, containSub: false, search: '', pageSize: oldPageSize }); let searchResult = await searchFile(); - - globalStore.setLastFilePath(req.path); // check search result,the file is exists? if (!searchResult.data.path) { req.path = oldUrl; + globalStore.setLastFilePath(req.path); MsgWarning(i18n.global.t('commons.res.notFound')); return; } - if (fileName && fileName.length > 1 && fileName.includes('.')) { - const fileData = searchResult.data.items.filter((item) => item.name === fileName); - if (fileData && fileData.length === 1) { - openView(fileData[0]); - } else { - MsgWarning(i18n.global.t('commons.res.notFound')); - } - } + req.path = searchResult.data.path; + globalStore.setLastFilePath(req.path); handleSearchResult(searchResult); getPaths(req.path); nextTick(function () { @@ -896,6 +878,10 @@ const openView = (item: File.File) => { }; const openPreview = (item: File.File, fileType: string) => { + if (item.mode.toString() == '-' && item.user == '-' && item.group == '-') { + MsgWarning(i18n.global.t('file.fileCanNotRead')); + return; + } filePreview.path = item.isSymlink ? item.linkPath : item.path; filePreview.name = item.name; filePreview.extension = item.extension;