mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
🎨 提供列出文件 API Fix https://github.com/siyuan-note/siyuan/issues/7765
This commit is contained in:
parent
9b5c94c62e
commit
14eb29b26c
4 changed files with 110 additions and 0 deletions
|
|
@ -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) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue