feat: add proxy_range option for 139Yun Alias AList V3 (#6496)

This commit is contained in:
j2rong4cn
2024-05-22 23:31:42 +08:00
committed by GitHub
parent 7013d1b7b8
commit 5f60b51cf8
10 changed files with 62 additions and 14 deletions

View File

@ -9,8 +9,10 @@ import (
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/net"
"github.com/alist-org/alist/v3/internal/stream"
"github.com/alist-org/alist/v3/pkg/http_range"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
)
func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.Obj) error {
@ -82,3 +84,21 @@ func attachFileName(w http.ResponseWriter, file model.Obj) {
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, fileName, url.PathEscape(fileName)))
w.Header().Set("Content-Type", utils.GetMimeType(fileName))
}
var NoProxyRange = &model.RangeReadCloser{}
func ProxyRange(link *model.Link, size int64) {
if link.MFile != nil {
return
}
if link.RangeReadCloser == nil {
var rrc, err = stream.GetRangeReadCloserFromLink(size, link)
if err != nil {
log.Warnf("ProxyRange error: %s", err)
return
}
link.RangeReadCloser = rrc
} else if link.RangeReadCloser == NoProxyRange {
link.RangeReadCloser = nil
}
}