mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 07:30:49 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
986166ff8b
30
API.md
30
API.md
@ -39,6 +39,7 @@
|
|||||||
* [Get file](#Get-file)
|
* [Get file](#Get-file)
|
||||||
* [Put file](#Put-file)
|
* [Put file](#Put-file)
|
||||||
* [Remove file](#Remove-file)
|
* [Remove file](#Remove-file)
|
||||||
|
* [List files](#List-files)
|
||||||
* [Export](#Export)
|
* [Export](#Export)
|
||||||
* [Export Markdown](#Export-Markdown)
|
* [Export Markdown](#Export-Markdown)
|
||||||
* [Notification](#Notification)
|
* [Notification](#Notification)
|
||||||
@ -886,6 +887,35 @@ View API token in <kbd>Settings - About</kbd>, request header: `Authorization: T
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### List files
|
||||||
|
|
||||||
|
* `/api/file/readDir`
|
||||||
|
* Parameters
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"path": "/data/20210808180117-6v0mkxr/20200923234011-ieuun1p.sy"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* `path`: the file path under the workspace path
|
||||||
|
* Return value
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"isDir": true,
|
||||||
|
"name": "20210808180320-abz7w6k"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isDir": false,
|
||||||
|
"name": "20210808180320-abz7w6k.sy"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Export
|
## Export
|
||||||
|
|
||||||
|
31
API_zh_CN.md
31
API_zh_CN.md
@ -39,6 +39,7 @@
|
|||||||
* [获取文件](#获取文件)
|
* [获取文件](#获取文件)
|
||||||
* [写入文件](#写入文件)
|
* [写入文件](#写入文件)
|
||||||
* [删除文件](#删除文件)
|
* [删除文件](#删除文件)
|
||||||
|
* [列出文件](#列出文件)
|
||||||
* [导出](#导出)
|
* [导出](#导出)
|
||||||
* [导出 Markdown 文本](#导出-markdown-文本)
|
* [导出 Markdown 文本](#导出-markdown-文本)
|
||||||
* [通知](#通知)
|
* [通知](#通知)
|
||||||
@ -880,6 +881,36 @@
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 列出文件
|
||||||
|
|
||||||
|
* `/api/file/readDir`
|
||||||
|
* 参数
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"path": "/data/20210808180117-6v0mkxr/20200923234011-ieuun1p.sy"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* `path`:工作空间路径下的文件路径
|
||||||
|
* 返回值
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"msg": "",
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"isDir": true,
|
||||||
|
"name": "20210808180320-abz7w6k"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"isDir": false,
|
||||||
|
"name": "20210808180320-abz7w6k.sy"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 导出
|
## 导出
|
||||||
|
|
||||||
### 导出 Markdown 文本
|
### 导出 Markdown 文本
|
||||||
|
@ -110,8 +110,56 @@ func getFile(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readDir(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
c.JSON(http.StatusOK, ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dirPath := arg["path"].(string)
|
||||||
|
dirPath = filepath.Join(util.WorkspaceDir, dirPath)
|
||||||
|
info, err := os.Stat(dirPath)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
c.Status(404)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("stat [%s] failed: %s", dirPath, err)
|
||||||
|
c.Status(500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
logging.LogErrorf("file [%s] is not a directory", dirPath)
|
||||||
|
c.Status(405)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(dirPath)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("read dir [%s] failed: %s", dirPath, err)
|
||||||
|
c.Status(500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
files := []map[string]interface{}{}
|
||||||
|
for _, entry := range entries {
|
||||||
|
files = append(files, map[string]interface{}{
|
||||||
|
"name": entry.Name(),
|
||||||
|
"isDir": entry.IsDir(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Data = files
|
||||||
|
}
|
||||||
|
|
||||||
func removeFile(c *gin.Context) {
|
func removeFile(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
arg, ok := util.JsonArg(c, ret)
|
arg, ok := util.JsonArg(c, ret)
|
||||||
if !ok {
|
if !ok {
|
||||||
c.JSON(http.StatusOK, ret)
|
c.JSON(http.StatusOK, ret)
|
||||||
|
@ -176,6 +176,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, model.CheckReadonly, putFile)
|
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, model.CheckReadonly, putFile)
|
||||||
ginServer.Handle("POST", "/api/file/copyFile", model.CheckAuth, model.CheckReadonly, copyFile)
|
ginServer.Handle("POST", "/api/file/copyFile", model.CheckAuth, model.CheckReadonly, copyFile)
|
||||||
ginServer.Handle("POST", "/api/file/removeFile", model.CheckAuth, model.CheckReadonly, removeFile)
|
ginServer.Handle("POST", "/api/file/removeFile", model.CheckAuth, model.CheckReadonly, removeFile)
|
||||||
|
ginServer.Handle("POST", "/api/file/readDir", model.CheckAuth, model.CheckReadonly, readDir)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/ref/refreshBacklink", model.CheckAuth, refreshBacklink)
|
ginServer.Handle("POST", "/api/ref/refreshBacklink", model.CheckAuth, refreshBacklink)
|
||||||
ginServer.Handle("POST", "/api/ref/getBacklink", model.CheckAuth, getBacklink)
|
ginServer.Handle("POST", "/api/ref/getBacklink", model.CheckAuth, getBacklink)
|
||||||
|
Loading…
Reference in New Issue
Block a user