Skip to content

Commit

Permalink
🧑‍💻 Add a kernel API /api/filetree/renameDocByID #13105
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 11, 2024
1 parent 3922e48 commit 7b9163d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
27 changes: 26 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions API_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions kernel/api/filetree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions kernel/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7b9163d

Please sign in to comment.