An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Embed block search returns empty in encrypted notebook https://github.com/siyuan-note/siyuan/issues/18034
Danielc4516c65ec71
diff --git a/app/src/protyle/render/blockRender.ts b/app/src/protyle/render/blockRender.tsindex df32814cc6..b3e3c6ae18 100644--- a/app/src/protyle/render/blockRender.ts+++ b/app/src/protyle/render/blockRender.ts@@ -5,6 +5,7 @@ import {highlightRender} from "./highlightRender";import {genBreadcrumb, improveBreadcrumbAppearance} from "../wysiwyg/renderBacklink";import {avRender} from "./av/render";import {genRenderFrame} from "./util";+import {isEncryptedBox} from "../../util/pathName";/*** 渲染嵌入块@@ -86,7 +87,8 @@ export const blockRender = (protyle: IProtyle, element: Element, top?: number) =stmt: content,headingMode: ["0", "1", "2"].includes(item.getAttribute("custom-heading-mode")) ? parseInt(item.getAttribute("custom-heading-mode")) : window.siyuan.config.editor.headingEmbedMode,excludeIDs: [item.getAttribute("data-node-id"), protyle.block.rootID],- breadcrumb+ breadcrumb,+ notebook: isEncryptedBox(protyle.notebookId) ? protyle.notebookId : ""}, (response) => {renderEmbed(response.data.blocks, protyle, item, top);});diff --git a/kernel/api/search.go b/kernel/api/search.goindex 6ac393e17d..d48451f31b 100644--- a/kernel/api/search.go+++ b/kernel/api/search.go@@ -364,7 +364,13 @@ func searchEmbedBlock(c *gin.Context) {breadcrumb = breadcrumbArg.(bool)}- blocks := model.SearchEmbedBlock(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb)+ // 加密笔记本的嵌入块查询走 InBox 版(查加密 content db,全局库不含加密数据)+ var blocks []*model.EmbedBlock+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {+ blocks = model.SearchEmbedBlockInBox(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb, notebook)+ } else {+ blocks = model.SearchEmbedBlock(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb)+ }if model.IsReadOnlyRoleContext(c) {publishAccess := model.GetPublishAccess()blocks = model.FilterEmbedBlocksByPublishAccess(c, publishAccess, blocks)diff --git a/kernel/model/search.go b/kernel/model/search.goindex 7b23122564..1d18679128 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -239,11 +239,18 @@ func getEmbedBlock(embedBlockID string, includeIDs []string, headingMode int, br}func SearchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMode int, breadcrumb bool) (ret []*EmbedBlock) {- return searchEmbedBlock(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb)+ return SearchEmbedBlockInBox(embedBlockID, stmt, excludeIDs, headingMode, breadcrumb, "")}-func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMode int, breadcrumb bool) (ret []*EmbedBlock) {- sqlBlocks := sql.SelectBlocksRawStmtNoParse(stmt, Conf.Search.Limit)+// SearchEmbedBlockInBox 与 SearchEmbedBlock 一致,但按 boxID 路由 SQL 到加密 content db。+// 加密笔记本的嵌入块查询走独立加密库(全局 siyuan.db 不含加密数据),boxID 为空时落回全局库。+func SearchEmbedBlockInBox(embedBlockID, stmt string, excludeIDs []string, headingMode int, breadcrumb bool, boxID string) (ret []*EmbedBlock) {+ var sqlBlocks []*sql.Block+ if "" != boxID {+ sqlBlocks = sql.SelectBlocksRawStmtNoParseInBox(stmt, Conf.Search.Limit, boxID)+ } else {+ sqlBlocks = sql.SelectBlocksRawStmtNoParse(stmt, Conf.Search.Limit)+ }ret = buildEmbedBlock(embedBlockID, excludeIDs, headingMode, breadcrumb, sqlBlocks)return}