Serve downloads list

This commit is contained in:
Ben Sarmiento
2024-01-07 23:44:26 +01:00
parent 57e6b0b860
commit 62de3723c1
4 changed files with 68 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
}
buf.WriteString(dav.BaseDirectory(directory, ""))
}
buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
@@ -86,3 +87,17 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
func ServeDownloadsListForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
var buf bytes.Buffer
if !torMgr.Config.GetConfig().UseDownloadCache {
buf.WriteString("Enable download cache in config to use this feature")
return buf.Bytes(), nil
}
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
for _, download := range torMgr.DownloadCache.Items() {
buf.WriteString(dav.File(download.Filename, download.Filesize, download.Generated))
}
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}

View File

@@ -24,6 +24,7 @@ func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
}
buf.WriteString(dav.Directory(directory, ""))
}
buf.WriteString(dav.Directory(config.DOWNLOADS, ""))
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
@@ -112,3 +113,18 @@ func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.T
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}
func ServeDownloadsList(torMgr *torrent.TorrentManager) ([]byte, error) {
var buf bytes.Buffer
if !torMgr.Config.GetConfig().UseDownloadCache {
buf.WriteString("Enable download cache in config to use this feature")
return buf.Bytes(), nil
}
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))
for _, download := range torMgr.DownloadCache.Items() {
buf.WriteString(dav.File(download.Filename, download.Filesize, download.Generated))
}
buf.WriteString("</d:multistatus>")
return buf.Bytes(), nil
}