thinking about timeout

This commit is contained in:
Ben Sarmiento
2024-01-27 23:53:22 +01:00
parent ce4b794098
commit 2502e5473f
3 changed files with 17 additions and 14 deletions

View File

@@ -14,11 +14,15 @@ import (
)
type Downloader struct {
client *zurghttp.HTTPClient
client *zurghttp.HTTPClient
timeoutSecs int
}
func NewDownloader(client *zurghttp.HTTPClient) *Downloader {
return &Downloader{client: client}
func NewDownloader(client *zurghttp.HTTPClient, timeoutSecs int) *Downloader {
return &Downloader{
client: client,
timeoutSecs: timeoutSecs,
}
}
// DownloadFile handles a GET request for files in torrents
@@ -162,7 +166,12 @@ 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 {