net: 支持1并发 分片下载

This commit is contained in:
j2rong4cn
2025-06-29 21:48:46 +08:00
parent b3d6da9e4f
commit 1462063708
3 changed files with 3 additions and 3 deletions

View File

@ -171,7 +171,7 @@ func (d *downloader) download() (io.ReadCloser, error) {
log.Debugf("cfgConcurrency:%d", d.cfg.Concurrency)
if d.cfg.Concurrency == 1 {
if maxPart == 1 {
if d.cfg.ConcurrencyLimit != nil {
go func() {
<-d.ctx.Done()

View File

@ -19,7 +19,7 @@ func GetRangeReadCloserFromLink(size int64, link *model.Link) (model.RangeReadCl
return nil, fmt.Errorf("can't create RangeReadCloser since URL is empty in link")
}
rangeReaderFunc := func(ctx context.Context, r http_range.Range) (io.ReadCloser, error) {
if link.Concurrency != 0 || link.PartSize != 0 {
if link.Concurrency > 0 || link.PartSize > 0 {
header := net.ProcessHeader(nil, link.Header)
down := net.NewDownloader(func(d *net.Downloader) {
d.Concurrency = link.Concurrency

View File

@ -41,7 +41,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
RangeReadCloserIF: link.RangeReadCloser,
Limiter: stream.ServerDownloadLimit,
})
} else if link.Concurrency != 0 || link.PartSize != 0 {
} else if link.Concurrency > 0 || link.PartSize > 0 {
attachHeader(w, file)
size := file.GetSize()
rangeReader := func(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error) {