Serve downloads list

This commit is contained in:
Ben Sarmiento
2024-01-07 23:44:26 +01:00
parent 57e6b0b860
commit 62de3723c1
4 changed files with 68 additions and 2 deletions

View File

@@ -57,6 +57,10 @@ func ApplyRouteTable(router *httprouter.Router, getfile *universal.GetFile, torM
router.GET("/dav/", zr.davRootHandler)
router.GET("/dav/:directory/", zr.davTorrentsListHandler)
router.GET("/dav/:directory/:torrent/", zr.davFilesListHandler)
// EXTRA: for browser handling of infuse
router.GET("/infuse/", zr.infuseDavRootHandler)
router.GET("/infuse/:directory/", zr.infuseDavTorrentsListHandler)
router.GET("/infuse/:directory/:torrent/", zr.infuseDavFilesListHandler)
// DELETE routes
router.DELETE("/dav/:directory/:torrent/", zr.deleteTorrentHandler)
router.DELETE("/dav/:directory/:torrent/:file", zr.deleteFileHandler)
@@ -129,11 +133,25 @@ func (zr *ZurgRouter) httpTorrentsListHandler(resp http.ResponseWriter, req *htt
}
func (zr *ZurgRouter) davTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
zr.handleTorrentsListRequest(resp, req, params, dav.ServeTorrentsList, "text/xml; charset=\"utf-8\"")
directory := params.ByName("directory")
handlerFunc := dav.ServeTorrentsList
if directory == config.DOWNLOADS {
handlerFunc = func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
return dav.ServeDownloadsList(torMgr)
}
}
zr.handleTorrentsListRequest(resp, req, params, handlerFunc, "text/xml; charset=\"utf-8\"")
}
func (zr *ZurgRouter) infuseDavTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
zr.handleTorrentsListRequest(resp, req, params, dav.ServeTorrentsListForInfuse, "text/xml; charset=\"utf-8\"")
directory := params.ByName("directory")
handlerFunc := dav.ServeTorrentsListForInfuse
if directory == config.DOWNLOADS {
handlerFunc = func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
return dav.ServeDownloadsListForInfuse(torMgr)
}
}
zr.handleTorrentsListRequest(resp, req, params, handlerFunc, "text/xml; charset=\"utf-8\"")
}
func (zr *ZurgRouter) handleFilesListRequest(resp http.ResponseWriter, req *http.Request, params httprouter.Params, handleFunc func(string, string, *torrent.TorrentManager) ([]byte, error), contentType string) {
@@ -158,6 +176,7 @@ func (zr *ZurgRouter) davFilesListHandler(resp http.ResponseWriter, req *http.Re
}
func (zr *ZurgRouter) infuseDavFilesListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
fmt.Println(">>>>>>>>>>>>>>>>>>> infuseDavFilesListHandler", params.ByName("directory"), params.ByName("torrent"))
zr.handleFilesListRequest(resp, req, params, dav.ServeFilesListForInfuse, "text/xml; charset=\"utf-8\"")
}