Get library state from 3 endpoints
This commit is contained in:
@@ -4,13 +4,14 @@ type LibraryState struct {
|
|||||||
TotalCount int
|
TotalCount int
|
||||||
ActiveCount int
|
ActiveCount int
|
||||||
FirstActiveTorrentId string
|
FirstActiveTorrentId string
|
||||||
|
FirstTorrentId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LibraryState) Eq(a LibraryState) bool {
|
func (ls *LibraryState) Eq(a LibraryState) bool {
|
||||||
if ls.TotalCount == 0 || ls.FirstActiveTorrentId == "" {
|
if ls.TotalCount == 0 || ls.FirstActiveTorrentId == "" || ls.FirstTorrentId == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if a.TotalCount != ls.TotalCount || a.ActiveCount != ls.ActiveCount || a.FirstActiveTorrentId != ls.FirstActiveTorrentId {
|
if a.TotalCount != ls.TotalCount || a.ActiveCount != ls.ActiveCount || a.FirstActiveTorrentId != ls.FirstActiveTorrentId || a.FirstTorrentId != ls.FirstTorrentId {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -20,20 +21,30 @@ func (t *TorrentManager) setNewLatestState(checksum LibraryState) {
|
|||||||
t.latestState.ActiveCount = checksum.ActiveCount
|
t.latestState.ActiveCount = checksum.ActiveCount
|
||||||
t.latestState.TotalCount = checksum.TotalCount
|
t.latestState.TotalCount = checksum.TotalCount
|
||||||
t.latestState.FirstActiveTorrentId = checksum.FirstActiveTorrentId
|
t.latestState.FirstActiveTorrentId = checksum.FirstActiveTorrentId
|
||||||
|
t.latestState.FirstTorrentId = checksum.FirstTorrentId
|
||||||
}
|
}
|
||||||
|
|
||||||
// generates a checksum based on the number of torrents, the first torrent id and the number of active torrents
|
// generates a checksum based on the number of torrents, the first torrent id and the number of active torrents
|
||||||
func (t *TorrentManager) getCurrentState() LibraryState {
|
func (t *TorrentManager) getCurrentState() LibraryState {
|
||||||
var state LibraryState
|
var state LibraryState
|
||||||
|
|
||||||
activeTorrents, totalCount, err := t.Api.GetTorrents(1, true)
|
activeTorrents, _, err := t.Api.GetTorrents(1, true)
|
||||||
|
if err != nil {
|
||||||
|
t.log.Errorf("Checksum API Error (GetActiveTorrents): %v", err)
|
||||||
|
return LibraryState{}
|
||||||
|
}
|
||||||
|
if len(activeTorrents) > 0 {
|
||||||
|
state.FirstActiveTorrentId = activeTorrents[0].ID
|
||||||
|
}
|
||||||
|
|
||||||
|
torrents, totalCount, err := t.Api.GetTorrents(1, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.log.Errorf("Checksum API Error (GetTorrents): %v", err)
|
t.log.Errorf("Checksum API Error (GetTorrents): %v", err)
|
||||||
return LibraryState{}
|
return LibraryState{}
|
||||||
}
|
}
|
||||||
state.TotalCount = totalCount
|
state.TotalCount = totalCount
|
||||||
if len(activeTorrents) > 0 {
|
if len(torrents) > 0 {
|
||||||
state.FirstActiveTorrentId = activeTorrents[0].ID
|
state.FirstTorrentId = torrents[0].ID
|
||||||
}
|
}
|
||||||
|
|
||||||
count, err := t.Api.GetActiveTorrentCount()
|
count, err := t.Api.GetActiveTorrentCount()
|
||||||
|
|||||||
Reference in New Issue
Block a user