Files
zurg/internal/dav/delete.go
Ben Sarmiento 3df201cc20 Fixes
2023-12-02 20:37:40 +01:00

43 lines
1.1 KiB
Go

package dav
import (
"fmt"
"github.com/debridmediamanager/zurg/internal/torrent"
)
func HandleDeleteTorrent(directory, torrentName string, t *torrent.TorrentManager) error {
torrents, ok := t.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)
}
t.Delete(torrentName, true, true)
return nil
}
func HandleDeleteFile(directory, torrentName, fileName string, t *torrent.TorrentManager) error {
torrents, ok := t.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)
}
file.Link = "unselect"
if t.CheckDeletedState(torrent) {
t.Delete(torrentName, true, true)
} else {
updatedPaths := t.UpdateTorrentResponseCache(torrent)
t.TriggerHookOnLibraryUpdate(updatedPaths)
}
return nil
}