This commit is contained in:
Liang Ding 2023-03-24 11:40:12 +08:00
parent 9b5c94c62e
commit 14eb29b26c
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 110 additions and 0 deletions

View file

@ -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)