Small repairs on logic
This commit is contained in:
@@ -59,7 +59,7 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) {
|
||||
result := <-allResults
|
||||
if result.err != nil {
|
||||
rd.log.Warnf("Ignoring error when fetching torrents pg %d: %v", result.page, result.err)
|
||||
continue
|
||||
return nil, 0, result.err
|
||||
}
|
||||
bIdx := (result.page - 1) % maxParallelThreads
|
||||
batches[bIdx] = []Torrent{}
|
||||
@@ -71,7 +71,7 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) {
|
||||
cIdxEnd := cachedCount - 1 - cIdx
|
||||
for tIdx, torrent := range batch { // 250 torrents
|
||||
tIdxEnd := indexFromEnd(tIdx, page+bIdx, pageSize, result.total)
|
||||
if torrent.ID == cached.ID && tIdxEnd == cIdxEnd {
|
||||
if torrent.ID == cached.ID && torrent.Progress == cached.Progress && tIdxEnd == cIdxEnd {
|
||||
allTorrents = append(allTorrents, batch[:tIdx]...)
|
||||
allTorrents = append(allTorrents, rd.torrentsCache[cIdx:]...)
|
||||
rd.log.Debugf("Got %d/%d torrents", len(allTorrents), result.total)
|
||||
|
||||
@@ -68,6 +68,20 @@ func (i *Torrent) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Torrent) MarshalJSON() ([]byte, error) {
|
||||
type Alias Torrent
|
||||
aux := &struct {
|
||||
Progress float64 `json:"progress"`
|
||||
Added string `json:"added"`
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(i),
|
||||
Progress: float64(i.Progress), // Convert int to float64 for JSON representation
|
||||
Added: i.Added,
|
||||
}
|
||||
return json.Marshal(aux)
|
||||
}
|
||||
|
||||
type TorrentInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"filename"`
|
||||
|
||||
Reference in New Issue
Block a user