|
|
@ -8,7 +8,6 @@ import (
|
|
|
|
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
|
|
|
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
|
|
|
"github.com/HFO4/cloudreve/pkg/serializer"
|
|
|
|
"github.com/HFO4/cloudreve/pkg/serializer"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -45,6 +44,7 @@ func (service *DownloadService) DownloadArchived(ctx context.Context, c *gin.Con
|
|
|
|
|
|
|
|
|
|
|
|
// 获取文件流
|
|
|
|
// 获取文件流
|
|
|
|
rs, err := fs.GetPhysicalFileContent(ctx, zipPath.(string))
|
|
|
|
rs, err := fs.GetPhysicalFileContent(ctx, zipPath.(string))
|
|
|
|
|
|
|
|
defer rs.Close()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -58,11 +58,6 @@ func (service *DownloadService) DownloadArchived(ctx context.Context, c *gin.Con
|
|
|
|
c.Header("Content-Type", "application/zip")
|
|
|
|
c.Header("Content-Type", "application/zip")
|
|
|
|
http.ServeContent(c.Writer, c.Request, "", time.Now(), rs)
|
|
|
|
http.ServeContent(c.Writer, c.Request, "", time.Now(), rs)
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否需要关闭文件
|
|
|
|
|
|
|
|
if fc, ok := rs.(io.Closer); ok {
|
|
|
|
|
|
|
|
err = fc.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return serializer.Response{
|
|
|
|
return serializer.Response{
|
|
|
|
Code: 0,
|
|
|
|
Code: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -84,6 +79,7 @@ func (service *FileAnonymousGetService) Download(ctx context.Context, c *gin.Con
|
|
|
|
|
|
|
|
|
|
|
|
// 获取文件流
|
|
|
|
// 获取文件流
|
|
|
|
rs, err := fs.GetDownloadContent(ctx, "")
|
|
|
|
rs, err := fs.GetDownloadContent(ctx, "")
|
|
|
|
|
|
|
|
defer rs.Close()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -91,11 +87,6 @@ func (service *FileAnonymousGetService) Download(ctx context.Context, c *gin.Con
|
|
|
|
// 发送文件
|
|
|
|
// 发送文件
|
|
|
|
http.ServeContent(c.Writer, c.Request, service.Name, fs.FileTarget[0].UpdatedAt, rs)
|
|
|
|
http.ServeContent(c.Writer, c.Request, service.Name, fs.FileTarget[0].UpdatedAt, rs)
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否需要关闭文件
|
|
|
|
|
|
|
|
if fc, ok := rs.(io.Closer); ok {
|
|
|
|
|
|
|
|
defer fc.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return serializer.Response{
|
|
|
|
return serializer.Response{
|
|
|
|
Code: 0,
|
|
|
|
Code: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -139,6 +130,7 @@ func (service *DownloadService) Download(ctx context.Context, c *gin.Context) se
|
|
|
|
// 开始处理下载
|
|
|
|
// 开始处理下载
|
|
|
|
ctx = context.WithValue(ctx, fsctx.GinCtx, c)
|
|
|
|
ctx = context.WithValue(ctx, fsctx.GinCtx, c)
|
|
|
|
rs, err := fs.GetDownloadContent(ctx, "")
|
|
|
|
rs, err := fs.GetDownloadContent(ctx, "")
|
|
|
|
|
|
|
|
defer rs.Close()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -154,11 +146,6 @@ func (service *DownloadService) Download(ctx context.Context, c *gin.Context) se
|
|
|
|
// 发送文件
|
|
|
|
// 发送文件
|
|
|
|
http.ServeContent(c.Writer, c.Request, "", fs.FileTarget[0].UpdatedAt, rs)
|
|
|
|
http.ServeContent(c.Writer, c.Request, "", fs.FileTarget[0].UpdatedAt, rs)
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否需要关闭文件
|
|
|
|
|
|
|
|
if fc, ok := rs.(io.Closer); ok {
|
|
|
|
|
|
|
|
defer fc.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return serializer.Response{
|
|
|
|
return serializer.Response{
|
|
|
|
Code: 0,
|
|
|
|
Code: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|