diff --git a/middleware/session.go b/middleware/session.go index d5b1666..20568f8 100644 --- a/middleware/session.go +++ b/middleware/session.go @@ -10,17 +10,19 @@ import ( ) // Store session存储 -var Store redis.Store +var Store memstore.Store // Session 初始化session func Session(secret string) gin.HandlerFunc { // Redis设置不为空,且非测试模式时使用Redis - if conf.RedisConfig.Server != "" && gin.Mode() == gin.TestMode { + if conf.RedisConfig.Server != "" && gin.Mode() != gin.TestMode { var err error Store, err = redis.NewStoreWithDB(10, "tcp", conf.RedisConfig.Server, conf.RedisConfig.Password, conf.RedisConfig.DB, []byte(secret)) if err != nil { - util.Log().Panic("无法连接到Redis:%s", err) + util.Log().Panic("无法连接到 Redis:%s", err) } + + util.Log().Info("已连接到 Redis 服务器:%s", conf.RedisConfig.Server) } else { Store = memstore.NewStore([]byte(secret)) } diff --git a/pkg/util/session.go b/pkg/util/session.go index 44c5bde..ffc00e9 100644 --- a/pkg/util/session.go +++ b/pkg/util/session.go @@ -11,12 +11,17 @@ func SetSession(c *gin.Context, list map[string]interface{}) { for key, value := range list { s.Set(key, value) } - s.Save() + + err := s.Save() + if err != nil { + Log().Warning("无法设置 Session 值:%s", err) + } } // GetSession 获取session func GetSession(c *gin.Context, key string) interface{} { s := sessions.Default(c) + Log().Debug("Key:%s Val:%s", key, s.Get(key)) return s.Get(key) } diff --git a/routers/controllers/file.go b/routers/controllers/file.go index d304def..f0f9774 100644 --- a/routers/controllers/file.go +++ b/routers/controllers/file.go @@ -20,7 +20,7 @@ func Download(c *gin.Context) { defer cancel() var service explorer.FileDownloadService - if err := c.ShouldBindQuery(&service); err == nil { + if err := c.ShouldBindUri(&service); err == nil { res := service.Download(ctx, c) if res.Code != 0 { c.JSON(200, res) diff --git a/routers/router.go b/routers/router.go index c1d2211..795a987 100644 --- a/routers/router.go +++ b/routers/router.go @@ -21,7 +21,7 @@ func InitRouter() *gin.Engine { r.Use(cors.New(cors.Config{ AllowOrigins: []string{"http://localhost:3000"}, AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"}, - AllowHeaders: []string{"Content-Length", "Content-Type", "X-Path", "X-FileName"}, + AllowHeaders: []string{"Cookie", "Content-Length", "Content-Type", "X-Path", "X-FileName"}, AllowCredentials: true, })) @@ -63,7 +63,7 @@ func InitRouter() *gin.Engine { // 文件上传 file.POST("upload", controllers.FileUploadStream) // 下载文件 - file.GET("", controllers.Download) + file.GET("*path", controllers.Download) } // 目录 diff --git a/service/explorer/file.go b/service/explorer/file.go index 2af51eb..a154cbf 100644 --- a/service/explorer/file.go +++ b/service/explorer/file.go @@ -11,7 +11,7 @@ import ( // FileDownloadService 文件下载服务,path为文件完整路径 type FileDownloadService struct { - Path string `form:"path" binding:"required,min=1,max=65535"` + Path string `uri:"path" binding:"required,min=1,max=65535"` } // Download 文件下载