mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 01:00:46 +08:00
🧑💻 Add a kernel API /api/filetree/renameDocByID
https://github.com/siyuan-note/siyuan/issues/13105
This commit is contained in:
parent
3922e48404
commit
7b9163d480
27
API.md
27
API.md
@ -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
|
||||
|
25
API_zh_CN.md
25
API_zh_CN.md
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user