45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package torrent
|
|
|
|
type LibraryState struct {
|
|
TotalCount int
|
|
ActiveCount int
|
|
FirstTorrentId string
|
|
}
|
|
|
|
func (ls *LibraryState) Eq(a LibraryState) bool {
|
|
if ls.TotalCount == 0 || ls.FirstTorrentId == "" {
|
|
return false
|
|
}
|
|
return a.TotalCount == ls.TotalCount && a.ActiveCount == ls.ActiveCount && a.FirstTorrentId == ls.FirstTorrentId
|
|
}
|
|
|
|
func (t *TorrentManager) setNewLatestState(checksum LibraryState) {
|
|
t.latestState.ActiveCount = checksum.ActiveCount
|
|
t.latestState.TotalCount = checksum.TotalCount
|
|
t.latestState.FirstTorrentId = checksum.FirstTorrentId
|
|
}
|
|
|
|
// 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(true)
|
|
if err != nil {
|
|
t.log.Errorf("Checksum API Error (GetTorrents): %v", err)
|
|
return LibraryState{}
|
|
}
|
|
state.TotalCount = totalCount
|
|
if len(torrents) > 0 {
|
|
state.FirstTorrentId = torrents[0].ID
|
|
}
|
|
|
|
count, err := t.api.GetActiveTorrentCount()
|
|
if err != nil {
|
|
t.log.Errorf("Checksum API Error (GetActiveTorrentCount): %v", err)
|
|
return LibraryState{}
|
|
}
|
|
state.ActiveCount = count.DownloadingCount
|
|
|
|
return state
|
|
}
|