Skip to content

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

:bug: fix encrypted-notebook tree loading when boxID unknown #18034

Daniel9782fbf9b32f
diff --git a/kernel/model/tree.go b/kernel/model/tree.go
index 60ad86b656..dd865920e2 100644
--- a/kernel/model/tree.go
+++ b/kernel/model/tree.go
@@ -208,6 +208,15 @@ func LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err e
}
bt := treenode.GetBlockTreeInBox(id, boxID)
+ if nil == bt && "" == boxID {
+ // boxID 未知时(如通用打开入口),遍历所有已打开的加密 box 查找
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
+ bt = encBT
+ break
+ }
+ }
+ }
if nil == bt {
if task.ContainIndexTask() {
err = ErrIndexing
@@ -279,6 +288,15 @@ func loadTreeByBlockIDInBox(id, boxID string) (ret *parse.Tree, err error) {
}
bt := treenode.GetBlockTreeInBox(id, boxID)
+ if nil == bt && "" == boxID {
+ // boxID 未知时(如通用打开入口),遍历所有已打开的加密 box 查找
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
+ bt = encBT
+ break
+ }
+ }
+ }
if nil == bt {
if task.ContainIndexTask() {
err = ErrIndexing
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index e0b1c62433..9d78316aee 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -842,6 +842,18 @@ func CloseAllEncryptedBlockTreeDBs() {
})
}
+// GetOpenedEncryptedBoxIDs 返回所有已打开的加密 blocktree db 对应的 boxID。
+// 供 boxID 未知时遍历查找(如通用打开入口 openFileById)。
+func GetOpenedEncryptedBoxIDs() (ret []string) {
+ encryptedBlockTreeDBs.Range(func(key, value any) bool {
+ if boxID, ok := key.(string); ok {
+ ret = append(ret, boxID)
+ }
+ return true
+ })
+ return
+}
+
// RemoveEncryptedBlockTreeDBFile 关闭连接并删除加密 blocktree db 文件。删笔记本时调用。
func RemoveEncryptedBlockTreeDBFile(boxID string) {
CloseEncryptedBlockTreeDB(boxID)