🧑‍💻 Add a kernel API /api/filetree/getPathByID

* 🧑‍💻 Add a new api '/api/filetree/getPathByID'

* 🧑‍💻 Add a new api '/api/filetree/getPathByID'
This commit is contained in:
ytm157 2024-08-28 17:45:09 +08:00 committed by GitHub
parent b062d3f45f
commit 593e3141ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 76 additions and 0 deletions

22
API.md
View file

@ -462,6 +462,28 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
"data": "/foo/bar"
}
```
### Get storage path based on ID
* `/api/filetree/getPathByID`
* Parameters
```json
{
"id": "20210917220056-yxtyl7i"
}
```
* `id`: Block ID
* Return value
```json
{
"code": 0,
"msg": "",
"data": "/20210828150719-r8edxl2/20210917220056-yxtyl7i.sy"
}
```
### Get IDs based on human-readable path

View file

@ -462,6 +462,27 @@
}
```
### 根据 ID 获取存储路径
* `/api/filetree/getPathByID`
* 参数
```json
{
"id": "20210917220056-yxtyl7i"
}
```
* `id`:块 ID
* 返回值
```json
{
"code": 0,
"msg": "",
"data": "/20210828150719-r8edxl2/20210917220056-yxtyl7i.sy"
}
```
### 根据人类可读路径获取 IDs
* `/api/filetree/getIDsByHPath`

View file

@ -364,6 +364,29 @@ func getHPathByID(c *gin.Context) {
ret.Data = hPath
}
func getPathByID(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
}
_path, err := model.GetPathByID(id)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
return
}
ret.Data = _path
}
func getFullHPathByID(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -106,6 +106,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/filetree/getHPathByPath", model.CheckAuth, getHPathByPath)
ginServer.Handle("POST", "/api/filetree/getHPathsByPaths", model.CheckAuth, getHPathsByPaths)
ginServer.Handle("POST", "/api/filetree/getHPathByID", model.CheckAuth, getHPathByID)
ginServer.Handle("POST", "/api/filetree/getPathByID", model.CheckAuth, getPathByID)
ginServer.Handle("POST", "/api/filetree/getFullHPathByID", model.CheckAuth, getFullHPathByID)
ginServer.Handle("POST", "/api/filetree/getIDsByHPath", model.CheckAuth, getIDsByHPath)
ginServer.Handle("POST", "/api/filetree/doc2Heading", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, doc2Heading)

View file

@ -1327,6 +1327,15 @@ func GetHPathByID(id string) (hPath string, err error) {
return
}
func GetPathByID(id string) (hPath string, err error) {
tree, err := LoadTreeByBlockID(id)
if nil != err {
return
}
hPath = tree.Path
return
}
func GetFullHPathByID(id string) (hPath string, err error) {
tree, err := LoadTreeByBlockID(id)
if nil != err {