Feat: batch download in streamming paradism

Fix: add cache-controler header in API call responses
This commit is contained in:
HFO4
2022-04-13 17:53:46 +08:00
parent 32a655f84e
commit febbd0c5a0
11 changed files with 98 additions and 97 deletions

View File

@@ -18,12 +18,9 @@ func DownloadArchive(c *gin.Context) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.DownloadService
var service explorer.ArchiveService
if err := c.ShouldBindUri(&service); err == nil {
res := service.DownloadArchived(ctx, c)
if res.Code != 0 {
c.JSON(200, res)
}
service.DownloadArchived(ctx, c)
} else {
c.JSON(200, ErrorResponse(err))
}
@@ -189,7 +186,7 @@ func Preview(c *gin.Context) {
res := service.PreviewContent(ctx, c, false)
// 是否需要重定向
if res.Code == -301 {
c.Redirect(301, res.Data.(string))
c.Redirect(302, res.Data.(string))
return
}
// 是否有错误发生

View File

@@ -100,7 +100,7 @@ func PreviewShare(c *gin.Context) {
res := service.PreviewContent(ctx, c, false)
// 是否需要重定向
if res.Code == -301 {
c.Redirect(301, res.Data.(string))
c.Redirect(302, res.Data.(string))
return
}
// 是否有错误发生

View File

@@ -34,6 +34,8 @@ func InitSlaveRouter() *gin.Engine {
v3.Use(middleware.SignRequired(auth.General))
// 主机信息解析
v3.Use(middleware.MasterMetadata())
// 禁止缓存
v3.Use(middleware.CacheControl())
/*
路由
@@ -133,8 +135,12 @@ func InitMasterRouter() *gin.Engine {
if gin.Mode() == gin.TestMode {
v3.Use(middleware.MockHelper())
}
// 用户会话
v3.Use(middleware.CurrentUser())
// 禁止缓存
v3.Use(middleware.CacheControl())
/*
路由
*/
@@ -205,10 +211,10 @@ func InitMasterRouter() *gin.Engine {
file.GET("get/:id/:name", controllers.AnonymousGetContent)
// 文件外链(301跳转)
file.GET("source/:id/:name", controllers.AnonymousPermLink)
// 下載已经打包好的文件
file.GET("archive/:id/archive.zip", controllers.DownloadArchive)
// 下载文件
file.GET("download/:id", controllers.Download)
// 打包并下载文件
file.GET("archive/:sessionID/archive.zip", controllers.DownloadArchive)
}
}