44 lines
1.2 KiB
Go
44 lines
1.2 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)
|
|
}
|
|
// todo: need to remove on all directories
|
|
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.State.Is("deleted_file") {
|
|
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
|
|
}
|