Handle adds and deletes
This commit is contained in:
@@ -11,10 +11,10 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func HandleListDirectories(t *torrent.TorrentManager) (*string, error) {
|
||||
func HandleListDirectories(torMgr *torrent.TorrentManager) (*string, error) {
|
||||
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
|
||||
davDoc += dav.BaseDirectory("", "")
|
||||
directories := t.DirectoryMap.Keys()
|
||||
directories := torMgr.DirectoryMap.Keys()
|
||||
sort.Strings(directories)
|
||||
for _, directory := range directories {
|
||||
if strings.HasPrefix(directory, "int__") {
|
||||
@@ -26,25 +26,33 @@ func HandleListDirectories(t *torrent.TorrentManager) (*string, error) {
|
||||
return &davDoc, nil
|
||||
}
|
||||
|
||||
func HandleListTorrents(directory string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||
_, ok := t.DirectoryMap.Get(directory)
|
||||
func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
}
|
||||
|
||||
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
|
||||
davDoc += dav.Directory("", "")
|
||||
directories := t.DirectoryMap.Keys()
|
||||
sort.Strings(directories)
|
||||
for _, directory := range directories {
|
||||
davDoc += dav.Directory(directory, "")
|
||||
var allTorrents []*torrent.Torrent
|
||||
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
||||
if tor.AllInProgress() {
|
||||
return
|
||||
}
|
||||
allTorrents = append(allTorrents, tor)
|
||||
})
|
||||
sort.Slice(allTorrents, func(i, j int) bool {
|
||||
return allTorrents[i].AccessKey < allTorrents[j].AccessKey
|
||||
})
|
||||
for _, tor := range allTorrents {
|
||||
davDoc += dav.Directory(tor.AccessKey, tor.LatestAdded)
|
||||
}
|
||||
davDoc += "</d:multistatus>"
|
||||
return &davDoc, nil
|
||||
}
|
||||
|
||||
func HandleListFiles(directory, torrentName string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||
torrents, ok := t.DirectoryMap.Get(directory)
|
||||
func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user