mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-25 19:52:48 +00:00
fix(archive preview): archive file view with leading slashes display abnormally (in addition to #2865) (#314)
* fix(archive preview): archive file view with leading slashes display abnormally (in addition to #2865) * Update ArchivePreview.tsx
This commit is contained in:
parent
a8e91e9bc8
commit
beb21a6dbc
|
|
@ -93,6 +93,14 @@ const ArchivePreview = () => {
|
||||||
return currentPath.split("/").filter(Boolean);
|
return currentPath.split("/").filter(Boolean);
|
||||||
}, [currentPath]);
|
}, [currentPath]);
|
||||||
|
|
||||||
|
// 规范化路径,去除开头可能存在的 `/`
|
||||||
|
const normalizeName = (name: string) => {
|
||||||
|
if (name && typeof name === "string" && name.startsWith("/")) {
|
||||||
|
return name.slice(1);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!viewerState || !viewerState.open) {
|
if (!viewerState || !viewerState.open) {
|
||||||
setEncoding(defaultEncodingValue);
|
setEncoding(defaultEncodingValue);
|
||||||
|
|
@ -122,17 +130,25 @@ const ArchivePreview = () => {
|
||||||
res.files
|
res.files
|
||||||
.filter((item) => item.is_directory)
|
.filter((item) => item.is_directory)
|
||||||
.forEach((item) => {
|
.forEach((item) => {
|
||||||
allDirs.add(item.name);
|
const normalizedName = normalizeName(item.name);
|
||||||
allItems.push(item);
|
allItems.push({
|
||||||
|
...item,
|
||||||
|
name: normalizedName,
|
||||||
|
});
|
||||||
|
allDirs.add(normalizedName);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 文件项,并补齐缺失目录
|
// 文件项,并补齐缺失目录
|
||||||
res.files
|
res.files
|
||||||
.filter((item) => !item.is_directory)
|
.filter((item) => !item.is_directory)
|
||||||
.forEach((item) => {
|
.forEach((item) => {
|
||||||
allItems.push(item);
|
const normalizedName = normalizeName(item.name);
|
||||||
|
allItems.push({
|
||||||
|
...item,
|
||||||
|
name: normalizedName,
|
||||||
|
});
|
||||||
|
|
||||||
const dirElements = item.name.split("/");
|
const dirElements = normalizedName.split("/");
|
||||||
for (let i = 1; i < dirElements.length; i++) {
|
for (let i = 1; i < dirElements.length; i++) {
|
||||||
const dirName = dirElements.slice(0, i).join("/");
|
const dirName = dirElements.slice(0, i).join("/");
|
||||||
if (!allDirs.has(dirName)) {
|
if (!allDirs.has(dirName)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue