🧑‍💻 Add a kernel API /api/filetree/renameDocByID https://github.com/siyuan-note/siyuan/issues/13105

This commit is contained in:
Daniel 2024-11-11 11:37:42 +08:00
parent 3922e48404
commit 7b9163d480
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
4 changed files with 83 additions and 1 deletions

27
API.md
View File

@ -351,12 +351,37 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
{
"notebook": "20210831090520-7dvbdv0",
"path": "/20210902210113-0avi12f.sy",
"title": "Document new title"
"title": "New document title"
}
```
* `notebook`: Notebook ID
* `path`: Document path
* `title`: New document title
* Return value
```json
{
"code": 0,
"msg": "",
"data": null
}
```
Rename a document by `id`:
* `/api/filetree/renameDocByID`
* Parameters
```json
{
"id": "20210902210113-0avi12f",
"title": "New document title"
}
```
* `id`: Document ID
* `title`: New document title
* Return value
```json

View File

@ -357,6 +357,31 @@
* `notebook`:笔记本 ID
* `path`:文档路径
* `title`:新标题
* 返回值
```json
{
"code": 0,
"msg": "",
"data": null
}
```
通过 `id` 重命名文档:
* `/api/filetree/renameDocByID`
* 参数
```json
{
"id": "20210902210113-0avi12f",
"title": "文档新标题"
}
```
* `id`:文档 ID
* `title`:新标题
* 返回值
```json

View File

@ -531,6 +531,37 @@ func renameDoc(c *gin.Context) {
return
}
func renameDocByID(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
if nil == arg["id"] {
return
}
id := arg["id"].(string)
title := arg["title"].(string)
tree, err := model.LoadTreeByBlockID(id)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
ret.Data = map[string]interface{}{"closeTimeout": 7000}
return
}
err = model.RenameDoc(tree.Box, tree.Path, title)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
return
}
}
func duplicateDoc(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View File

@ -103,6 +103,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/filetree/createDailyNote", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, createDailyNote)
ginServer.Handle("POST", "/api/filetree/createDoc", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, createDoc)
ginServer.Handle("POST", "/api/filetree/renameDoc", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, renameDoc)
ginServer.Handle("POST", "/api/filetree/renameDocByID", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, renameDocByID)
ginServer.Handle("POST", "/api/filetree/removeDoc", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, removeDoc)
ginServer.Handle("POST", "/api/filetree/removeDocs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, removeDocs)
ginServer.Handle("POST", "/api/filetree/moveDocs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, moveDocs)