Refactors
This commit is contained in:
@@ -47,10 +47,9 @@ type RootResponse struct {
|
||||
TrafficServedPerAPI map[string]uint64 `json:"traffic_served_per_api"`
|
||||
}
|
||||
|
||||
func (zr *Handlers) generateResponse(resp http.ResponseWriter, req *http.Request) (*RootResponse, error) {
|
||||
func (zr *Handlers) generateResponse(req *http.Request) (*RootResponse, error) {
|
||||
userInfo, err := zr.rd.GetUserInformation()
|
||||
if err != nil {
|
||||
http.Error(resp, err.Error(), http.StatusInternalServerError)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -130,8 +129,9 @@ func (zr *Handlers) generateResponse(resp http.ResponseWriter, req *http.Request
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleHomeJson(resp http.ResponseWriter, req *http.Request) {
|
||||
response, err := zr.generateResponse(resp, req)
|
||||
response, err := zr.generateResponse(req)
|
||||
if err != nil {
|
||||
http.Error(resp, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (zr *Handlers) handleHomeJson(resp http.ResponseWriter, req *http.Request)
|
||||
}
|
||||
|
||||
func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
response, err := zr.generateResponse(resp, req)
|
||||
response, err := zr.generateResponse(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -102,17 +102,12 @@ 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", "/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.MethodFunc("PROPFIND", "/{mountType}/{directory}/{torrent}/{filename}", hs.checkSingleFileHandler)
|
||||
router.Delete("/{mountType}/{directory}/{torrent}/", hs.deleteTorrentHandler)
|
||||
router.Delete("/{mountType}/{directory}/{torrent}/{filename}", hs.deleteFileHandler)
|
||||
router.MethodFunc("MKCOL", "/{mountType}/{directory}/{torrent}/", hs.mkcolTorrentHandler)
|
||||
@@ -196,32 +191,19 @@ func (hs *Handlers) innerTorrentsListHandler(resp http.ResponseWriter, req *http
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleHttpTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
directory, err := url.PathUnescape(chi.URLParam(req, "directory"))
|
||||
if err != nil {
|
||||
directory = chi.URLParam(req, "directory")
|
||||
}
|
||||
handlerFunc := intHttp.ServeTorrentsList
|
||||
if directory == config.DOWNLOADS {
|
||||
handlerFunc = func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
return intHttp.ServeDownloadsList(torMgr)
|
||||
}
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/html; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, intHttp.ServeGroupDirectory, "text/html; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleDavTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := dav.ServeGroupDirectoryForDav
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, dav.ServeGroupDirectoryForDav, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleInfuseTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := dav.ServeGroupDirectoryForInfuse
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, dav.ServeGroupDirectoryForInfuse, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleVidHubTorrentsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := dav.ServeGroupDirectoryForVidHub
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, dav.ServeGroupDirectoryForVidHub, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
// handle files list request
|
||||
@@ -273,31 +255,19 @@ func (hs *Handlers) handleVidHubFilesList(resp http.ResponseWriter, req *http.Re
|
||||
// handle downloads list request
|
||||
|
||||
func (hs *Handlers) handleHttpDownloadsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
return intHttp.ServeDownloadsList(torMgr)
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/html; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, intHttp.ServeDownloadsList, "text/html; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleDavDownloadsList(resp http.ResponseWriter, req *http.Request) {
|
||||
handlerFunc := func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
return dav.ServeDownloadsForDav(torMgr)
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, dav.ServeDownloadsForDav, "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.ServeDownloadsForInfuse(torMgr)
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, dav.ServeDownloadsForInfuse, "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.ServeDownloadsForVidHub(torMgr)
|
||||
}
|
||||
hs.innerTorrentsListHandler(resp, req, handlerFunc, "text/xml; charset=\"utf-8\"")
|
||||
hs.innerTorrentsListHandler(resp, req, dav.ServeDownloadsForVidHub, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
// handle delete request
|
||||
|
||||
Reference in New Issue
Block a user