mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Kernel API transferBlockRef
https://github.com/siyuan-note/siyuan/issues/8522
This commit is contained in:
parent
4153d22acb
commit
eda8da1bbe
4 changed files with 67 additions and 3 deletions
27
API.md
27
API.md
|
@ -30,6 +30,7 @@
|
||||||
* [Move a block](#Move-a-block)
|
* [Move a block](#Move-a-block)
|
||||||
* [Get a block kramdown](#Get-a-block-kramdown)
|
* [Get a block kramdown](#Get-a-block-kramdown)
|
||||||
* [Get child blocks](#get-child-blocks)
|
* [Get child blocks](#get-child-blocks)
|
||||||
|
* [Transfer block ref](#transfer-block-ref)
|
||||||
* [Attributes](#Attributes)
|
* [Attributes](#Attributes)
|
||||||
* [Set block attributes](#Set-block-attributes)
|
* [Set block attributes](#Set-block-attributes)
|
||||||
* [Get block attributes](#Get-block-attributes)
|
* [Get block attributes](#Get-block-attributes)
|
||||||
|
@ -815,6 +816,32 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Transfer block ref
|
||||||
|
|
||||||
|
* `/api/block/transferBlockRef`
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"fromID": "20230612160235-mv6rrh1",
|
||||||
|
"toID": "20230613093045-uwcomng",
|
||||||
|
"refIDs": ["20230613092230-cpyimmd"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `fromID`: Def block ID
|
||||||
|
* `toID`: Target block ID
|
||||||
|
* `refIDs`: Ref block IDs point to def block ID, optional, if not specified, all ref block IDs will be transferred
|
||||||
|
* Return value
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Attributes
|
## Attributes
|
||||||
|
|
||||||
### Set block attributes
|
### Set block attributes
|
||||||
|
|
28
API_zh_CN.md
28
API_zh_CN.md
|
@ -30,6 +30,7 @@
|
||||||
* [移动块](#移动块)
|
* [移动块](#移动块)
|
||||||
* [获取块 kramdown 源码](#获取块-kramdown-源码)
|
* [获取块 kramdown 源码](#获取块-kramdown-源码)
|
||||||
* [获取子块](#获取子块)
|
* [获取子块](#获取子块)
|
||||||
|
* [转移块引用](#转移块引用)
|
||||||
* [属性](#属性)
|
* [属性](#属性)
|
||||||
* [设置块属性](#设置块属性)
|
* [设置块属性](#设置块属性)
|
||||||
* [获取块属性](#获取块属性)
|
* [获取块属性](#获取块属性)
|
||||||
|
@ -808,6 +809,33 @@
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 转移块引用
|
||||||
|
|
||||||
|
* `/api/block/transferBlockRef`
|
||||||
|
* 参数
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"fromID": "20230612160235-mv6rrh1",
|
||||||
|
"toID": "20230613093045-uwcomng",
|
||||||
|
"refIDs": ["20230613092230-cpyimmd"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* `fromID`:定义块 ID
|
||||||
|
* `toID`:目标块 ID
|
||||||
|
* `refIDs`:指向定义块 ID 的引用所在块 ID,可选,如果不指定,所有指向定义块 ID 的引用块 ID 都会被转移
|
||||||
|
* 返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## 属性
|
## 属性
|
||||||
|
|
||||||
### 设置块属性
|
### 设置块属性
|
||||||
|
|
|
@ -47,7 +47,14 @@ func transferBlockRef(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := model.TransferBlockRef(fromID, toID)
|
var refIDs []string
|
||||||
|
if nil != arg["refIDs"] {
|
||||||
|
for _, refID := range arg["refIDs"].([]interface{}) {
|
||||||
|
refIDs = append(refIDs, refID.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := model.TransferBlockRef(fromID, toID, refIDs)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
|
@ -117,7 +117,7 @@ func RecentUpdatedBlocks() (ret []*Block) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransferBlockRef(fromID, toID string) (err error) {
|
func TransferBlockRef(fromID, toID string, refIDs []string) (err error) {
|
||||||
toTree, _ := loadTreeByBlockID(toID)
|
toTree, _ := loadTreeByBlockID(toID)
|
||||||
if nil == toTree {
|
if nil == toTree {
|
||||||
err = ErrBlockNotFound
|
err = ErrBlockNotFound
|
||||||
|
@ -132,7 +132,9 @@ func TransferBlockRef(fromID, toID string) (err error) {
|
||||||
|
|
||||||
util.PushMsg(Conf.Language(116), 7000)
|
util.PushMsg(Conf.Language(116), 7000)
|
||||||
|
|
||||||
refIDs, _ := sql.QueryRefIDsByDefID(fromID, false)
|
if 1 > len(refIDs) { // 如果不指定 refIDs,则转移所有引用了 fromID 的块
|
||||||
|
refIDs, _ = sql.QueryRefIDsByDefID(fromID, false)
|
||||||
|
}
|
||||||
for _, refID := range refIDs {
|
for _, refID := range refIDs {
|
||||||
tree, _ := loadTreeByBlockID(refID)
|
tree, _ := loadTreeByBlockID(refID)
|
||||||
if nil == tree {
|
if nil == tree {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue