mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
Feat: download temporary archive file
This commit is contained in:
@@ -17,7 +17,23 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ArchiveAndDownload(c *gin.Context) {
|
||||
func DownloadArchive(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
var service explorer.ArchiveDownloadService
|
||||
if err := c.ShouldBindUri(&service); err == nil {
|
||||
res := service.Download(ctx, c)
|
||||
if res.Code != 0 {
|
||||
c.JSON(200, res)
|
||||
}
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
}
|
||||
|
||||
func Archive(c *gin.Context) {
|
||||
// 创建上下文
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -67,6 +67,7 @@ func InitRouter() *gin.Engine {
|
||||
{
|
||||
file := sign.Group("file")
|
||||
{
|
||||
// 下載文件
|
||||
file.GET("get/:id/:name", controllers.AnonymousGetContent)
|
||||
}
|
||||
}
|
||||
@@ -101,8 +102,10 @@ func InitRouter() *gin.Engine {
|
||||
file.GET("thumb/:id", controllers.Thumb)
|
||||
// 取得文件外链
|
||||
file.GET("source/:id", controllers.GetSource)
|
||||
// 测试用:压缩文件和目录并下載
|
||||
file.POST("archive", controllers.ArchiveAndDownload)
|
||||
// 打包要下载的文件
|
||||
file.POST("archive", controllers.Archive)
|
||||
// 下載已经打包好的文件
|
||||
file.Use(middleware.SignRequired()).GET("archive/:id", controllers.DownloadArchive)
|
||||
}
|
||||
|
||||
// 目录
|
||||
|
||||
Reference in New Issue
Block a user