Delete failed download link for next retry

This commit is contained in:
Mukhtar Akere
2025-10-15 11:56:15 +01:00
parent b1b6353fb3
commit 2a4f09c06d
6 changed files with 46 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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)
}
}