Add infuse route

This commit is contained in:
Ben Sarmiento
2023-12-12 02:00:25 +01:00
parent 2a1bc59300
commit d0ecaa0752
2 changed files with 131 additions and 7 deletions

View File

@@ -42,13 +42,13 @@ func ApplyRouteTable(router *httprouter.Router, getfile *universal.GetFile, torM
// dav router
router.GET("/dav/:directory/:torrent/:file", zr.universalDownloadFileHandler)
router.GET("/dav/:directory/:torrent/", zr.propfindTorrentHandler)
router.GET("/dav/:directory/", zr.propfindDirectoryHandler)
router.GET("/dav/", zr.propfindRootHandler)
// PROPFIND routes
router.Handle("PROPFIND", "/dav/:directory/:torrent/", zr.propfindTorrentHandler)
router.Handle("PROPFIND", "/dav/:directory/", zr.propfindDirectoryHandler)
router.Handle("PROPFIND", "/dav/", zr.propfindRootHandler)
// extras
router.GET("/dav/:directory/:torrent/", zr.propfindTorrentHandler)
router.GET("/dav/:directory/", zr.propfindDirectoryHandler)
router.GET("/dav/", zr.propfindRootHandler)
// DELETE routes
router.DELETE("/dav/:directory/:torrent/:file", zr.deleteFileHandler)
router.DELETE("/dav/:directory/:torrent/", zr.deleteTorrentHandler)
@@ -56,9 +56,14 @@ func ApplyRouteTable(router *httprouter.Router, getfile *universal.GetFile, torM
router.Handle("PROPFIND", "/dav/:directory/:torrent/:file", zr.propfindFileHandler)
router.Handle("MKCOL", "/dav/:directory/:torrent/", zr.mkcolTorrentHandler)
router.Handle("MOVE", "/dav/:directory/:torrent/:file", zr.moveFileHandler)
// MOVE routes
router.Handle("MOVE", "/dav/:directory/:torrent/", zr.moveTorrentHandler)
// infuse routes
router.GET("/infuse/:directory/:torrent/:file", zr.universalDownloadFileHandler)
router.Handle("PROPFIND", "/infuse/:directory/:torrent/", zr.propfindInfuseTorrentHandler)
router.Handle("PROPFIND", "/infuse/:directory/", zr.propfindInfuseDirectoryHandler)
router.Handle("PROPFIND", "/infuse/", zr.propfindInfuseRootHandler)
// Global OPTIONS route
router.GlobalOPTIONS = http.HandlerFunc(zr.globalOptionsHandler)
@@ -70,8 +75,8 @@ func ApplyRouteTable(router *httprouter.Router, getfile *universal.GetFile, torM
router.GET("/logs/", zr.logsHandler)
router.MethodNotAllowed = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
zr.log.Debugf("Method Not Allowed: %s %s %v", req.Method, req.URL, req.Header)
http.Error(resp, "Method Not Allowed", http.StatusMethodNotAllowed)
zr.log.Debugf("Method not allowed: %s %s %v", req.Method, req.URL, req.Header)
http.Error(resp, "Method not allowed", http.StatusMethodNotAllowed)
})
}
@@ -127,6 +132,42 @@ func (zr *ZurgRouter) propfindFileHandler(resp http.ResponseWriter, req *http.Re
resp.Write(out)
}
func (zr *ZurgRouter) propfindInfuseTorrentHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
directory := params.ByName("directory")
torrentName := params.ByName("torrent")
out, err := dav.HandleInfuseListFiles(directory, torrentName, zr.torMgr, zr.log)
if err != nil {
http.Error(resp, "Not Found", http.StatusNotFound)
return
}
resp.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
resp.WriteHeader(http.StatusOK)
resp.Write(out)
}
func (zr *ZurgRouter) propfindInfuseDirectoryHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
directory := params.ByName("directory")
out, err := dav.HandleInfuseListTorrents(directory, zr.torMgr, zr.log)
if err != nil {
http.Error(resp, "Not Found", http.StatusNotFound)
return
}
resp.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
resp.WriteHeader(http.StatusOK)
resp.Write(out)
}
func (zr *ZurgRouter) propfindInfuseRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
out, err := dav.HandleInfuseListDirectories(zr.torMgr)
if err != nil {
http.Error(resp, "Not Found", http.StatusNotFound)
return
}
resp.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
resp.WriteHeader(http.StatusOK)
resp.Write(out)
}
func (zr *ZurgRouter) propfindTorrentHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
directory := params.ByName("directory")
torrentName := params.ByName("torrent")