From 2a4f09c06ddeb6856b2d9ab5655425b1bb457aca Mon Sep 17 00:00:00 2001 From: Mukhtar Akere Date: Wed, 15 Oct 2025 11:56:15 +0100 Subject: [PATCH] Delete failed download link for next retry --- pkg/debrid/common/interface.go | 1 + pkg/debrid/providers/alldebrid/alldebrid.go | 5 +++++ pkg/debrid/providers/debridlink/debrid_link.go | 5 +++++ pkg/debrid/providers/realdebrid/realdebrid.go | 17 +++++++++++++++++ pkg/debrid/providers/torbox/torbox.go | 5 +++++ pkg/debrid/store/download_link.go | 13 +++++++++++++ 6 files changed, 46 insertions(+) diff --git a/pkg/debrid/common/interface.go b/pkg/debrid/common/interface.go index 83cc603..4e3b963 100644 --- a/pkg/debrid/common/interface.go +++ b/pkg/debrid/common/interface.go @@ -27,4 +27,5 @@ type Client interface { GetProfile() (*types.Profile, error) GetAvailableSlots() (int, error) SyncAccounts() error // Updates each accounts details(like traffic, username, etc.) + DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error } diff --git a/pkg/debrid/providers/alldebrid/alldebrid.go b/pkg/debrid/providers/alldebrid/alldebrid.go index 7e53447..77e97cd 100644 --- a/pkg/debrid/providers/alldebrid/alldebrid.go +++ b/pkg/debrid/providers/alldebrid/alldebrid.go @@ -497,3 +497,8 @@ func (ad *AllDebrid) AccountManager() *account.Manager { func (ad *AllDebrid) SyncAccounts() error { return nil } + +func (ad *AllDebrid) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error { + account.DeleteDownloadLink(downloadLink.Link) + return nil +} diff --git a/pkg/debrid/providers/debridlink/debrid_link.go b/pkg/debrid/providers/debridlink/debrid_link.go index 8a336bc..5ca5fb6 100644 --- a/pkg/debrid/providers/debridlink/debrid_link.go +++ b/pkg/debrid/providers/debridlink/debrid_link.go @@ -518,3 +518,8 @@ func (dl *DebridLink) AccountManager() *account.Manager { func (dl *DebridLink) SyncAccounts() error { return nil } + +func (dl *DebridLink) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error { + account.DeleteDownloadLink(downloadLink.Link) + return nil +} diff --git a/pkg/debrid/providers/realdebrid/realdebrid.go b/pkg/debrid/providers/realdebrid/realdebrid.go index 034e525..0365029 100644 --- a/pkg/debrid/providers/realdebrid/realdebrid.go +++ b/pkg/debrid/providers/realdebrid/realdebrid.go @@ -986,3 +986,20 @@ func (r *RealDebrid) syncAccount(account *account.Account) error { //r.accountsManager.Update(account) return nil } + +func (r *RealDebrid) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error { + url := fmt.Sprintf("%s/downloads/delete/%s", r.Host, downloadLink.Id) + req, _ := http.NewRequest(http.MethodDelete, url, nil) + resp, err := account.Client().Do(req) + if err != nil { + return err + } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) + if resp.StatusCode != http.StatusNoContent { + return fmt.Errorf("realdebrid API error: %d", resp.StatusCode) + } + account.DeleteDownloadLink(downloadLink.Link) + return nil +} diff --git a/pkg/debrid/providers/torbox/torbox.go b/pkg/debrid/providers/torbox/torbox.go index f111891..82c1054 100644 --- a/pkg/debrid/providers/torbox/torbox.go +++ b/pkg/debrid/providers/torbox/torbox.go @@ -654,3 +654,8 @@ func (tb *Torbox) AccountManager() *account.Manager { func (tb *Torbox) SyncAccounts() error { return nil } + +func (tb *Torbox) DeleteDownloadLink(account *account.Account, downloadLink types.DownloadLink) error { + account.DeleteDownloadLink(downloadLink.Link) + return nil +} diff --git a/pkg/debrid/store/download_link.go b/pkg/debrid/store/download_link.go index f8320f7..032614f 100644 --- a/pkg/debrid/store/download_link.go +++ b/pkg/debrid/store/download_link.go @@ -172,6 +172,19 @@ func (c *Cache) MarkLinkAsInvalid(downloadLink types.DownloadLink, reason string return } accountManager.Disable(account) + } else if reason == "link_not_found" { + // Let's try to delete the download link from the account, so we can fetch a new one next time + accountManager := c.client.AccountManager() + account, err := accountManager.GetAccount(downloadLink.Token) + if err != nil { + c.logger.Error().Err(err).Str("token", utils.Mask(downloadLink.Token)).Msg("Failed to get account to delete download link") + return + } + if account == nil { + c.logger.Error().Str("token", utils.Mask(downloadLink.Token)).Msg("Account not found to delete download link") + return + } + c.client.DeleteDownloadLink(account, downloadLink) } }