Modify: use uri parameter in Get File

pull/247/head
HFO4 5 years ago
parent 2c2ee5b1c1
commit 0cbbe5bb79

@ -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))
}

@ -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)
}

@ -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)

@ -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)
}
// 目录

@ -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 文件下载

Loading…
Cancel
Save