Catch bw limit errors and prevent repair loops
This commit is contained in:
@@ -293,19 +293,22 @@ func backoffFunc(attempt int) time.Duration {
|
||||
return time.Duration(backoff) * time.Second
|
||||
}
|
||||
|
||||
func (r *HTTPClient) VerifyURL(url string) bool {
|
||||
func (r *HTTPClient) VerifyURL(url string) error {
|
||||
req, err := http.NewRequest(http.MethodHead, url, nil)
|
||||
if err != nil {
|
||||
return false
|
||||
return err
|
||||
}
|
||||
timeout := time.Duration(r.timeoutSecs) * time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
req = req.WithContext(ctx)
|
||||
resp, _ := r.Do(req)
|
||||
if resp != nil {
|
||||
defer resp.Body.Close()
|
||||
return resp.StatusCode == http.StatusOK
|
||||
resp, err := r.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return false
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -113,8 +113,11 @@ func (rd *RealDebrid) UnrestrictLink(link string, verifyDownloadURL bool) (*Down
|
||||
}
|
||||
|
||||
// will only check for first byte if serving from rclone
|
||||
if verifyDownloadURL && !rd.downloadClient.VerifyURL(response.Download) {
|
||||
return nil, fmt.Errorf("download URL verification failed: %s", response.Download)
|
||||
if verifyDownloadURL {
|
||||
err := rd.downloadClient.VerifyURL(response.Download)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// rd.log.Debugf("Unrestricted link %s into %s", link, response.Download)
|
||||
|
||||
Reference in New Issue
Block a user