From d42dfd7224dcc24d941736791a749ccfd36ee55a Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Wed, 6 Dec 2023 04:17:38 +0100 Subject: [PATCH] Add triggers again --- internal/dav/delete.go | 2 -- internal/torrent/manager.go | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/dav/delete.go b/internal/dav/delete.go index 80266e5..73313aa 100644 --- a/internal/dav/delete.go +++ b/internal/dav/delete.go @@ -35,7 +35,5 @@ func HandleDeleteFile(directory, torrentName, fileName string, torMgr *torrent.T if torMgr.CheckDeletedState(torrent) { torMgr.Delete(torrentName, true) } - // todo: triggeer an update ??? - // t.TriggerHookOnLibraryUpdate(updatedPaths) return nil } diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 9acdff2..ea8a2b1 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -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)) {