Skip to content

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

:bug: 只读模式下多项折叠会导致数据类型错误 https://github.com/siyuan-note/siyuan/issues/6557

Liang Ding6d8d73026239
diff --git a/kernel/api/transaction.go b/kernel/api/transaction.go
index 0008809a94..9dc32e7478 100644
--- a/kernel/api/transaction.go
+++ b/kernel/api/transaction.go
@@ -63,17 +63,23 @@ func performTransactions(c *gin.Context) {
return
}
- if op := model.IsSetAttrs(&transactions); nil != op {
+ setAttrsOps := model.ExtractSetAttrsOps(&transactions)
+ for _, setAttrsOp := range setAttrsOps {
attrs := map[string]string{}
- if err = gulu.JSON.UnmarshalJSON([]byte(op.Data.(string)), &attrs); nil != err {
+ if err = gulu.JSON.UnmarshalJSON([]byte(setAttrsOp.Data.(string)), &attrs); nil != err {
+ return
+ }
+ if err = model.SetBlockAttrs(setAttrsOp.ID, attrs); nil != err {
+ if errors.Is(err, filelock.ErrUnableAccessFile) {
+ ret.Code = 1
+ return
+ }
+ logging.LogFatalf("set block attrs failed: %s", err)
return
}
- err = model.SetBlockAttrs(op.ID, attrs)
- } else {
- err = model.PerformTransactions(&transactions)
}
- if errors.Is(err, filelock.ErrUnableAccessFile) {
+ if err = model.PerformTransactions(&transactions); errors.Is(err, filelock.ErrUnableAccessFile) {
ret.Code = 1
return
}
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 657f6a6fc5..81b9547de9 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -56,13 +56,20 @@ func IsUnfoldHeading(transactions *[]*Transaction) bool {
return false
}
-func IsSetAttrs(transactions *[]*Transaction) *Operation {
- if 1 == len(*transactions) && 1 == len((*transactions)[0].DoOperations) {
- if op := (*transactions)[0].DoOperations[0]; "setAttrs" == op.Action {
- return op
+func ExtractSetAttrsOps(transactions *[]*Transaction) (ret []*Operation) {
+ for _, tx := range *transactions {
+ var setAttrsOps, tmp []*Operation
+ for _, op := range tx.DoOperations {
+ if "setAttrs" == op.Action {
+ setAttrsOps = append(setAttrsOps, op)
+ } else {
+ tmp = append(tmp, op)
+ }
}
+ ret = append(ret, setAttrsOps...)
+ tx.DoOperations = tmp
}
- return nil
+ return
}
const txFixDelay = 10