mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Add internal kernel API /api/attr/batchSetBlockAttrs https://github.com/siyuan-note/siyuan/issues/10337
This commit is contained in:
parent
70869ec218
commit
11993cab32
3 changed files with 86 additions and 0 deletions
|
|
@ -88,6 +88,48 @@ func setBlockAttrs(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func batchSetBlockAttrs(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
blockAttrsArg := arg["blockAttrs"].([]interface{})
|
||||
var blockAttrs []map[string]interface{}
|
||||
for _, blockAttrArg := range blockAttrsArg {
|
||||
blockAttr := blockAttrArg.(map[string]interface{})
|
||||
id := blockAttr["id"].(string)
|
||||
if util.InvalidIDPattern(id, ret) {
|
||||
return
|
||||
}
|
||||
|
||||
attrs := blockAttr["attrs"].(map[string]interface{})
|
||||
nameValues := map[string]string{}
|
||||
for name, value := range attrs {
|
||||
if nil == value {
|
||||
nameValues[name] = ""
|
||||
} else {
|
||||
nameValues[name] = value.(string)
|
||||
}
|
||||
}
|
||||
|
||||
blockAttrs = append(blockAttrs, map[string]interface{}{
|
||||
"id": id,
|
||||
"attrs": nameValues,
|
||||
})
|
||||
}
|
||||
|
||||
err := model.BatchSetBlockAttrs(blockAttrs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func resetBlockAttrs(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue