From 3fb296c88c1dec3e06205f9e6308bfe735978000 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 3 Feb 2023 23:37:46 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=90=9C=E7=B4=A2=E5=A4=84=E4=BA=8E?= =?UTF-8?q?=E6=8A=98=E5=8F=A0=E7=8A=B6=E6=80=81=E7=9A=84=E5=9D=97=E6=97=B6?= =?UTF-8?q?=E6=9C=AA=E8=81=9A=E7=84=A6=E6=98=BE=E7=A4=BA=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/7252?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/block.go | 14 +------------- kernel/model/block.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kernel/api/block.go b/kernel/api/block.go index 13269d5dd..71d0a54e6 100644 --- a/kernel/api/block.go +++ b/kernel/api/block.go @@ -154,19 +154,7 @@ func checkBlockFold(c *gin.Context) { } id := arg["id"].(string) - b, err := model.GetBlock(id, nil) - if errors.Is(err, filelock.ErrUnableAccessFile) { - ret.Code = 2 - ret.Data = id - return - } - if errors.Is(err, model.ErrIndexing) { - ret.Code = 0 - ret.Data = false - return - } - - ret.Data = nil != b && "1" == b.IAL["fold"] + ret.Data = model.IsBlockFolded(id) } func checkBlockExist(c *gin.Context) { diff --git a/kernel/model/block.go b/kernel/model/block.go index d0775aeb7..b9b51f668 100644 --- a/kernel/model/block.go +++ b/kernel/model/block.go @@ -87,6 +87,22 @@ type Path struct { Created string `json:"created"` // 创建时间 } +func IsBlockFolded(id string) bool { + for i := 0; i < 32; i++ { + b, _ := getBlock(id, nil) + if nil == b { + return true + } + + if "1" == b.IAL["fold"] { + return true + } + + id = b.ParentID + } + return false +} + func RecentUpdatedBlocks() (ret []*Block) { ret = []*Block{}