Files
zurg/internal/dav/rename.go
2024-01-29 22:28:27 +01:00

43 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.Rename = 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 || file.IsDeleted {
return fmt.Errorf("cannot find file %s", fileName)
}
oldName := torMgr.GetPath(file)
file.Rename = newName
torrent.SelectedFiles.Set(newName, file)
torrent.SelectedFiles.Remove(oldName)
return nil
}