Files
zurg/internal/dav/rename.go
Ben Sarmiento 9e181c2b19 Add rename
2023-12-10 21:00:02 +01:00

42 lines
1.1 KiB
Go

package dav
import (
"fmt"
"github.com/debridmediamanager/zurg/internal/torrent"
)
func HandleRenameTorrent(directory, torrentName, newName 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)
}
torrents.Remove(torrentName)
torrents.Set(newName, torrent)
torrent.AccessKey = newName
return nil
}
func HandleRenameFile(directory, torrentName, fileName, newName 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)
}
torrent.SelectedFiles.Remove(torrentName)
torrent.SelectedFiles.Set(newName, file)
file.Path = newName
return nil
}