1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-17 03:04:46 +08:00

fix: 主机文件的路径栏路径 Bug 解决 (#6428)

Refs #6310
This commit is contained in:
2024-09-10 11:46:08 +08:00 committed by GitHub
parent 64bc92a7fd
commit b6c873f22d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 24 deletions

View File

@ -62,9 +62,13 @@ func NewIFileService() IFileService {
func (f *FileService) GetFileList(op request.FileOption) (response.FileInfo, error) { func (f *FileService) GetFileList(op request.FileOption) (response.FileInfo, error) {
var fileInfo response.FileInfo 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 return fileInfo, nil
} }
if !data.IsDir() {
op.FileOption.Path = filepath.Dir(op.FileOption.Path)
}
info, err := files.NewFileInfo(op.FileOption) info, err := files.NewFileInfo(op.FileOption)
if err != nil { if err != nil {
return fileInfo, err return fileInfo, err

View File

@ -724,40 +724,22 @@ const top = () => {
}; };
const jump = async (url: string) => { 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.splice(pointer + 1);
history.push(url); history.push(url);
pointer = history.length - 1; pointer = history.length - 1;
const oldUrl = req.path; const { path: oldUrl, pageSize: oldPageSize } = req;
const oldPageSize = req.pageSize; Object.assign(req, initData(), { path: url, containSub: false, search: '', pageSize: oldPageSize });
// reset search params before exec jump
Object.assign(req, initData());
req.path = filePath;
req.containSub = false;
req.search = '';
req.pageSize = oldPageSize;
let searchResult = await searchFile(); let searchResult = await searchFile();
globalStore.setLastFilePath(req.path);
// check search result,the file is exists? // check search result,the file is exists?
if (!searchResult.data.path) { if (!searchResult.data.path) {
req.path = oldUrl; req.path = oldUrl;
globalStore.setLastFilePath(req.path);
MsgWarning(i18n.global.t('commons.res.notFound')); MsgWarning(i18n.global.t('commons.res.notFound'));
return; return;
} }
if (fileName && fileName.length > 1 && fileName.includes('.')) { req.path = searchResult.data.path;
const fileData = searchResult.data.items.filter((item) => item.name === fileName); globalStore.setLastFilePath(req.path);
if (fileData && fileData.length === 1) {
openView(fileData[0]);
} else {
MsgWarning(i18n.global.t('commons.res.notFound'));
}
}
handleSearchResult(searchResult); handleSearchResult(searchResult);
getPaths(req.path); getPaths(req.path);
nextTick(function () { nextTick(function () {
@ -896,6 +878,10 @@ const openView = (item: File.File) => {
}; };
const openPreview = (item: File.File, fileType: string) => { 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.path = item.isSymlink ? item.linkPath : item.path;
filePreview.name = item.name; filePreview.name = item.name;
filePreview.extension = item.extension; filePreview.extension = item.extension;