no message

master
a7458969 2020-05-11 15:14:22 +08:00
parent 9f1536013d
commit 290049bb38
2 changed files with 31 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import (
"background/utils"
"github.com/disintegration/imaging"
"github.com/gin-gonic/gin"
json "github.com/json-iterator/go"
uuid "github.com/satori/go.uuid"
"image"
"image/color"
@ -75,11 +76,19 @@ func (this *FileController) OnUpload(c *gin.Context) {
}
func (this *FileController) FileList(c *gin.Context) {
var nodes utils.FileDesc
path := c.Query("path")
utils.GetPathFileName("files/" + path)
utils.GetPathFileName("files\\" + path,&nodes)
log.Print(nodes)
bs,e := json.Marshal(nodes)
if nil != e{
log.Print(e.Error())
}
log.Print(string(bs))
c.JSON(200,map[string]interface{}{
"msg":"ok",
"status":200,
"files":nodes,
})
}

View File

@ -3,6 +3,7 @@ package utils
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
@ -25,15 +26,30 @@ func GetCurrentDirectory() string {
return strings.Replace(dir, "\\", "/", -1)
}
func GetPathFileName(pathname string) (error) {
type FileDesc struct {
Child []FileDesc `json:"child"`
Types int32 `json:"types"`
Name string `json:"name"`
}
func GetPathFileName(pathname string,desc *FileDesc) (error) {
log.Print("call once")
desc.Name = pathname
desc.Child = make([]FileDesc,0)
desc.Types = 1 // 1 means fileholder
rd, err := ioutil.ReadDir(pathname)
for _, fi := range rd {
log.Print(fi.Name())
if fi.IsDir() {
fmt.Printf("[%s]\n", pathname+"\\"+fi.Name())
GetPathFileName(pathname + fi.Name() + "\\")
childdir := new (FileDesc)
childdir.Types = 1
childdir.Name = fi.Name()
GetPathFileName(pathname + "\\"+ fi.Name() + "\\",childdir)
desc.Child = append(desc.Child,*childdir)
} else {
fmt.Println(fi.Name())
childdir := new (FileDesc)
childdir.Types = 0
childdir.Name = fi.Name()
desc.Child = append(desc.Child,*childdir)
}
}
return err