Add VidHub endpoints

This commit is contained in:
Ben Adrian Sarmiento
2024-07-11 15:53:20 +02:00
parent f8f68e8225
commit 396a8781aa
10 changed files with 182 additions and 86 deletions

View File

@@ -28,6 +28,7 @@ type RootResponse struct {
Html string `json:"html"`
Dav string `json:"dav"`
Infuse string `json:"infuse"`
VidHub string `json:"vidhub"`
Logs string `json:"logs"`
UserInfo *realdebrid.User `json:"user_info"`
LibrarySize int `json:"library_size"` // Number of torrents in the library
@@ -104,6 +105,7 @@ func (zr *Handlers) generateResponse(resp http.ResponseWriter, req *http.Request
Html: fmt.Sprintf("//%s/http/", req.Host),
Dav: fmt.Sprintf("//%s/dav/", req.Host),
Infuse: fmt.Sprintf("//%s/infuse/", req.Host),
VidHub: fmt.Sprintf("//%s/vidhub/", req.Host),
Logs: fmt.Sprintf("//%s/logs/", req.Host),
UserInfo: userInfo,
TrafficServedPerAPI: trafficFromAPI,
@@ -255,6 +257,10 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
<td>Infuse</td>
<td colspan="2"><a href="%s">%s</a></td>
</tr>
<tr>
<td>VidHub</td>
<td colspan="2"><a href="%s">%s</a></td>
</tr>
<tr>
<td>Logs</td>
<td colspan="2"><a href="%s">%s</a></td>
@@ -268,6 +274,8 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
response.Dav,
response.Infuse,
response.Infuse,
response.VidHub,
response.VidHub,
response.Logs,
response.Logs,
)

View File

@@ -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)
}