fix(search): add null check for canvas elements in fulltext search

添加对 Canvas 笔记 elements 字段的空值检查,防止当 elements 为 null 或非数组时搜索功能报错。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jason Wasem 2025-12-18 00:42:12 +08:00
parent b9c39d757b
commit ecb972c71c

View File

@ -317,11 +317,16 @@ class NoteContentFulltextExp extends Expression {
let canvasContent = JSON.parse(content);
const elements: Element[] = canvasContent.elements;
const texts = elements
.filter((element: Element) => element.type === "text" && element.text) // Filter for 'text' type elements with a 'text' property
.map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering
content = normalize(texts.toString());
if (elements && Array.isArray(elements)) {
const texts = elements
.filter((element: Element) => element.type === "text" && element.text) // Filter for 'text' type elements with a 'text' property
.map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering
content = normalize(texts.toString());
} else {
content = "";
}
}
return content.trim();