From c28229dd5cc6583149dcb489fa8b20ec49dd232b Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Wed, 10 Jul 2024 17:09:36 +0200 Subject: [PATCH] Exclusive for dav endpoint --- internal/dav/{listing.go => dav.go} | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) rename internal/dav/{listing.go => dav.go} (84%) diff --git a/internal/dav/listing.go b/internal/dav/dav.go similarity index 84% rename from internal/dav/listing.go rename to internal/dav/dav.go index e26f2a9..98f5b59 100644 --- a/internal/dav/listing.go +++ b/internal/dav/dav.go @@ -13,10 +13,10 @@ import ( "github.com/debridmediamanager/zurg/pkg/dav" ) -func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) { +func ServeRootDirectoryForDav(torMgr *torrent.TorrentManager) ([]byte, error) { var buf bytes.Buffer buf.WriteString("") - buf.WriteString(dav.BaseDirectory("", "")) + buf.WriteString(dav.BaseDirectory(addSlash(""), "")) directories := torMgr.DirectoryMap.Keys() sort.Strings(directories) for _, directory := range directories { @@ -32,7 +32,7 @@ func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) { return buf.Bytes(), nil } -func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte, error) { +func ServeTorrentsListForDav(directory string, torMgr *torrent.TorrentManager) ([]byte, error) { torrents, ok := torMgr.DirectoryMap.Get(directory) if !ok { return nil, fmt.Errorf("cannot find directory %s", directory) @@ -40,7 +40,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte var buf bytes.Buffer buf.WriteString("") - buf.WriteString(dav.BaseDirectory(directory, "")) + buf.WriteString(dav.BaseDirectory(addSlash(directory), "")) torrentNames := torrents.Keys() sort.Strings(torrentNames) for _, torrentName := range torrentNames { @@ -54,7 +54,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte return buf.Bytes(), nil } -func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) { +func ServeFilesListForDav(directory, torrentName string, torMgr *torrent.TorrentManager, shouldHideBrokenTorrents bool) ([]byte, error) { torrents, ok := torMgr.DirectoryMap.Get(directory) if !ok { return nil, fmt.Errorf("cannot find directory %s", directory) @@ -72,7 +72,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage var buf bytes.Buffer buf.WriteString("") - buf.WriteString(dav.BaseDirectory(filepath.Join(directory, torMgr.GetKey(tor)), tor.Added)) + buf.WriteString(dav.BaseDirectory(addSlash(filepath.Join(directory, torMgr.GetKey(tor))), tor.Added)) filenames := tor.SelectedFiles.Keys() sort.Strings(filenames) for _, filename := range filenames { @@ -114,13 +114,13 @@ func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.T var buf bytes.Buffer buf.WriteString("") - buf.WriteString(dav.BaseDirectory(filepath.Join(directory, torMgr.GetKey(tor)), tor.Added)) + buf.WriteString(dav.BaseDirectory(addSlash(filepath.Join(directory, torMgr.GetKey(tor))), tor.Added)) buf.WriteString(dav.File(fileName, file.Bytes, file.Ended)) buf.WriteString("") return buf.Bytes(), nil } -func ServeDownloadsList(torMgr *torrent.TorrentManager) ([]byte, error) { +func ServeDownloadsListForDav(torMgr *torrent.TorrentManager) ([]byte, error) { var buf bytes.Buffer buf.WriteString("") buf.WriteString(dav.BaseDirectory(config.DOWNLOADS, ""))