From f8a671a5347d58d9de7eb6fc129ee59006bea2a4 Mon Sep 17 00:00:00 2001 From: Leonard <1679550318@qq.com> Date: Wed, 16 Mar 2022 18:41:47 +0800 Subject: [PATCH] =?UTF-8?q?fixed(api/v1/example/exa=5Fexcel.go):=20=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=A8=A1=E7=89=88=E5=A4=B1=E8=B4=A5=20(#916)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: yangping --- server/api/v1/example/exa_excel.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/api/v1/example/exa_excel.go b/server/api/v1/example/exa_excel.go index 8646a8b6..d6578487 100644 --- a/server/api/v1/example/exa_excel.go +++ b/server/api/v1/example/exa_excel.go @@ -1,10 +1,11 @@ package example import ( + "os" + "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/flipped-aurora/gin-vue-admin/server/model/example" - "github.com/flipped-aurora/gin-vue-admin/server/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) @@ -89,12 +90,18 @@ func (e *ExcelApi) LoadExcel(c *gin.Context) { func (e *ExcelApi) DownloadTemplate(c *gin.Context) { fileName := c.Query("fileName") filePath := global.GVA_CONFIG.Excel.Dir + fileName - ok, err := utils.PathExists(filePath) - if !ok || err != nil { + + fi, err := os.Stat(filePath) + if err != nil { global.GVA_LOG.Error("文件不存在!", zap.Error(err)) response.FailWithMessage("文件不存在", c) return } + if fi.IsDir() { + global.GVA_LOG.Error("不支持下载文件夹!", zap.Error(err)) + response.FailWithMessage("不支持下载文件夹", c) + return + } c.Writer.Header().Add("success", "true") c.File(filePath) } -- GitLab