🐛 fix ftp download error

This commit is contained in:
微凉
2022-01-13 22:56:07 +08:00
parent b472c2ee18
commit 424ec10692
3 changed files with 33 additions and 10 deletions

View File

@ -11,8 +11,10 @@ import (
log "github.com/sirupsen/logrus"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
)
func Proxy(c *gin.Context) {
@ -47,6 +49,12 @@ func Proxy(c *gin.Context) {
c.Redirect(302, link)
return
}
// 检查文件
file, err := driver.File(path, account)
if err != nil {
common.ErrorResp(c, err, 500)
return
}
// 对于中转不需要重设IP
link, err := driver.Link(base.Args{Path: path}, account)
if err != nil {
@ -60,7 +68,9 @@ func Proxy(c *gin.Context) {
_ = link.Data.Close()
}()
c.Status(http.StatusOK)
c.Header("content", "application/octet-stream")
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename=%s`, url.QueryEscape(file.Name)))
c.Header("Content-Length", strconv.FormatInt(file.Size, 10))
_, err = io.Copy(c.Writer, link.Data)
if err != nil {
_, _ = c.Writer.WriteString(err.Error())