Add token management

This commit is contained in:
Ben Adrian Sarmiento
2024-06-28 13:19:09 +02:00
parent 962845fb81
commit c3aea427d0
9 changed files with 100 additions and 114 deletions

View File

@@ -9,7 +9,6 @@ import (
"time"
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/pkg/http"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
"github.com/debridmediamanager/zurg/pkg/utils"
mapset "github.com/deckarep/golang-set/v2"
@@ -197,7 +196,7 @@ func (t *TorrentManager) repair(torrent *Torrent, wg *sync.WaitGroup) {
return
}
_, err := t.UnrestrictFile(file)
if dlErr, ok := err.(*http.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
if utils.IsBWLimitExceeded(err) {
bwLimitReached = true
return
}
@@ -253,7 +252,7 @@ func (t *TorrentManager) repair(torrent *Torrent, wg *sync.WaitGroup) {
info, err := t.redownloadTorrent(torrent, []string{}) // reinsert the whole torrent, passing empty selection
if info != nil && info.Progress == 100 {
err = t.checkIfBroken(info, brokenFiles)
if dlErr, ok := err.(*http.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
if utils.IsBWLimitExceeded(err) {
t.repairLog.Warnf("Your account has reached the bandwidth limit, cannot continue repairing torrent %s", t.GetKey(torrent))
return
}
@@ -339,8 +338,8 @@ func (t *TorrentManager) assignLinks(torrent *Torrent) bool {
bwLimitReached := false
torrent.UnassignedLinks.Clone().Each(func(link string) bool {
// unrestrict each unassigned link that was filled out during torrent init
unrestrict, err := t.rd.UnrestrictLink(link)
if dlErr, ok := err.(*http.DownloadErrorResponse); ok && dlErr.Message == "bytes_limit_reached" {
unrestrict, err := t.rd.UnrestrictAndVerify(link)
if utils.IsBWLimitExceeded(err) {
bwLimitReached = true
return true
}