| 76 | * 转换为优化格式 |
| 77 | */ |
| 78 | export function convertToOptimizedHighlight(highlight: HiNote): OptimizedHighlight { |
| 79 | const now = Date.now(); |
| 80 | const optimized: OptimizedHighlight = { |
| 81 | text: highlight.text, |
| 82 | position: highlight.position, |
| 83 | created: highlight.createdAt ?? now, |
| 84 | updated: highlight.updatedAt ?? now |
| 85 | }; |
| 86 | |
| 87 | if (highlight.backgroundColor) { |
| 88 | optimized.backgroundColor = highlight.backgroundColor; |
| 89 | } |
| 90 | |
| 91 | if (highlight.blockId) { |
| 92 | optimized.blockId = highlight.blockId; |
| 93 | } |
| 94 | |
| 95 | if (highlight.isCloze) { |
| 96 | optimized.isCloze = highlight.isCloze; |
| 97 | } |
| 98 | |
| 99 | if (highlight.isVirtual) { |
| 100 | optimized.isVirtual = highlight.isVirtual; |
| 101 | } |
| 102 | |
| 103 | if (highlight.paragraphOffset !== undefined) { |
| 104 | optimized.paragraphOffset = highlight.paragraphOffset; |
| 105 | } |
| 106 | |
| 107 | if (highlight.contextBefore) { |
| 108 | optimized.contextBefore = highlight.contextBefore; |
| 109 | } |
| 110 | |
| 111 | if (highlight.contextAfter) { |
| 112 | optimized.contextAfter = highlight.contextAfter; |
| 113 | } |
| 114 | |
| 115 | if (highlight.textFingerprint) { |
| 116 | optimized.textFingerprint = highlight.textFingerprint; |
| 117 | } |
| 118 | |
| 119 | if (highlight.comments && highlight.comments.length > 0) { |
| 120 | optimized.comments = highlight.comments.map((comment: CommentItem) => ({ |
| 121 | id: comment.id, |
| 122 | content: comment.content, |
| 123 | created: comment.createdAt, |
| 124 | updated: comment.updatedAt |
| 125 | })); |
| 126 | } |
| 127 | |
| 128 | return optimized; |
| 129 | } |