Feat: download file and get file downloading session

This commit is contained in:
HFO4
2019-12-13 20:46:11 +08:00
parent ad02a659a6
commit f262caf1f5
10 changed files with 150 additions and 18 deletions

View File

@@ -22,9 +22,9 @@ func DownloadArchive(c *gin.Context) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.ArchiveDownloadService
var service explorer.DownloadService
if err := c.ShouldBindUri(&service); err == nil {
res := service.Download(ctx, c)
res := service.DownloadArchived(ctx, c)
if res.Code != 0 {
c.JSON(200, res)
}
@@ -137,13 +137,28 @@ func Thumb(c *gin.Context) {
}
// Download 文件下载
// CreateDownloadSession 创建文件下载会话
func CreateDownloadSession(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)
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}
// DownloadArchived 文件下载
func Download(c *gin.Context) {
// 创建上下文
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var service explorer.FileDownloadService
var service explorer.DownloadService
if err := c.ShouldBindUri(&service); err == nil {
res := service.Download(ctx, c)
if res.Code != 0 {

View File

@@ -75,6 +75,8 @@ func InitRouter() *gin.Engine {
file.GET("get/:id/:name", controllers.AnonymousGetContent)
// 下載已经打包好的文件
file.GET("archive/:id/archive.zip", controllers.DownloadArchive)
// 下载文件
file.GET("download/:id", controllers.Download)
}
}
@@ -102,9 +104,9 @@ func InitRouter() *gin.Engine {
{
// 文件上传
file.POST("upload", controllers.FileUploadStream)
// 下载文件
file.GET("download/*path", controllers.Download)
// 下载文件
// 创建文件下载会话
file.PUT("download/*path", controllers.CreateDownloadSession)
// 获取缩略图
file.GET("thumb/:id", controllers.Thumb)
// 取得文件外链
file.GET("source/:id", controllers.GetSource)