Fix http mount
This commit is contained in:
@@ -42,10 +42,15 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
router.Use(optionsMiddleware)
|
||||
|
||||
router.Get("/", hs.handleHome)
|
||||
router.Get("/{mountType}/version.txt", hs.handleVersionFile)
|
||||
// version
|
||||
router.Get(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleVersionFile)
|
||||
router.Head(fmt.Sprintf("/{mountType}/%s", version.FILE), hs.handleCheckVersionFile)
|
||||
// download
|
||||
router.Get(fmt.Sprintf("/{mountType}/%s/{filename}", config.DOWNLOADS), hs.handleDownloadLink)
|
||||
router.Head(fmt.Sprintf("/{mountType}/%s/{filename}", config.DOWNLOADS), hs.handleCheckDownloadLink)
|
||||
// file
|
||||
router.Get("/{mountType}/{directory}/{torrent}/{filename}", hs.handleDownloadFile)
|
||||
router.Head("/{mountType}/{directory}/{torrent}/{filename}", hs.handleCheckCachedLink)
|
||||
router.Head("/{mountType}/{directory}/{torrent}/{filename}", hs.handleCheckFile)
|
||||
|
||||
router.Get("/http/", hs.handleHttpRoot)
|
||||
router.Get(fmt.Sprintf("/http/%s/", config.DOWNLOADS), hs.handleHttpDownloadsList)
|
||||
@@ -297,13 +302,6 @@ func (hs *Handlers) handleDownloadFile(resp http.ResponseWriter, req *http.Reque
|
||||
hs.downloader.DownloadFile(directory, torrentName, fileName, resp, req, hs.torMgr, hs.cfg, hs.log)
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleCheckCachedLink(resp http.ResponseWriter, req *http.Request) {
|
||||
directory := chi.URLParam(req, "directory")
|
||||
torrentName := chi.URLParam(req, "torrent")
|
||||
fileName := chi.URLParam(req, "filename")
|
||||
universal.HandleHeadRequest(directory, torrentName, fileName, resp, req, hs.torMgr, hs.log)
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleDownloadLink(resp http.ResponseWriter, req *http.Request) {
|
||||
filename := chi.URLParam(req, "filename")
|
||||
if download, ok := hs.torMgr.DownloadMap.Get(filename); ok {
|
||||
@@ -313,6 +311,22 @@ func (hs *Handlers) handleDownloadLink(resp http.ResponseWriter, req *http.Reque
|
||||
}
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleCheckFile(resp http.ResponseWriter, req *http.Request) {
|
||||
directory := chi.URLParam(req, "directory")
|
||||
torrentName := chi.URLParam(req, "torrent")
|
||||
fileName := chi.URLParam(req, "filename")
|
||||
universal.CheckFile(directory, torrentName, fileName, resp, req, hs.torMgr, hs.log)
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleCheckDownloadLink(resp http.ResponseWriter, req *http.Request) {
|
||||
filename := chi.URLParam(req, "filename")
|
||||
if download, ok := hs.torMgr.DownloadMap.Get(filename); ok {
|
||||
universal.CheckDownloadLink(download, resp, req, hs.torMgr, hs.log)
|
||||
} else {
|
||||
http.NotFound(resp, req)
|
||||
}
|
||||
}
|
||||
|
||||
// handle version file request
|
||||
|
||||
func (hs *Handlers) handleVersionFile(resp http.ResponseWriter, req *http.Request) {
|
||||
@@ -322,6 +336,10 @@ func (hs *Handlers) handleVersionFile(resp http.ResponseWriter, req *http.Reques
|
||||
resp.Write(out)
|
||||
}
|
||||
|
||||
func (hs *Handlers) handleCheckVersionFile(resp http.ResponseWriter, req *http.Request) {
|
||||
universal.CheckVersionFile(resp, req, hs.torMgr, hs.log)
|
||||
}
|
||||
|
||||
// logs handler
|
||||
|
||||
func (hs *Handlers) logsHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user