This commit is contained in:
Ben Sarmiento
2024-05-23 19:29:16 +02:00
parent 2a5f12e37f
commit d03b59bb2a
10 changed files with 275 additions and 226 deletions

View File

@@ -15,19 +15,24 @@ import (
func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
var buf bytes.Buffer
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
directories := torMgr.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
if strings.HasPrefix(directory, "int__") {
continue
}
buf.WriteString(dav.BaseDirectory(directory, ""))
}
if torMgr.Config.EnableDownloadMount() {
buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))
}
_, size := version.GetFile()
buf.WriteString(dav.File(version.FILE, size, ""))
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
@@ -40,15 +45,18 @@ func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager
var buf bytes.Buffer
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
torrentNames := torrents.Keys()
sort.Strings(torrentNames)
for _, torrentName := range torrentNames {
tor, ok := torrents.Get(torrentName)
if !ok || tor.AllInProgress() {
if !ok {
continue
}
buf.WriteString(dav.BaseDirectory(torMgr.GetKey(tor), tor.Added))
}
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
@@ -58,12 +66,14 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
if !ok {
return nil, fmt.Errorf("cannot find directory %s", directory)
}
tor, ok := torrents.Get(torrentName)
if !ok {
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
}
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)
biggestFileSize := int64(0)
if dirCfg.OnlyShowTheBiggestFile {
biggestFileSize = tor.ComputeBiggestFileSize()
@@ -71,8 +81,10 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
var buf bytes.Buffer
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames)
for _, filename := range filenames {
file, _ := tor.SelectedFiles.Get(filename)
if !file.State.Is("ok_file") {
@@ -89,6 +101,7 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
}
buf.WriteString(dav.File(filename, file.Bytes, tor.Added))
}
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
@@ -99,9 +112,12 @@ func ServeDownloadsListForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
buf.WriteString("Enable download mount in config to use this feature")
return buf.Bytes(), nil
}
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
filenames := torMgr.DownloadMap.Keys()
sort.Strings(filenames)
for _, filename := range filenames {
download, ok := torMgr.DownloadMap.Get(filename)
if !ok {
@@ -109,6 +125,7 @@ func ServeDownloadsListForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
}
buf.WriteString(dav.File(download.Filename, download.Filesize, download.Generated))
}
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}

View File

@@ -47,7 +47,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte
sort.Strings(torrentNames)
for _, torrentName := range torrentNames {
tor, ok := torrents.Get(torrentName)
if !ok || tor.AllInProgress() {
if !ok {
continue
}
buf.WriteString(dav.Directory(torMgr.GetKey(tor), tor.Added))