Add support for configs

This commit is contained in:
Ben Sarmiento
2023-10-18 21:09:25 +02:00
parent f9b5b1efac
commit 4650213218
19 changed files with 359 additions and 48 deletions

View File

@@ -9,9 +9,9 @@ import (
)
// createMultiTorrentResponse creates a WebDAV response for a list of torrents
func createMultiTorrentResponse(torrents []torrent.Torrent) (*dav.MultiStatus, error) {
func createMultiTorrentResponse(basePath string, torrents []torrent.Torrent) (*dav.MultiStatus, error) {
var responses []dav.Response
responses = append(responses, dav.Directory("/torrents"))
responses = append(responses, dav.Directory(basePath))
seen := make(map[string]bool)
@@ -19,12 +19,12 @@ func createMultiTorrentResponse(torrents []torrent.Torrent) (*dav.MultiStatus, e
if item.Progress != 100 {
continue
}
if _, exists := seen[item.Filename]; exists {
if _, exists := seen[item.Name]; exists {
continue
}
seen[item.Filename] = true
seen[item.Name] = true
path := filepath.Join("/torrents", item.Filename)
path := filepath.Join(basePath, item.Name)
responses = append(responses, dav.Directory(path))
}
@@ -36,10 +36,10 @@ func createMultiTorrentResponse(torrents []torrent.Torrent) (*dav.MultiStatus, e
// createTorrentResponse creates a WebDAV response for a single torrent
// but it also handles the case where there are many torrents with the same name
func createCombinedTorrentResponse(torrents []torrent.Torrent, t *torrent.TorrentManager) (*dav.MultiStatus, error) {
func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent, t *torrent.TorrentManager) (*dav.MultiStatus, error) {
var responses []dav.Response
// initial response is the directory itself
currentPath := filepath.Join("/torrents", torrents[0].Filename)
currentPath := filepath.Join(basePath, torrents[0].Name)
responses = append(responses, dav.Directory(currentPath))
seen := make(map[string]bool)