49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package torrent
|
|
|
|
import (
|
|
"github.com/debridmediamanager/zurg/internal/config"
|
|
cmap "github.com/orcaman/concurrent-map/v2"
|
|
)
|
|
|
|
// CheckDeletedStatus checks if all files in a torrent are marked as deleted, if so, it returns true
|
|
func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|
var deletedIDs []int
|
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
|
if file.State.Is("deleted_file") {
|
|
deletedIDs = append(deletedIDs, file.ID)
|
|
}
|
|
})
|
|
if len(deletedIDs) == torrent.SelectedFiles.Count() && len(deletedIDs) > 0 {
|
|
return true
|
|
} else if len(deletedIDs) > 0 {
|
|
t.writeTorrentToFile(torrent)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
|
|
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
|
if torrent, ok := allTorrents.Get(accessKey); ok {
|
|
if deleteInRD {
|
|
torrent.DownloadedIDs.Clone().Each(func(torrentID string) bool {
|
|
t.DeleteByID(torrentID)
|
|
return false
|
|
})
|
|
}
|
|
}
|
|
// t.log.Infof("Removing torrent %s from zurg database (not real-debrid)", accessKey)
|
|
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
|
if directory == config.DOWNLOADS || directory == config.DUMPED_TORRENTS {
|
|
return
|
|
}
|
|
torrents.Remove(accessKey)
|
|
})
|
|
|
|
allTorrents.Remove(accessKey)
|
|
}
|
|
|
|
func (t *TorrentManager) DeleteByID(torrentID string) {
|
|
t.rd.DeleteTorrent(torrentID)
|
|
t.deleteInfoFile(torrentID)
|
|
}
|