From a050f8928b84322951263a0235479ab7affe7039 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Mon, 11 May 2020 16:28:25 +0800 Subject: [PATCH] no message --- controller/file.go | 18 ++++++++++++++++++ utils/base.go | 5 +---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/controller/file.go b/controller/file.go index 70be41e..c69e772 100644 --- a/controller/file.go +++ b/controller/file.go @@ -97,6 +97,24 @@ func (this *FileController) FileType(c *gin.Context) { } func (this *FileController) DownloadFile(c *gin.Context) { + resp := RespBase{Msg:"FAIL",Status: 211} + filename := c.Query("filename") + file,e := os.Open( "files//" +filename) + if nil != e{ + log.Print(e.Error()) + c.JSON(200,resp) + return + } + bytes,e :=ioutil.ReadAll(file) + if nil != e{ + log.Print(e.Error()) + c.JSON(200,resp) + return + } + c.Header("X-Content-Type-Options", "nosniff") + c.Header("Content-Disposition", + "/files/" + filename) + c.Writer.Write(bytes) } diff --git a/utils/base.go b/utils/base.go index b21365f..0803444 100644 --- a/utils/base.go +++ b/utils/base.go @@ -3,7 +3,6 @@ package utils import ( "fmt" "io/ioutil" - "log" "os" "path/filepath" "strings" @@ -32,18 +31,16 @@ type FileDesc struct { 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() { childdir := new (FileDesc) childdir.Types = 1 childdir.Name = fi.Name() - GetPathFileName(pathname + "\\"+ fi.Name() + "\\",childdir) + GetPathFileName(pathname + fi.Name() + "\\",childdir) desc.Child = append(desc.Child,*childdir) } else { childdir := new (FileDesc)