Do not repair invalid download code error

This commit is contained in:
Ben Adrian Sarmiento
2024-07-01 03:37:04 +02:00
parent 99ca9d2602
commit b5fa74bd69
3 changed files with 17 additions and 6 deletions

View File

@@ -171,8 +171,10 @@ func (dl *Downloader) streamFileToResponse(
// log.Errorf("Your account has reached the bandwidth limit, please try again after 12AM CET") // log.Errorf("Your account has reached the bandwidth limit, please try again after 12AM CET")
http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusBadRequest) http.Error(resp, "File is not available (bandwidth limit reached)", http.StatusBadRequest)
return return
} } else if utils.IsInvalidDownloadCode(err) {
if err != nil { http.Error(resp, "File is not available (invalid download code)", http.StatusInternalServerError)
return
} else if err != nil {
log.Errorf("Cannot download file %s: %v", unrestrict.Download, err) log.Errorf("Cannot download file %s: %v", unrestrict.Download, err)
if file != nil && file.State.Event(context.Background(), "break_file") == nil { if file != nil && file.State.Event(context.Background(), "break_file") == nil {
torMgr.EnqueueForRepair(torrent) torMgr.EnqueueForRepair(torrent)

View File

@@ -81,8 +81,9 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
if utils.IsBytesLimitReached(err) { if utils.IsBytesLimitReached(err) {
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded") rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
continue continue
} } else if utils.IsInvalidDownloadCode(err) {
if err == nil { continue
} else if err == nil {
rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY) rd.verifiedLinks.Set(download.ID, time.Now().Unix()+DOWNLOAD_LINK_EXPIRY)
return download, nil return download, nil
} }
@@ -101,8 +102,9 @@ func (rd *RealDebrid) UnrestrictAndVerify(link string) (*Download, error) {
if utils.IsBytesLimitReached(err) { if utils.IsBytesLimitReached(err) {
rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded") rd.TokenManager.SetTokenAsExpired(token, "bandwidth limit exceeded")
continue continue
} } else if utils.IsInvalidDownloadCode(err) {
if err != nil { continue
} else if err != nil {
return nil, err return nil, err
} }

View File

@@ -9,6 +9,13 @@ func IsBytesLimitReached(err error) bool {
return false return false
} }
func IsInvalidDownloadCode(err error) bool {
if dlErr, ok := err.(*http.DownloadErrorResponse); ok && dlErr.Message == "invalid_download_code" {
return true
}
return false
}
func AreAllTokensExpired(err error) bool { func AreAllTokensExpired(err error) bool {
return err != nil && err.Error() == "all tokens are expired" return err != nil && err.Error() == "all tokens are expired"
} }