Fix possible issues
This commit is contained in:
@@ -1,68 +1,44 @@
|
||||
package torrent
|
||||
|
||||
import (
|
||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||
)
|
||||
|
||||
type LibraryState struct {
|
||||
TotalCount int
|
||||
ActiveCount int
|
||||
FirstTorrent *realdebrid.Torrent
|
||||
FirstActiveTorrent *realdebrid.Torrent
|
||||
TotalCount int
|
||||
ActiveCount int
|
||||
FirstActiveTorrentId string
|
||||
}
|
||||
|
||||
func (ls LibraryState) equal(a LibraryState) bool {
|
||||
if a.TotalCount != ls.TotalCount || a.ActiveCount != ls.ActiveCount {
|
||||
func (ls *LibraryState) Eq(a LibraryState) bool {
|
||||
if ls.TotalCount == 0 || ls.FirstActiveTorrentId == "" {
|
||||
return false
|
||||
}
|
||||
if (ls.FirstTorrent == nil) != (a.FirstTorrent == nil) {
|
||||
return false
|
||||
}
|
||||
if ls.FirstTorrent != nil && (ls.FirstTorrent.ID != a.FirstTorrent.ID || ls.FirstTorrent.Status != a.FirstTorrent.Status) {
|
||||
return false
|
||||
}
|
||||
if (ls.FirstActiveTorrent == nil) != (a.FirstActiveTorrent == nil) {
|
||||
return false
|
||||
}
|
||||
if ls.FirstActiveTorrent != nil && (ls.FirstActiveTorrent.ID != a.FirstActiveTorrent.ID || ls.FirstActiveTorrent.Status != a.FirstActiveTorrent.Status) {
|
||||
if a.TotalCount != ls.TotalCount || a.ActiveCount != ls.ActiveCount || a.FirstActiveTorrentId != ls.FirstActiveTorrentId {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *TorrentManager) SetNewLatestState(checksum LibraryState) {
|
||||
func (t *TorrentManager) setNewLatestState(checksum LibraryState) {
|
||||
t.latestState.ActiveCount = checksum.ActiveCount
|
||||
t.latestState.TotalCount = checksum.TotalCount
|
||||
t.latestState.FirstTorrent = checksum.FirstTorrent
|
||||
t.latestState.FirstActiveTorrent = checksum.FirstActiveTorrent
|
||||
t.latestState.FirstActiveTorrentId = checksum.FirstActiveTorrentId
|
||||
}
|
||||
|
||||
// generates a checksum based on the number of torrents, the first torrent id and the number of active torrents
|
||||
func (t *TorrentManager) getCurrentState() LibraryState {
|
||||
var state LibraryState
|
||||
|
||||
torrents, totalCount, err := t.Api.GetTorrents(1, false)
|
||||
activeTorrents, totalCount, err := t.Api.GetTorrents(1, true)
|
||||
if err != nil {
|
||||
t.log.Warnf("Checksum API Error (GetTorrents): %v", err)
|
||||
t.log.Errorf("Checksum API Error (GetTorrents): %v", err)
|
||||
return LibraryState{}
|
||||
}
|
||||
if len(torrents) > 0 {
|
||||
state.FirstTorrent = &torrents[0]
|
||||
}
|
||||
state.TotalCount = totalCount
|
||||
|
||||
activeTorrents, _, err := t.Api.GetTorrents(1, true)
|
||||
if err != nil {
|
||||
t.log.Warnf("Checksum API Error (GetTorrents): %v", err)
|
||||
return LibraryState{}
|
||||
}
|
||||
if len(activeTorrents) > 0 {
|
||||
state.FirstActiveTorrent = &activeTorrents[0]
|
||||
state.FirstActiveTorrentId = activeTorrents[0].ID
|
||||
}
|
||||
|
||||
count, err := t.Api.GetActiveTorrentCount()
|
||||
if err != nil {
|
||||
t.log.Warnf("Checksum API Error (GetActiveTorrentCount): %v", err)
|
||||
t.log.Errorf("Checksum API Error (GetActiveTorrentCount): %v", err)
|
||||
return LibraryState{}
|
||||
}
|
||||
state.ActiveCount = count.DownloadingCount
|
||||
|
||||
Reference in New Issue
Block a user