Rename variables for easy reference

This commit is contained in:
Ben Adrian Sarmiento
2024-07-21 02:11:32 +02:00
parent 47751320f7
commit f8b9f8955b
8 changed files with 46 additions and 33 deletions

View File

@@ -84,9 +84,11 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
if expiry, ok := rd.verifiedLinks.Get(download.ID); ok && expiry > time.Now().Unix() {
return download, nil
} else if ok {
// if the link is expired, remove it from the verified links cache
rd.verifiedLinks.Remove(download.ID)
}
// check if the link is still valid (not in the cache or expired)
err := rd.downloadClient.VerifyLink(download.Download)
if utils.IsBytesLimitReached(err) {
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
@@ -95,6 +97,7 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
return download, nil
}
// if verification failed, remove the link from the token map
tokenMap.Remove(link)
}
@@ -419,8 +422,10 @@ func (rd *RealDebrid) DownloadFile(req *http.Request) (*http.Response, error) {
// MonitorExpiredTokens is a permanent job for monitoring expired tokens if they are still expired
func (rd *RealDebrid) MonitorExpiredTokens() {
sleepPeriod := 1 * time.Minute
i := 0
rd.workerPool.Submit(func() {
for {
i++
expiredTokens := rd.TokenManager.GetExpiredTokens()
for _, token := range expiredTokens {
tokenMap, _ := rd.UnrestrictMap.Get(token)
@@ -432,7 +437,12 @@ func (rd *RealDebrid) MonitorExpiredTokens() {
}
err := rd.downloadClient.VerifyLink(download.Download)
if err != nil {
skipAll = utils.IsBytesLimitReached(err)
if utils.IsBytesLimitReached(err) {
if i%15 == 0 {
rd.log.Debugf("Token %s is still expired", utils.MaskToken(token))
}
skipAll = true
}
return
}
stillExpired = false