* 获取文件的所有高亮数据 * @param filePath 文件路径 * @returns 高亮数组
(filePath: string)
| 80 | * @returns 高亮数组 |
| 81 | */ |
| 82 | async getFileHighlights(filePath: string): Promise<HiNote[]> { |
| 83 | const storagePath = this.getStoragePathForFile(filePath); |
| 84 | |
| 85 | try { |
| 86 | const content = await this.app.vault.adapter.read(storagePath); |
| 87 | const data: OptimizedHighlightData = JSON.parse(content); |
| 88 | |
| 89 | // 验证数据格式 |
| 90 | const validation = DataValidator.validateHighlightData(data); |
| 91 | if (!validation.valid) { |
| 92 | console.warn(`文件 ${filePath} 的高亮数据验证失败:`, validation.errors); |
| 93 | return []; |
| 94 | } |
| 95 | |
| 96 | // 转换为旧格式以保持兼容性 |
| 97 | return Object.entries(data.highlights).map(([id, highlight]) => |
| 98 | convertToLegacyHighlight(id, highlight, filePath) |
| 99 | ); |
| 100 | } catch { |
| 101 | // 文件不存在或读取失败 |
| 102 | return []; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * 保存文件的高亮数据 |
nothing calls this directly
no test coverage detected