Fix issues with account swutching

This commit is contained in:
Mukhtar Akere
2025-08-26 15:31:24 +01:00
parent eefe8a3901
commit 267cc2d32b
13 changed files with 149 additions and 115 deletions

View File

@@ -247,7 +247,7 @@ func (dl *DebridLink) UpdateTorrent(t *types.Torrent) error {
t.Files[f.Name] = file
}
dl.accounts.SetDownloadLinks(nil, links)
dl.accounts.SetDownloadLinks(links)
return nil
}
@@ -287,6 +287,7 @@ func (dl *DebridLink) SubmitMagnet(t *types.Torrent) (*types.Torrent, error) {
links := make(map[string]*types.DownloadLink)
now := time.Now()
account := dl.accounts.Current()
for _, f := range data.Files {
file := types.File{
TorrentId: t.Id,
@@ -303,12 +304,14 @@ func (dl *DebridLink) SubmitMagnet(t *types.Torrent) (*types.Torrent, error) {
DownloadLink: f.DownloadURL,
Generated: now,
ExpiresAt: now.Add(dl.autoExpiresLinksAfter),
Token: account.Token,
MaskedToken: account.MaskedToken,
}
links[file.Link] = link
file.DownloadLink = link
t.Files[f.Name] = file
}
dl.accounts.SetDownloadLinks(nil, links)
dl.accounts.SetDownloadLinks(links)
return t, nil
}
@@ -356,7 +359,7 @@ func (dl *DebridLink) RefreshDownloadLinks() error {
return nil
}
func (dl *DebridLink) GetDownloadLink(t *types.Torrent, file *types.File) (*types.DownloadLink, *types.Account, error) {
func (dl *DebridLink) GetDownloadLink(t *types.Torrent, file *types.File) (*types.DownloadLink, error) {
return dl.accounts.GetDownloadLink(file.Link)
}
@@ -407,6 +410,7 @@ func (dl *DebridLink) getTorrents(page, perPage int) ([]*types.Torrent, error) {
if len(data) == 0 {
return torrents, nil
}
account := dl.accounts.Current()
for _, t := range data {
if t.Status != 100 {
continue
@@ -444,6 +448,8 @@ func (dl *DebridLink) getTorrents(page, perPage int) ([]*types.Torrent, error) {
DownloadLink: f.DownloadURL,
Generated: now,
ExpiresAt: now.Add(dl.autoExpiresLinksAfter),
Token: account.Token,
MaskedToken: account.MaskedToken,
}
links[file.Link] = link
file.DownloadLink = link
@@ -451,7 +457,7 @@ func (dl *DebridLink) getTorrents(page, perPage int) ([]*types.Torrent, error) {
}
torrents = append(torrents, torrent)
}
dl.accounts.SetDownloadLinks(nil, links)
dl.accounts.SetDownloadLinks(links)
return torrents, nil
}