Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-04-06 19:14:40 +08:00
commit 053c4864a1
7 changed files with 139 additions and 0 deletions

45
API.md
View file

@ -27,6 +27,7 @@
* [Append blocks](#Append-blocks)
* [Update a block](#Update-a-block)
* [Delete a block](#Delete-a-block)
* [Move a block](#Move-a-block)
* [Get a block kramdown](#Get-a-block-kramdown)
* [Attributes](#Attributes)
* [Set block attributes](#Set-block-attributes)
@ -696,6 +697,50 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
}
```
### Move a block
* `/api/block/moveBlock`
* Parameters
```json
{
"id": "20230406180530-3o1rqkc",
"previousID": "20230406152734-if5kyx6",
"parentID": "20230404183855-woe52ko"
}
```
* `id`: Block ID to move
* `previousID`: The ID of the previous block, used to anchor the insertion position
* `parentID`: The ID of the parent block, used to anchor the insertion position, `previousID` and `parentID` cannot be empty at the same time, if they exist at the same time, `previousID` will be used first
* Return value
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "move",
"data": null,
"id": "20230406180530-3o1rqkc",
"parentID": "20230404183855-woe52ko",
"previousID": "20230406152734-if5kyx6",
"nextID": "",
"retData": null,
"srcIDs": null,
"name": "",
"type": ""
}
],
"undoOperations": null
}
]
}
```
### Get a block kramdown
* `/api/block/getBlockKramdown`

View file

@ -27,6 +27,7 @@
* [插入后置子块](#插入后置子块)
* [更新块](#更新块)
* [删除块](#删除块)
* [移动块](#移动块)
* [获取块 kramdown 源码](#获取块-kramdown-源码)
* [属性](#属性)
* [设置块属性](#设置块属性)
@ -690,6 +691,50 @@
}
```
### 移动块
* `/api/block/moveBlock`
* 参数
```json
{
"id": "20230406180530-3o1rqkc",
"previousID": "20230406152734-if5kyx6",
"parentID": "20230404183855-woe52ko"
}
```
* `id`:待移动块 ID
* `previousID`:前一个块的 ID用于锚定插入位置
* `parentID`:父块的 ID用于锚定插入位置`previousID``parentID` 不能同时为空,同时存在的话优先使用 `previousID`
* 返回值
```json
{
"code": 0,
"msg": "",
"data": [
{
"doOperations": [
{
"action": "move",
"data": null,
"id": "20230406180530-3o1rqkc",
"parentID": "20230404183855-woe52ko",
"previousID": "20230406152734-if5kyx6",
"nextID": "",
"retData": null,
"srcIDs": null,
"name": "",
"type": ""
}
],
"undoOperations": null
}
]
}
```
### 获取块 kramdown 源码
* `/api/block/getBlockKramdown`

0
changelogs/v2.8.4.md Normal file
View file

View file

View file

@ -29,6 +29,54 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func moveBlock(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
id := arg["id"].(string)
if util.InvalidIDPattern(id, ret) {
return
}
var parentID, previousID string
if nil != arg["parentID"] {
parentID = arg["parentID"].(string)
if util.InvalidIDPattern(parentID, ret) {
return
}
}
if nil != arg["previousID"] {
previousID = arg["previousID"].(string)
if util.InvalidIDPattern(previousID, ret) {
return
}
}
transactions := []*model.Transaction{
{
DoOperations: []*model.Operation{
{
Action: "move",
ID: id,
PreviousID: previousID,
ParentID: parentID,
},
},
},
}
model.PerformTransactions(&transactions)
model.WaitForWritingFiles()
ret.Data = transactions
broadcastTransactions(transactions)
}
func appendBlock(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -164,6 +164,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/block/appendBlock", model.CheckAuth, model.CheckReadonly, appendBlock)
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, model.CheckReadonly, updateBlock)
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, model.CheckReadonly, deleteBlock)
ginServer.Handle("POST", "/api/block/moveBlock", model.CheckAuth, model.CheckReadonly, moveBlock)
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, model.CheckReadonly, setBlockReminder)
ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction)
ginServer.Handle("POST", "/api/block/getHeadingDeleteTransaction", model.CheckAuth, getHeadingDeleteTransaction)