Skip to content

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

:bug: fix encrypted-notebook edge function fallbacks #18034

Danielaffe78c40bf1
diff --git a/kernel/model/backlink.go b/kernel/model/backlink.go
index 69bc1210dd..902f29ad92 100644
--- a/kernel/model/backlink.go
+++ b/kernel/model/backlink.go
@@ -141,12 +141,28 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren, highlight
ret = []*Backlink{}
sqlBlock := sql.GetBlock(defID)
+ if nil == sqlBlock {
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBlock := sql.GetBlockInBox(defID, encBoxID); nil != encBlock {
+ sqlBlock = encBlock
+ break
+ }
+ }
+ }
if nil == sqlBlock {
return
}
rootID := sqlBlock.RootID
tmpRefs := sql.QueryRefsByDefID(defID, containChildren)
+ if len(tmpRefs) == 0 {
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encRefs := sql.QueryRefsByDefIDInBox(defID, containChildren, encBoxID); len(encRefs) > 0 {
+ tmpRefs = encRefs
+ break
+ }
+ }
+ }
var refs []*sql.Ref
for _, ref := range tmpRefs {
if ref.RootID == refTreeID {
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 6d8fcfa254..591eef5964 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -1299,6 +1299,14 @@ func getEmbeddedBlock(trees map[string]*parse.Tree, sqlBlock *sql.Block, heading
}
b := treenode.GetBlockTree(def.ID)
+ if nil == b {
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(def.ID, encBoxID); nil != encBT {
+ b = encBT
+ break
+ }
+ }
+ }
if nil == b {
return
}
diff --git a/kernel/model/blockinfo.go b/kernel/model/blockinfo.go
index 2280bca493..0dedef4dda 100644
--- a/kernel/model/blockinfo.go
+++ b/kernel/model/blockinfo.go
@@ -154,6 +154,16 @@ func GetDocsInfo(blockIDs []string, queryRefCount bool, queryAv bool) (rets []*B
trees := filesys.LoadTrees(blockIDs)
bts := treenode.GetBlockTrees(blockIDs)
+ for _, id := range blockIDs {
+ if _, ok := bts[id]; !ok {
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {
+ bts[id] = encBT
+ break
+ }
+ }
+ }
+ }
for _, blockID := range blockIDs {
tree := trees[blockID]
if nil == tree {
@@ -376,6 +386,14 @@ func GetBlockRefs(defID string) (refDefs []*RefDefs, originalRefBlockIDs map[str
refDefs = []*RefDefs{}
originalRefBlockIDs = map[string]string{}
bt := treenode.GetBlockTree(defID)
+ if nil == bt {
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(defID, encBoxID); nil != encBT {
+ bt = encBT
+ break
+ }
+ }
+ }
if nil == bt {
return
}
diff --git a/kernel/model/crypto.go b/kernel/model/crypto.go
index a1ef099960..7fa5bd73c7 100644
--- a/kernel/model/crypto.go
+++ b/kernel/model/crypto.go
@@ -319,6 +319,15 @@ func IsBlockRefCrossingBoundary(srcBoxID, defBlockID string) bool {
}
// 源在普通 box:def 块必须在普通 box(查全局 blocktree,且其 box 非加密)
bt := treenode.GetBlockTree(defBlockID)
+ if nil == bt {
+ // 全局查不到时遍历加密 box 查找,防止对向漏判(普通 box 引用加密 box 块)
+ for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
+ if encBT := treenode.GetBlockTreeInBox(defBlockID, encBoxID); nil != encBT {
+ bt = encBT
+ break
+ }
+ }
+ }
if nil == bt {
return false // def 块不存在(可能是新建块的临时态),不拦
}