Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions frontend/src/views/host/file-management/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ import {
computeDirSize,
fileWgetKeys,
getFileContent,
checkFile,
removeFileShare,
getFilesList,
setFileRemark,
Expand Down Expand Up @@ -1067,10 +1068,60 @@ const handleSearchResult = (res: ResultData<File.File>) => {
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');
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -2363,7 +2415,7 @@ onMounted(async () => {
initShowHidden();
initTabsAndPaths();
await getHostMount();
initHistory();
await initHistory();
checkFFmpeg();
await nextTick(function () {
handlePath();
Expand Down
Loading