Files
zurg/internal/torrent/delete.go
2024-07-21 02:11:32 +02:00

50 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) {
torrents, _ := t.DirectoryMap.Get(INT_ALL)
if torrent, ok := torrents.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)
})
torrents.Remove(accessKey)
}
func (t *TorrentManager) DeleteByID(torrentID string) {
t.rd.DeleteTorrent(torrentID)
t.deleteInfoFile(torrentID)
}