fix(archive preview): archive file view with leading slashes display abnormally (in addition to #2865)

This commit is contained in:
Darren Yu 2025-09-14 09:55:45 +08:00
parent dece1c7098
commit 18ef42a076
No known key found for this signature in database
GPG Key ID: 2D69AA5646405984

View File

@ -122,17 +122,25 @@ const ArchivePreview = () => {
res.files
.filter((item) => item.is_directory)
.forEach((item) => {
allDirs.add(item.name);
allItems.push(item);
let normalizedName = item.name && typeof item.name === "string" && item.name.startsWith("/") ? item.name.slice(1) : item.name;
allDirs.add(normalizedName);
allItems.push({
...item,
name: normalizedName,
});
});
// 文件项,并补齐缺失目录
res.files
.filter((item) => !item.is_directory)
.forEach((item) => {
allItems.push(item);
let normalizedName = item.name && typeof item.name === "string" && item.name.startsWith("/") ? item.name.slice(1) : item.name;
allItems.push({
...item,
name: normalizedName,
});
const dirElements = item.name.split("/");
const dirElements = normalizedName.split("/");
for (let i = 1; i < dirElements.length; i++) {
const dirName = dirElements.slice(0, i).join("/");
if (!allDirs.has(dirName)) {