mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Modify: close file in main routine
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/HFO4/cloudreve/pkg/filesystem/fsctx"
|
||||
"github.com/HFO4/cloudreve/pkg/serializer"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -41,6 +42,11 @@ func (service *FileAnonymousGetService) Download(ctx context.Context, c *gin.Con
|
||||
// 发送文件
|
||||
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{
|
||||
Code: 0,
|
||||
}
|
||||
@@ -66,6 +72,11 @@ func (service *FileDownloadService) Download(ctx context.Context, c *gin.Context
|
||||
// 发送文件
|
||||
http.ServeContent(c.Writer, c.Request, "", fs.FileTarget[0].UpdatedAt, rs)
|
||||
|
||||
// 检查是否需要关闭文件
|
||||
if fc, ok := rs.(io.Closer); ok {
|
||||
defer fc.Close()
|
||||
}
|
||||
|
||||
return serializer.Response{
|
||||
Code: 0,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user