Files
zurg/internal/dav/delete.go

46 lines
1.2 KiB
Go

package dav
import (
"fmt"
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/internal/torrent"
)
func HandleDeleteTorrent(directory, torrentName string, torMgr *torrent.TorrentManager) error {
torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok {
return fmt.Errorf("cannot find directory %s", directory)
}
if !torrents.Has(torrentName) {
return fmt.Errorf("cannot find torrent %s", torrentName)
}
torMgr.Delete(torrentName, true)
return nil
}
func HandleDeleteFile(directory, torrentName, fileName string, torMgr *torrent.TorrentManager) error {
torrents, ok := torMgr.DirectoryMap.Get(directory)
if !ok {
return fmt.Errorf("cannot find directory %s", directory)
}
torrent, ok := torrents.Get(torrentName)
if !ok {
return fmt.Errorf("cannot find torrent %s", torrentName)
}
file, ok := torrent.SelectedFiles.Get(fileName)
if !ok {
return fmt.Errorf("cannot find file %s", fileName)
}
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)
if dirCfg.OnlyShowTheBiggestFile {
torMgr.Delete(torrentName, true)
} else {
file.Link = "unselect"
if torMgr.CheckDeletedStatus(torrent) {
torMgr.Delete(torrentName, true)
}
}
return nil
}