fix: 修复 LibraryView formatDate 函数日期格式化错误

问题:
- Library 页面渲染时崩溃
- Console 错误: RangeError: Invalid time value
- formatDate 函数未处理无效日期

原因:
- formatDate(date) 没有 null/undefined 检查
- new Date(date) 对无效字符串创建 Invalid Date
- Invalid Date.toISOString() 抛出 RangeError

修复:
- 添加 null/undefined 检查
- 添加 try-catch 错误处理
- 验证日期有效性后才格式化

测试:
- ✅ TypeScript 编译通过
- ✅ Vite build 成功
- ✅ 错误处理正确

影响:
- Library 页面正常显示文件列表
- 无效日期显示为空字符串
- 不会崩溃
This commit is contained in:
2026-10-09 23:02:58 +08:00
parent 366b65cdf4
commit 670ef45c32

View File

@@ -1015,7 +1015,14 @@ function formatSize(bytes: number) {
}
function formatDate(date: string) {
return new Date(date).toISOString().slice(0, 10)
if (!date) return ''
try {
const d = new Date(date)
if (isNaN(d.getTime())) return ''
return d.toISOString().slice(0, 10)
} catch {
return ''
}
}
function formatRelativeTime(isoString: string | undefined): string {