mirror of https://github.com/cloudreve/Cloudreve
Modify: use uri parameter in Get File
parent
2c2ee5b1c1
commit
0cbbe5bb79
|
@ -10,17 +10,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Store session存储
|
// Store session存储
|
||||||
var Store redis.Store
|
var Store memstore.Store
|
||||||
|
|
||||||
// Session 初始化session
|
// Session 初始化session
|
||||||
func Session(secret string) gin.HandlerFunc {
|
func Session(secret string) gin.HandlerFunc {
|
||||||
// Redis设置不为空,且非测试模式时使用Redis
|
// Redis设置不为空,且非测试模式时使用Redis
|
||||||
if conf.RedisConfig.Server != "" && gin.Mode() == gin.TestMode {
|
if conf.RedisConfig.Server != "" && gin.Mode() != gin.TestMode {
|
||||||
var err error
|
var err error
|
||||||
Store, err = redis.NewStoreWithDB(10, "tcp", conf.RedisConfig.Server, conf.RedisConfig.Password, conf.RedisConfig.DB, []byte(secret))
|
Store, err = redis.NewStoreWithDB(10, "tcp", conf.RedisConfig.Server, conf.RedisConfig.Password, conf.RedisConfig.DB, []byte(secret))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.Log().Panic("无法连接到 Redis:%s", err)
|
util.Log().Panic("无法连接到 Redis:%s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util.Log().Info("已连接到 Redis 服务器:%s", conf.RedisConfig.Server)
|
||||||
} else {
|
} else {
|
||||||
Store = memstore.NewStore([]byte(secret))
|
Store = memstore.NewStore([]byte(secret))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,17 @@ func SetSession(c *gin.Context, list map[string]interface{}) {
|
||||||
for key, value := range list {
|
for key, value := range list {
|
||||||
s.Set(key, value)
|
s.Set(key, value)
|
||||||
}
|
}
|
||||||
s.Save()
|
|
||||||
|
err := s.Save()
|
||||||
|
if err != nil {
|
||||||
|
Log().Warning("无法设置 Session 值:%s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSession 获取session
|
// GetSession 获取session
|
||||||
func GetSession(c *gin.Context, key string) interface{} {
|
func GetSession(c *gin.Context, key string) interface{} {
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
|
Log().Debug("Key:%s Val:%s", key, s.Get(key))
|
||||||
return s.Get(key)
|
return s.Get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func Download(c *gin.Context) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var service explorer.FileDownloadService
|
var service explorer.FileDownloadService
|
||||||
if err := c.ShouldBindQuery(&service); err == nil {
|
if err := c.ShouldBindUri(&service); err == nil {
|
||||||
res := service.Download(ctx, c)
|
res := service.Download(ctx, c)
|
||||||
if res.Code != 0 {
|
if res.Code != 0 {
|
||||||
c.JSON(200, res)
|
c.JSON(200, res)
|
||||||
|
|
|
@ -21,7 +21,7 @@ func InitRouter() *gin.Engine {
|
||||||
r.Use(cors.New(cors.Config{
|
r.Use(cors.New(cors.Config{
|
||||||
AllowOrigins: []string{"http://localhost:3000"},
|
AllowOrigins: []string{"http://localhost:3000"},
|
||||||
AllowMethods: []string{"PUT", "POST", "GET", "OPTIONS"},
|
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,
|
AllowCredentials: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func InitRouter() *gin.Engine {
|
||||||
// 文件上传
|
// 文件上传
|
||||||
file.POST("upload", controllers.FileUploadStream)
|
file.POST("upload", controllers.FileUploadStream)
|
||||||
// 下载文件
|
// 下载文件
|
||||||
file.GET("", controllers.Download)
|
file.GET("*path", controllers.Download)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 目录
|
// 目录
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
// FileDownloadService 文件下载服务,path为文件完整路径
|
// FileDownloadService 文件下载服务,path为文件完整路径
|
||||||
type FileDownloadService struct {
|
type FileDownloadService struct {
|
||||||
Path string `form:"path" binding:"required,min=1,max=65535"`
|
Path string `uri:"path" binding:"required,min=1,max=65535"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download 文件下载
|
// Download 文件下载
|
||||||
|
|
Loading…
Reference in New Issue