Skip to content

Commit 2a4f09c

Browse files
committed
Delete failed download link for next retry
1 parent b1b6353 commit 2a4f09c

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

pkg/debrid/common/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ type Client interface {
2727
GetProfile() (*types.Profile, error)
2828
GetAvailableSlots() (int, error)
2929
SyncAccounts() error // Updates each accounts details(like traffic, username, etc.)
30+
DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error
3031
}

pkg/debrid/providers/alldebrid/alldebrid.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,3 +497,8 @@ func (ad *AllDebrid) AccountManager() *account.Manager {
497497
func (ad *AllDebrid) SyncAccounts() error {
498498
return nil
499499
}
500+
501+
func (ad *AllDebrid) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error {
502+
account.DeleteDownloadLink(downloadLink.Link)
503+
return nil
504+
}

pkg/debrid/providers/debridlink/debrid_link.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,8 @@ func (dl *DebridLink) AccountManager() *account.Manager {
518518
func (dl *DebridLink) SyncAccounts() error {
519519
return nil
520520
}
521+
522+
func (dl *DebridLink) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error {
523+
account.DeleteDownloadLink(downloadLink.Link)
524+
return nil
525+
}

pkg/debrid/providers/realdebrid/realdebrid.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,3 +986,20 @@ func (r *RealDebrid) syncAccount(account *account.Account) error {
986986
//r.accountsManager.Update(account)
987987
return nil
988988
}
989+
990+
func (r *RealDebrid) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error {
991+
url := fmt.Sprintf("%s/downloads/delete/%s", r.Host, downloadLink.Id)
992+
req, _ := http.NewRequest(http.MethodDelete, url, nil)
993+
resp, err := account.Client().Do(req)
994+
if err != nil {
995+
return err
996+
}
997+
defer func(Body io.ReadCloser) {
998+
_ = Body.Close()
999+
}(resp.Body)
1000+
if resp.StatusCode != http.StatusNoContent {
1001+
return fmt.Errorf("realdebrid API error: %d", resp.StatusCode)
1002+
}
1003+
account.DeleteDownloadLink(downloadLink.Link)
1004+
return nil
1005+
}

pkg/debrid/providers/torbox/torbox.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,8 @@ func (tb *Torbox) AccountManager() *account.Manager {
654654
func (tb *Torbox) SyncAccounts() error {
655655
return nil
656656
}
657+
658+
func (tb *Torbox) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error {
659+
account.DeleteDownloadLink(downloadLink.Link)
660+
return nil
661+
}

pkg/debrid/store/download_link.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ func (c *Cache) MarkLinkAsInvalid(downloadLink types.DownloadLink, reason string
172172
return
173173
}
174174
accountManager.Disable(account)
175+
} else if reason == "link_not_found" {
176+
// Let's try to delete the download link from the account, so we can fetch a new one next time
177+
accountManager := c.client.AccountManager()
178+
account, err := accountManager.GetAccount(downloadLink.Token)
179+
if err != nil {
180+
c.logger.Error().Err(err).Str("token", utils.Mask(downloadLink.Token)).Msg("Failed to get account to delete download link")
181+
return
182+
}
183+
if account == nil {
184+
c.logger.Error().Str("token", utils.Mask(downloadLink.Token)).Msg("Account not found to delete download link")
185+
return
186+
}
187+
c.client.DeleteDownloadLink(account, downloadLink)
175188
}
176189
}
177190

0 commit comments

Comments
 (0)