Fix traffic computation and optimize open ended requests

This commit is contained in:
Ben Adrian Sarmiento
2024-07-04 03:39:53 +02:00
parent 6deeb45db0
commit 49432dd810
5 changed files with 100 additions and 106 deletions

View File

@@ -70,6 +70,10 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
tokenMap, _ := rd.UnrestrictMap.Get(token)
if tokenMap.Has(link) {
download, _ := tokenMap.Get(link)
if !rd.cfg.ShouldServeFromRclone() {
return download, nil
}
// check if the link is in the verified links cache
if expiry, ok := rd.verifiedLinks.Get(download.ID); ok && expiry > time.Now().Unix() {
return download, nil
@@ -98,17 +102,19 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
tokenMap.Set(link, download)
err = rd.downloadClient.VerifyLink(download.Download)
if utils.IsBytesLimitReached(err) {
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
continue
} else if utils.IsInvalidDownloadCode(err) {
continue
} else if err != nil {
return nil, err
}
if rd.cfg.ShouldServeFromRclone() {
err = rd.downloadClient.VerifyLink(download.Download)
if utils.IsBytesLimitReached(err) {
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
continue
} else if utils.IsInvalidDownloadCode(err) {
continue
} else if err != nil {
return nil, err
}
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
}
return download, err
}