修复部分显示问题

This commit is contained in:
yoyuzh
2026-03-26 14:29:30 +08:00
parent b2d9db7be9
commit 448e2a6886
14 changed files with 630 additions and 163 deletions

View File

@@ -0,0 +1,23 @@
export function ellipsizeFileName(fileName: string, maxLength = 36) {
if (fileName.length <= maxLength) {
return fileName;
}
if (maxLength <= 3) {
return '.'.repeat(Math.max(0, maxLength));
}
const extensionIndex = fileName.lastIndexOf('.');
const hasUsableExtension = extensionIndex > 0 && extensionIndex < fileName.length - 1;
if (hasUsableExtension) {
const extension = fileName.slice(extensionIndex);
const prefixLength = maxLength - extension.length - 3;
if (prefixLength > 0) {
return `${fileName.slice(0, prefixLength)}...${extension}`;
}
}
return `${fileName.slice(0, maxLength - 3)}...`;
}