Add rename
This commit is contained in:
41
internal/dav/rename.go
Normal file
41
internal/dav/rename.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user