Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: encrypted-notebook box-scoped read: block ref text (stage 8 part 2a) #18034

Daniel7068621dd817
diff --git a/kernel/api/block.go b/kernel/api/block.go
index 03eaf0b36c..8856dc7eee 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -544,7 +544,13 @@ func getRefText(c *gin.Context) {
return
}
- refText := model.GetBlockRefText(id)
+ // 加密笔记本的块引解析走 InBox 版(查加密 blocktree + content db)
+ var refText string
+ if notebook, ok := arg["notebook"].(string); ok && notebook != "" && model.IsEncryptedBox(notebook) {
+ refText = model.GetBlockRefTextInBox(id, notebook)
+ } else {
+ refText = model.GetBlockRefText(id)
+ }
if "" == refText {
// 空块返回 id https://github.com/siyuan-note/siyuan/issues/10259
refText = id
diff --git a/kernel/model/encrypted_ops.go b/kernel/model/encrypted_ops.go
new file mode 100644
index 0000000000..fe56bf1587
--- /dev/null
+++ b/kernel/model/encrypted_ops.go
@@ -0,0 +1,65 @@
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package model
+
+import (
+ "github.com/88250/lute/ast"
+ "github.com/siyuan-note/siyuan/kernel/sql"
+ "github.com/siyuan-note/siyuan/kernel/treenode"
+)
+
+// 本文件提供加密笔记本的专用操作函数。每个函数接收 boxID,路由到加密 db。
+// 与原函数(GetBlockRefText、GetDoc 等)完全独立,原函数行为不变。
+// 调用方为 API handler 层:当请求带 notebook 参数且为加密 box 时,调这里的 InBox 版。
+
+// GetBlockRefTextInBox 在指定加密 box 内解析块引锚文本。
+func GetBlockRefTextInBox(id, boxID string) string {
+ FlushTxQueue()
+
+ bt := treenode.GetBlockTreeInBox(id, boxID)
+ if nil == bt {
+ return ErrBlockNotFound.Error()
+ }
+
+ tree, err := loadTreeByBlockTree(bt)
+ if err != nil {
+ return ""
+ }
+
+ node := treenode.GetNodeInTree(tree, id)
+ if nil == node {
+ return ErrBlockNotFound.Error()
+ }
+
+ ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
+ if !entering {
+ return ast.WalkContinue
+ }
+ if n.IsTextMarkType("inline-memo") {
+ n.TextMarkInlineMemoContent = ""
+ return ast.WalkContinue
+ }
+ return ast.WalkContinue
+ })
+
+ return getNodeRefText(node)
+}
+
+// GetRefTextInBox 在指定加密 box 内查块的引用文本(SQL 查询版,不走文件系统)。
+func GetRefTextInBox(defBlockID, boxID string) string {
+ return sql.GetRefTextInBox(defBlockID, boxID)
+}