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" "background/utils"
"github.com/disintegration/imaging" "github.com/disintegration/imaging"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
json "github.com/json-iterator/go"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"image" "image"
"image/color" "image/color"
@ -75,11 +76,19 @@ func (this *FileController) OnUpload(c *gin.Context) {
} }
func (this *FileController) FileList(c *gin.Context) { func (this *FileController) FileList(c *gin.Context) {
var nodes utils.FileDesc
path := c.Query("path") 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{}{ c.JSON(200,map[string]interface{}{
"msg":"ok", "msg":"ok",
"status":200, "status":200,
"files":nodes,
}) })
} }

View File

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