mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: file compress / download
This commit is contained in:
@@ -137,6 +137,25 @@ func Thumb(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// RedirectToDownload 创建下载会话并重定向至下载地址
|
||||
func RedirectToDownload(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
var service explorer.FileDownloadCreateService
|
||||
if err := c.ShouldBindUri(&service); err == nil {
|
||||
res := service.CreateDownloadSession(ctx, c)
|
||||
if res.Code == 0 {
|
||||
c.Redirect(301, res.Data.(string))
|
||||
return
|
||||
}
|
||||
c.JSON(200, res)
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
}
|
||||
|
||||
// CreateDownloadSession 创建文件下载会话
|
||||
func CreateDownloadSession(c *gin.Context) {
|
||||
// 创建上下文
|
||||
|
||||
@@ -106,6 +106,8 @@ func InitRouter() *gin.Engine {
|
||||
file.POST("upload", controllers.FileUploadStream)
|
||||
// 创建文件下载会话
|
||||
file.PUT("download/*path", controllers.CreateDownloadSession)
|
||||
// 创建文件下载并重定向到下载地址
|
||||
file.GET("redirect/*path", controllers.RedirectToDownload)
|
||||
// 获取缩略图
|
||||
file.GET("thumb/:id", controllers.Thumb)
|
||||
// 取得文件外链
|
||||
|
||||
Reference in New Issue
Block a user