its the fastest ever

This commit is contained in:
Ben Sarmiento
2024-01-28 02:23:19 +01:00
parent abdc8fcbb0
commit f07b65d5da
7 changed files with 70 additions and 66 deletions

View File

@@ -14,14 +14,12 @@ import (
)
type Downloader struct {
client *zurghttp.HTTPClient
timeoutSecs int
client *zurghttp.HTTPClient
}
func NewDownloader(client *zurghttp.HTTPClient, timeoutSecs int) *Downloader {
func NewDownloader(client *zurghttp.HTTPClient) *Downloader {
return &Downloader{
client: client,
timeoutSecs: timeoutSecs,
client: client,
}
}
@@ -157,7 +155,6 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
if req.Header.Get("Range") != "" {
dlReq.Header.Add("Range", req.Header.Get("Range"))
rangeLog = " (range: " + req.Header.Get("Range") + ")"
}
if torrent != nil {
@@ -166,12 +163,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
log.Debugf("Downloading unrestricted link %s (%s)%s", unrestrict.Download, unrestrict.Link, rangeLog)
}
// timeout := time.Duration(dl.timeoutSecs) * time.Second
// ctx, cancel := context.WithTimeout(context.TODO(), timeout)
// dlReq = dlReq.WithContext(ctx)
download, err := dl.client.Do(dlReq)
if err != nil {
log.Warnf("Cannot download file %s: %v", unrestrict.Download, err)
if file != nil && unrestrict.Streamable == 1 {
@@ -185,7 +177,6 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor
http.Error(resp, "File is not available", http.StatusNotFound)
return
}
defer download.Body.Close()
if download.StatusCode/100 != 2 {