package torrent import cmap "github.com/orcaman/concurrent-map/v2" func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool { var unselectedIDs []int torrent.SelectedFiles.IterCb(func(_ string, file *File) { if file.Link == "unselect" { unselectedIDs = append(unselectedIDs, file.ID) } }) if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 { return true } else if len(unselectedIDs) > 0 { infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE) torrent.DownloadedIDs.Each(func(id string) bool { info, _ := infoCache.Get(id) info.SelectedFiles.IterCb(func(_ string, file *File) { for _, unselectedID := range unselectedIDs { if file.ID == unselectedID { file.Link = "unselect" break } } }) t.writeTorrentToFile(id, info) return false }) } return false } func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) { allTorrents, _ := t.DirectoryMap.Get(INT_ALL) if deleteInRD { infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE) if torrent, ok := allTorrents.Get(accessKey); ok { torrent.DownloadedIDs.Union(torrent.InProgressIDs).Each(func(id string) bool { t.log.Debugf("Deleting torrent %s (id=%s) in RD", accessKey, id) t.Api.DeleteTorrent(id) infoCache.Remove(id) t.deleteTorrentFile(id) return false }) } } t.allAccessKeys.Remove(accessKey) t.log.Infof("Removing torrent %s from zurg database (not real-debrid)", accessKey) t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) { torrents.Remove(accessKey) }) allTorrents.Remove(accessKey) }