Add VidHub endpoints
This commit is contained in:
@@ -50,6 +50,7 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
router.Use(hs.basicAuth)
|
||||
}
|
||||
router.Use(hs.options)
|
||||
router.NotFound(hs.handleNotFound)
|
||||
|
||||
router.Get("/", hs.handleHome)
|
||||
router.Get("/stats", hs.handleHomeJson)
|
||||
@@ -86,7 +87,6 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
router.MethodFunc("PROPFIND", fmt.Sprintf("/dav/%s/", config.DOWNLOADS), hs.handleDavDownloadsList)
|
||||
router.MethodFunc("PROPFIND", "/dav/{directory}/", hs.handleDavTorrentsList)
|
||||
router.MethodFunc("PROPFIND", "/dav/{directory}/{torrent}/", hs.handleDavFilesList)
|
||||
router.MethodFunc("PROPFIND", "/dav/{directory}/{torrent}/{filename}", hs.davCheckSingleFileHandler)
|
||||
|
||||
router.Get("/infuse/", hs.handleInfuseRoot)
|
||||
router.Get(fmt.Sprintf("/infuse/%s/", config.DOWNLOADS), hs.handleInfuseDownloadsList)
|
||||
@@ -102,13 +102,16 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
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)
|
||||
// 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", "/{mountType}/{directory}/{torrent}/{filename}", hs.checkSingleFileHandler)
|
||||
|
||||
// note: reused handlers for dav and infuse
|
||||
router.Delete("/{mountType}/{directory}/{torrent}/", hs.deleteTorrentHandler)
|
||||
router.Delete("/{mountType}/{directory}/{torrent}/{filename}", hs.deleteFileHandler)
|
||||
@@ -207,17 +210,17 @@ func (hs *Handlers) handleHttpTorrentsList(resp http.ResponseWriter, req *http.R
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleDavTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := dav.ServeTorrentsListForDav
|
||||
handlerFunc := dav.ServeGroupDirectoryForDav
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleInfuseTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := dav.ServeTorrentsListForInfuse
|
||||
handlerFunc := dav.ServeGroupDirectoryForInfuse
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleVidHubTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := dav.ServeTorrentsListForVidHub
|
||||
handlerFunc := dav.ServeGroupDirectoryForVidHub
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
@@ -256,15 +259,15 @@ 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.ServeFilesListForDav, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerFilesListHandler(resp, req, dav.ServeTorrentFilesForDav, "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\"")
|
||||
hs.innerFilesListHandler(resp, req, dav.ServeTorrentFilesForInfuse, "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\"")
|
||||
hs.innerFilesListHandler(resp, req, dav.ServeTorrentFilesForVidHub, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
// handle downloads list request
|
||||
@@ -278,21 +281,21 @@ 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.ServeDownloadsListForDav(torMgr)
|
||||
return dav.ServeDownloadsForDav(torMgr)
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleInfuseDownloadsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
return dav.ServeDownloadsListForInfuse(torMgr)
|
||||
return dav.ServeDownloadsForInfuse(torMgr)
|
||||
}
|
||||
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)
|
||||
return dav.ServeDownloadsForVidHub(torMgr)
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
@@ -337,7 +340,7 @@ func (hs *Handlers) deleteTorrentHandler(resp http.ResponseWriter, req *http.Req
|
||||
|
||||
// other handlers
|
||||
|
||||
func (hs *Handlers) davCheckSingleFileHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
func (hs *Handlers) checkSingleFileHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
directory, err := url.PathUnescape(chi.URLParam(req, "directory"))
|
||||
if err != nil {
|
||||
directory = chi.URLParam(req, "directory")
|
||||
@@ -494,3 +497,8 @@ func (hs *Handlers) uploadLogsHandler(resp http.ResponseWriter, req *http.Reques
|
||||
}
|
||||
http.Redirect(resp, req, url, http.StatusFound)
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleNotFound(resp http.ResponseWriter, req *http.Request) {
|
||||
hs.log.Debugf("Not found: %s %s", req.Method, req.URL)
|
||||
http.NotFound(resp, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user