From 3f0870cd1cb620c48fb2d8673bc47246a3472209 Mon Sep 17 00:00:00 2001 From: Mukhtar Akere Date: Tue, 16 Sep 2025 21:34:58 +0100 Subject: [PATCH] torbox: fix pagination bug, fix download uncached bug --- pkg/debrid/providers/torbox/torbox.go | 23 ++++++++++++++++++++++- pkg/debrid/store/repair.go | 13 +++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pkg/debrid/providers/torbox/torbox.go b/pkg/debrid/providers/torbox/torbox.go index b6c03ed..f111891 100644 --- a/pkg/debrid/providers/torbox/torbox.go +++ b/pkg/debrid/providers/torbox/torbox.go @@ -139,6 +139,9 @@ func (tb *Torbox) SubmitMagnet(torrent *types.Torrent) (*types.Torrent, error) { payload := &bytes.Buffer{} writer := multipart.NewWriter(payload) _ = writer.WriteField("magnet", torrent.Magnet.Link) + if !torrent.DownloadUncached { + _ = writer.WriteField("add_only_if_cached", "true") + } err := writer.Close() if err != nil { return nil, err @@ -518,7 +521,25 @@ func (tb *Torbox) GetDownloadingStatus() []string { } func (tb *Torbox) GetTorrents() ([]*types.Torrent, error) { - url := fmt.Sprintf("%s/api/torrents/mylist", tb.Host) + offset := 0 + allTorrents := make([]*types.Torrent, 0) + + for { + torrents, err := tb.getTorrents(offset) + if err != nil { + break + } + if len(torrents) == 0 { + break + } + allTorrents = append(allTorrents, torrents...) + offset += len(torrents) + } + return allTorrents, nil +} + +func (tb *Torbox) getTorrents(offset int) ([]*types.Torrent, error) { + url := fmt.Sprintf("%s/api/torrents/mylist?offset=%d", tb.Host, offset) req, _ := http.NewRequest(http.MethodGet, url, nil) resp, err := tb.client.MakeRequest(req) if err != nil { diff --git a/pkg/debrid/store/repair.go b/pkg/debrid/store/repair.go index 49ad664..7f65031 100644 --- a/pkg/debrid/store/repair.go +++ b/pkg/debrid/store/repair.go @@ -235,12 +235,13 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) { // Submit the magnet to the debrid service newTorrent := &types.Torrent{ - Name: torrent.Name, - Magnet: utils.ConstructMagnet(torrent.InfoHash, torrent.Name), - InfoHash: torrent.InfoHash, - Size: torrent.Size, - Files: make(map[string]types.File), - Arr: torrent.Arr, + Name: torrent.Name, + Magnet: utils.ConstructMagnet(torrent.InfoHash, torrent.Name), + InfoHash: torrent.InfoHash, + Size: torrent.Size, + Files: make(map[string]types.File), + Arr: torrent.Arr, + DownloadUncached: false, } var err error newTorrent, err = c.client.SubmitMagnet(newTorrent)