From d0a5d79e2b4b9eb94fbc80faa6a2ccbf78481bd3 Mon Sep 17 00:00:00 2001 From: lan-yonghui Date: Fri, 15 May 2026 16:26:00 +0800 Subject: [PATCH] fix: Fix directory issue where file management loading does not exist --- .../src/views/host/file-management/index.vue | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/host/file-management/index.vue b/frontend/src/views/host/file-management/index.vue index 898b10305a34..8696f05cca87 100644 --- a/frontend/src/views/host/file-management/index.vue +++ b/frontend/src/views/host/file-management/index.vue @@ -711,6 +711,7 @@ import { computeDirSize, fileWgetKeys, getFileContent, + checkFile, removeFileShare, getFilesList, setFileRemark, @@ -1067,10 +1068,60 @@ const handleSearchResult = (res: ResultData) => { paginationConfig.total = res.data.itemTotal; dirNum.value = data.value.filter((item) => item.isDir).length; fileNum.value = data.value.filter((item) => !item.isDir).length; - req.path = res.data.path; + if (res.data.path) { + req.path = res.data.path; + } scheduleRemarkLoad(); }; +const normalizeFilePath = (filePath: string) => { + if (!filePath) { + return '/'; + } + const normalized = `/${filePath.split('/').filter(Boolean).join('/')}`; + return normalized === '' ? '/' : normalized; +}; + +const findExistingPath = async (filePath: string) => { + const segments = normalizeFilePath(filePath).split('/').filter(Boolean); + while (segments.length > 0) { + const current = `/${segments.join('/')}`; + try { + const res = await checkFile(current, false); + if (res.data) { + return current; + } + } catch { + // ignore check errors + } + segments.pop(); + } + return '/'; +}; + +const loadInitialExistingPath = async (url: string) => { + const existingPath = await findExistingPath(url); + if (existingPath === normalizeFilePath(url)) { + return; + } + const { pageSize: oldPageSize, sortBy: oldSortBy, sortOrder: oldSortOrder, showHidden } = req; + Object.assign(req, initData(), { + path: existingPath, + containSub: false, + search: '', + pageSize: oldPageSize, + sortBy: oldSortBy, + sortOrder: oldSortOrder, + showHidden, + }); + globalStore.lastFilePath = req.path; + getPaths(req.path); + updateTab(req.path); + paths.value = buildPaths(req.path); + resetPaths(); + MsgWarning(i18n.global.t('commons.res.notFound')); +}; + const viewHideFile = async () => { req.showHidden = !req.showHidden; localStorage.setItem('show-hidden', req.showHidden ? 'true' : 'false'); @@ -2202,8 +2253,9 @@ function buildPaths(path: string) { }, []); } -function initHistory() { - search(); +async function initHistory() { + await loadInitialExistingPath(req.path); + await search(); history.push(req.path); pointer = history.length - 1; } @@ -2363,7 +2415,7 @@ onMounted(async () => { initShowHidden(); initTabsAndPaths(); await getHostMount(); - initHistory(); + await initHistory(); checkFFmpeg(); await nextTick(function () { handlePath();