diff --git a/internal/handlers/router.go b/internal/handlers/router.go index 69d24a2..644d9f6 100644 --- a/internal/handlers/router.go +++ b/internal/handlers/router.go @@ -97,6 +97,18 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t router.MethodFunc("PROPFIND", "/infuse/{directory}/", hs.handleInfuseTorrentsList) router.MethodFunc("PROPFIND", "/infuse/{directory}/{torrent}/", hs.handleInfuseFilesList) + router.Get("/vidhub/", hs.handleVidHubRoot) + router.Get(fmt.Sprintf("/vidhub/%s/", config.DOWNLOADS), hs.handleVidHubDownloadsList) + router.Get("/vidhub/{directory}/", hs.handleVidHubTorrentsList) + router.Get("/vidhub/{directory}/{torrent}/", hs.handleVidHubFilesList) + router.MethodFunc("PROPFIND", "/vidhub/", hs.handleVidHubRoot) + router.MethodFunc("PROPFIND", fmt.Sprintf("/vidhub/%s/", config.DOWNLOADS), hs.handleVidHubDownloadsList) + router.MethodFunc("PROPFIND", "/vidhub/{directory}/", hs.handleVidHubTorrentsList) + router.MethodFunc("PROPFIND", "/vidhub/{directory}/{torrent}/", hs.handleVidHubFilesList) + router.MethodFunc("PROPFIND", fmt.Sprintf("/vidhub/%s", config.DOWNLOADS), hs.handleVidHubDownloadsList) + router.MethodFunc("PROPFIND", "/vidhub/{directory}", hs.handleVidHubTorrentsList) + router.MethodFunc("PROPFIND", "/vidhub/{directory}/{torrent}", hs.handleVidHubFilesList) + // note: reused handlers for dav and infuse router.Delete("/{mountType}/{directory}/{torrent}/", hs.deleteTorrentHandler) router.Delete("/{mountType}/{directory}/{torrent}/{filename}", hs.deleteFileHandler) @@ -143,13 +155,17 @@ func (hs *Handlers) handleHttpRoot(resp http.ResponseWriter, req *http.Request) } func (hs *Handlers) handleDavRoot(resp http.ResponseWriter, req *http.Request) { - hs.innerRootHandler(resp, req, dav.ServeRootDirectory, "text/xml; charset=\"utf-8\"") + hs.innerRootHandler(resp, req, dav.ServeRootDirectoryForDav, "text/xml; charset=\"utf-8\"") } func (hs *Handlers) handleInfuseRoot(resp http.ResponseWriter, req *http.Request) { hs.innerRootHandler(resp, req, dav.ServeRootDirectoryForInfuse, "text/xml; charset=\"utf-8\"") } +func (hs *Handlers) handleVidHubRoot(resp http.ResponseWriter, req *http.Request) { + hs.innerRootHandler(resp, req, dav.ServeRootDirectoryForVidHub, "text/xml; charset=\"utf-8\"") +} + // handle torrent list request func (hs *Handlers) innerTorrentsListHandler(resp http.ResponseWriter, req *http.Request, handleFunc func(string, *torrent.TorrentManager) ([]byte, error), contentType string) { @@ -191,30 +207,17 @@ func (hs *Handlers) handleHttpTorrentsList(resp http.ResponseWriter, req *http.R } func (hs *Handlers) handleDavTorrentsList(resp http.ResponseWriter, req *http.Request) { - directory, err := url.PathUnescape(chi.URLParam(req, "directory")) - if err != nil { - directory = chi.URLParam(req, "directory") - } - handlerFunc := dav.ServeTorrentsList - if directory == config.DOWNLOADS { - handlerFunc = func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) { - return dav.ServeDownloadsList(torMgr) - } - } + handlerFunc := dav.ServeTorrentsListForDav hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"") } func (hs *Handlers) handleInfuseTorrentsList(resp http.ResponseWriter, req *http.Request) { - directory, err := url.PathUnescape(chi.URLParam(req, "directory")) - if err != nil { - directory = chi.URLParam(req, "directory") - } handlerFunc := dav.ServeTorrentsListForInfuse - if directory == config.DOWNLOADS { - handlerFunc = func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) { - return dav.ServeDownloadsListForInfuse(torMgr) - } - } + hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"") +} + +func (hs *Handlers) handleVidHubTorrentsList(resp http.ResponseWriter, req *http.Request) { + handlerFunc := dav.ServeTorrentsListForVidHub hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"") } @@ -253,13 +256,17 @@ func (hs *Handlers) handleHttpFilesList(resp http.ResponseWriter, req *http.Requ } func (hs *Handlers) handleDavFilesList(resp http.ResponseWriter, req *http.Request) { - hs.innerFilesListHandler(resp, req, dav.ServeFilesList, "text/xml; charset=\"utf-8\"") + hs.innerFilesListHandler(resp, req, dav.ServeFilesListForDav, "text/xml; charset=\"utf-8\"") } func (hs *Handlers) handleInfuseFilesList(resp http.ResponseWriter, req *http.Request) { hs.innerFilesListHandler(resp, req, dav.ServeFilesListForInfuse, "text/xml; charset=\"utf-8\"") } +func (hs *Handlers) handleVidHubFilesList(resp http.ResponseWriter, req *http.Request) { + hs.innerFilesListHandler(resp, req, dav.ServeFilesListForVidHub, "text/xml; charset=\"utf-8\"") +} + // handle downloads list request func (hs *Handlers) handleHttpDownloadsList(resp http.ResponseWriter, req *http.Request) { @@ -271,7 +278,7 @@ func (hs *Handlers) handleHttpDownloadsList(resp http.ResponseWriter, req *http. func (hs *Handlers) handleDavDownloadsList(resp http.ResponseWriter, req *http.Request) { handlerFunc := func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) { - return dav.ServeDownloadsList(torMgr) + return dav.ServeDownloadsListForDav(torMgr) } hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"") } @@ -283,6 +290,13 @@ func (hs *Handlers) handleInfuseDownloadsList(resp http.ResponseWriter, req *htt hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"") } +func (hs *Handlers) handleVidHubDownloadsList(resp http.ResponseWriter, req *http.Request) { + handlerFunc := func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) { + return dav.ServeDownloadsListForVidHub(torMgr) + } + hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"") +} + // handle delete request func (hs *Handlers) deleteFileHandler(resp http.ResponseWriter, req *http.Request) {