Add triggers again

This commit is contained in:
Ben Sarmiento
2023-12-06 04:17:38 +01:00
parent dd2a9d23f1
commit d42dfd7224
2 changed files with 11 additions and 3 deletions

View File

@@ -111,7 +111,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
}
func (t *TorrentManager) RefreshTorrents() {
instances, _, err := t.Api.GetTorrents(10)
instances, _, err := t.Api.GetTorrents(0)
if err != nil {
t.log.Warnf("Cannot get torrents: %v\n", err)
return
@@ -154,6 +154,7 @@ func (t *TorrentManager) RefreshTorrents() {
return true
})
// new
var updatedPaths []string
strset.Difference(freshKeys, t.accessKeySet).Each(func(accessKey string) bool {
t.accessKeySet.Add(accessKey)
tor, _ := allTorrents.Get(accessKey)
@@ -163,11 +164,14 @@ func (t *TorrentManager) RefreshTorrents() {
}
torrents, _ := t.DirectoryMap.Get(directory)
torrents.Set(accessKey, tor)
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey))
})
return true
})
t.SetNewLatestState(t.getCurrentState())
t.TriggerHookOnLibraryUpdate(updatedPaths)
}
// getMoreInfo gets original name, size and files for a torrent
@@ -718,6 +722,12 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
t.repair(torrent)
t.log.Info("Finished repairing torrent %s", torrent.AccessKey)
})
var updatedPaths []string
t.AssignedDirectoryCb(torrent, func(directory string) {
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, torrent.AccessKey))
})
t.TriggerHookOnLibraryUpdate(updatedPaths)
}
func (t *TorrentManager) AssignedDirectoryCb(tor *Torrent, cb func(string)) {