Refactor routing
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleInfuseListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
|
func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||||
directories := torMgr.DirectoryMap.Keys()
|
directories := torMgr.DirectoryMap.Keys()
|
||||||
@@ -27,7 +27,7 @@ func HandleInfuseListDirectories(torMgr *torrent.TorrentManager) ([]byte, error)
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleInfuseListTorrents(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
@@ -48,7 +48,7 @@ func HandleInfuseListTorrents(directory string, torMgr *torrent.TorrentManager,
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleInfuseListFiles(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
|
func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
buf.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">")
|
||||||
buf.WriteString(dav.BaseDirectory("", ""))
|
buf.WriteString(dav.BaseDirectory("", ""))
|
||||||
@@ -29,7 +29,7 @@ func HandleListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
@@ -51,7 +51,7 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
@@ -86,7 +86,7 @@ func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManag
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandlePropfindFile(directory, torrentName, fileName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
|
func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString("<ol>")
|
buf.WriteString("<ol>")
|
||||||
directories := torMgr.DirectoryMap.Keys()
|
directories := torMgr.DirectoryMap.Keys()
|
||||||
@@ -29,7 +29,7 @@ func HandleListDirectories(torMgr *torrent.TorrentManager) ([]byte, error) {
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
@@ -49,7 +49,7 @@ func HandleListTorrents(directory string, torMgr *torrent.TorrentManager, log *l
|
|||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleListFiles(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||||
|
|||||||
@@ -32,39 +32,39 @@ func ApplyRouteTable(router *httprouter.Router, getfile *universal.GetFile, torM
|
|||||||
log: log,
|
log: log,
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP router
|
|
||||||
router.GET("/http/:directory/:torrent/", zr.httpTorrentHandler)
|
|
||||||
router.GET("/http/:directory/", zr.httpDirectoryHandler)
|
|
||||||
router.GET("/http/", zr.httpRootHandler)
|
|
||||||
|
|
||||||
// WEBDAV router
|
|
||||||
router.Handle("PROPFIND", "/dav/:directory/:torrent/", zr.davTorrentHandler)
|
|
||||||
router.Handle("PROPFIND", "/dav/:directory/", zr.davDirectoryHandler)
|
|
||||||
router.Handle("PROPFIND", "/dav/", zr.davRootHandler)
|
|
||||||
// EXTRA: for browser handling
|
|
||||||
router.GET("/dav/:directory/:torrent/", zr.davTorrentHandler)
|
|
||||||
router.GET("/dav/:directory/", zr.davDirectoryHandler)
|
|
||||||
router.GET("/dav/", zr.davRootHandler)
|
|
||||||
// DELETE routes
|
|
||||||
router.DELETE("/dav/:directory/:torrent/:file", zr.deleteFileHandler)
|
|
||||||
router.DELETE("/dav/:directory/:torrent/", zr.deleteTorrentHandler)
|
|
||||||
// RENAME sequence
|
|
||||||
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)
|
|
||||||
router.Handle("MOVE", "/dav/:directory/:torrent/", zr.moveTorrentHandler)
|
|
||||||
|
|
||||||
// INFUSE DAV routes
|
|
||||||
router.Handle("PROPFIND", "/infuse/:directory/:torrent/", zr.infuseDavTorrentHandler)
|
|
||||||
router.Handle("PROPFIND", "/infuse/:directory/", zr.infuseDavDirectoryHandler)
|
|
||||||
router.Handle("PROPFIND", "/infuse/", zr.infuseDavRootHandler)
|
|
||||||
|
|
||||||
// file download handler
|
// file download handler
|
||||||
router.GET("/http/:directory/:torrent/:file", zr.universalDownloadFileHandler)
|
router.GET("/http/:directory/:torrent/:file", zr.universalDownloadFileHandler)
|
||||||
router.GET("/dav/:directory/:torrent/:file", zr.universalDownloadFileHandler)
|
router.GET("/dav/:directory/:torrent/:file", zr.universalDownloadFileHandler)
|
||||||
router.GET("/infuse/:directory/:torrent/:file", zr.universalDownloadFileHandler)
|
router.GET("/infuse/:directory/:torrent/:file", zr.universalDownloadFileHandler)
|
||||||
// HEAD route
|
// HEAD route
|
||||||
router.HEAD("/http/:directory/:torrent/:file", zr.headHandler)
|
router.HEAD("/http/:directory/:torrent/:file", zr.httpHeadHandler)
|
||||||
|
|
||||||
|
// HTTP router
|
||||||
|
router.GET("/http/", zr.httpRootHandler)
|
||||||
|
router.GET("/http/:directory/", zr.httpTorrentsListHandler)
|
||||||
|
router.GET("/http/:directory/:torrent/", zr.httpFilesListHandler)
|
||||||
|
|
||||||
|
// INFUSE DAV routes
|
||||||
|
router.Handle("PROPFIND", "/infuse/", zr.infuseDavRootHandler)
|
||||||
|
router.Handle("PROPFIND", "/infuse/:directory/", zr.infuseDavTorrentsListHandler)
|
||||||
|
router.Handle("PROPFIND", "/infuse/:directory/:torrent/", zr.infuseDavFilesListHandler)
|
||||||
|
|
||||||
|
// WEBDAV router
|
||||||
|
router.Handle("PROPFIND", "/dav/", zr.davRootHandler)
|
||||||
|
router.Handle("PROPFIND", "/dav/:directory/", zr.davTorrentsListHandler)
|
||||||
|
router.Handle("PROPFIND", "/dav/:directory/:torrent/", zr.davFilesListHandler)
|
||||||
|
// EXTRA: for browser handling
|
||||||
|
router.GET("/dav/", zr.davRootHandler)
|
||||||
|
router.GET("/dav/:directory/", zr.davTorrentsListHandler)
|
||||||
|
router.GET("/dav/:directory/:torrent/", zr.davFilesListHandler)
|
||||||
|
// DELETE routes
|
||||||
|
router.DELETE("/dav/:directory/:torrent/", zr.deleteTorrentHandler)
|
||||||
|
router.DELETE("/dav/:directory/:torrent/:file", zr.deleteFileHandler)
|
||||||
|
// RENAME sequence
|
||||||
|
router.Handle("PROPFIND", "/dav/:directory/:torrent/:file", zr.davCheckSingleFileHandler)
|
||||||
|
router.Handle("MKCOL", "/dav/:directory/:torrent/", zr.mkcolTorrentHandler)
|
||||||
|
router.Handle("MOVE", "/dav/:directory/:torrent/:file", zr.moveFileHandler)
|
||||||
|
router.Handle("MOVE", "/dav/:directory/:torrent/", zr.moveTorrentHandler)
|
||||||
|
|
||||||
// Global OPTIONS route
|
// Global OPTIONS route
|
||||||
router.GlobalOPTIONS = http.HandlerFunc(zr.globalOptionsHandler)
|
router.GlobalOPTIONS = http.HandlerFunc(zr.globalOptionsHandler)
|
||||||
@@ -94,18 +94,18 @@ func (zr *ZurgRouter) handleRootRequest(resp http.ResponseWriter, req *http.Requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) httpRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) httpRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleRootRequest(resp, req, params, intHttp.HandleListDirectories, "text/html; charset=\"utf-8\"")
|
zr.handleRootRequest(resp, req, params, intHttp.ServeRootDirectory, "text/html; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) davRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) davRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleRootRequest(resp, req, params, dav.HandleListDirectories, "text/xml; charset=\"utf-8\"")
|
zr.handleRootRequest(resp, req, params, dav.ServeRootDirectory, "text/xml; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) infuseDavRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) infuseDavRootHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleRootRequest(resp, req, params, dav.HandleInfuseListDirectories, "text/xml; charset=\"utf-8\"")
|
zr.handleRootRequest(resp, req, params, dav.ServeRootDirectoryForInfuse, "text/xml; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) handleDirectoryRequest(resp http.ResponseWriter, req *http.Request, params httprouter.Params, handleFunc func(string, *torrent.TorrentManager, *logutil.Logger) ([]byte, error), contentType string) {
|
func (zr *ZurgRouter) handleTorrentsListRequest(resp http.ResponseWriter, req *http.Request, params httprouter.Params, handleFunc func(string, *torrent.TorrentManager, *logutil.Logger) ([]byte, error), contentType string) {
|
||||||
directory := params.ByName("directory")
|
directory := params.ByName("directory")
|
||||||
out, err := handleFunc(directory, zr.torMgr, zr.log)
|
out, err := handleFunc(directory, zr.torMgr, zr.log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -117,19 +117,19 @@ func (zr *ZurgRouter) handleDirectoryRequest(resp http.ResponseWriter, req *http
|
|||||||
resp.Write(out)
|
resp.Write(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) httpDirectoryHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) httpTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleDirectoryRequest(resp, req, params, intHttp.HandleListTorrents, "text/html; charset=\"utf-8\"")
|
zr.handleTorrentsListRequest(resp, req, params, intHttp.ServeTorrentsList, "text/html; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) davDirectoryHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) davTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleDirectoryRequest(resp, req, params, dav.HandleListTorrents, "text/xml; charset=\"utf-8\"")
|
zr.handleTorrentsListRequest(resp, req, params, dav.ServeTorrentsList, "text/xml; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) infuseDavDirectoryHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) infuseDavTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleDirectoryRequest(resp, req, params, dav.HandleInfuseListTorrents, "text/xml; charset=\"utf-8\"")
|
zr.handleTorrentsListRequest(resp, req, params, dav.ServeTorrentsListForInfuse, "text/xml; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) handleTorrentRequest(resp http.ResponseWriter, req *http.Request, params httprouter.Params, handleFunc func(string, string, *torrent.TorrentManager, *logutil.Logger) ([]byte, error), contentType string) {
|
func (zr *ZurgRouter) handleFilesListRequest(resp http.ResponseWriter, req *http.Request, params httprouter.Params, handleFunc func(string, string, *torrent.TorrentManager, *logutil.Logger) ([]byte, error), contentType string) {
|
||||||
directory := params.ByName("directory")
|
directory := params.ByName("directory")
|
||||||
torrentName := params.ByName("torrent")
|
torrentName := params.ByName("torrent")
|
||||||
out, err := handleFunc(directory, torrentName, zr.torMgr, zr.log)
|
out, err := handleFunc(directory, torrentName, zr.torMgr, zr.log)
|
||||||
@@ -142,16 +142,16 @@ func (zr *ZurgRouter) handleTorrentRequest(resp http.ResponseWriter, req *http.R
|
|||||||
resp.Write(out)
|
resp.Write(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) httpTorrentHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) httpFilesListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleTorrentRequest(resp, req, params, intHttp.HandleListFiles, "text/html; charset=\"utf-8\"")
|
zr.handleFilesListRequest(resp, req, params, intHttp.ServeFilesList, "text/html; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) davTorrentHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) davFilesListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleTorrentRequest(resp, req, params, dav.HandleListFiles, "text/xml; charset=\"utf-8\"")
|
zr.handleFilesListRequest(resp, req, params, dav.ServeFilesList, "text/xml; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) infuseDavTorrentHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) infuseDavFilesListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
zr.handleTorrentRequest(resp, req, params, dav.HandleInfuseListFiles, "text/xml; charset=\"utf-8\"")
|
zr.handleFilesListRequest(resp, req, params, dav.ServeFilesListForInfuse, "text/xml; charset=\"utf-8\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) deleteFileHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) deleteFileHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
@@ -175,11 +175,11 @@ func (zr *ZurgRouter) deleteTorrentHandler(resp http.ResponseWriter, req *http.R
|
|||||||
resp.WriteHeader(http.StatusNoContent)
|
resp.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) propfindFileHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) davCheckSingleFileHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
directory := params.ByName("directory")
|
directory := params.ByName("directory")
|
||||||
torrentName := params.ByName("torrent")
|
torrentName := params.ByName("torrent")
|
||||||
fileName := params.ByName("file")
|
fileName := params.ByName("file")
|
||||||
out, err := dav.HandlePropfindFile(directory, torrentName, fileName, zr.torMgr, zr.log)
|
out, err := dav.HandleSingleFile(directory, torrentName, fileName, zr.torMgr, zr.log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(">>>>>>>>>>>>>>>>>>>. not found", err)
|
fmt.Println(">>>>>>>>>>>>>>>>>>>. not found", err)
|
||||||
http.Error(resp, "Not Found", http.StatusNotFound)
|
http.Error(resp, "Not Found", http.StatusNotFound)
|
||||||
@@ -232,10 +232,10 @@ func (zr *ZurgRouter) universalDownloadFileHandler(resp http.ResponseWriter, req
|
|||||||
directory := params.ByName("directory")
|
directory := params.ByName("directory")
|
||||||
torrentName := params.ByName("torrent")
|
torrentName := params.ByName("torrent")
|
||||||
fileName := params.ByName("file")
|
fileName := params.ByName("file")
|
||||||
zr.getfile.HandleGetRequest(directory, torrentName, fileName, resp, req, zr.torMgr, zr.cfg, zr.log)
|
zr.getfile.ServeFile(directory, torrentName, fileName, resp, req, zr.torMgr, zr.cfg, zr.log)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zr *ZurgRouter) headHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
func (zr *ZurgRouter) httpHeadHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||||
directory := params.ByName("directory")
|
directory := params.ByName("directory")
|
||||||
torrentName := params.ByName("torrent")
|
torrentName := params.ByName("torrent")
|
||||||
fileName := params.ByName("file")
|
fileName := params.ByName("file")
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ func NewGetFile(client *zurghttp.HTTPClient) *GetFile {
|
|||||||
return &GetFile{client: client}
|
return &GetFile{client: client}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleGetRequest handles a GET request universally for both WebDAV and HTTP
|
// ServeFile handles a GET request universally for both WebDAV and HTTP
|
||||||
func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, resp http.ResponseWriter, req *http.Request, torMgr *intTor.TorrentManager, cfg config.ConfigInterface, log *logutil.Logger) {
|
func (gf *GetFile) ServeFile(directory, torrentName, fileName string, resp http.ResponseWriter, req *http.Request, torMgr *intTor.TorrentManager, cfg config.ConfigInterface, log *logutil.Logger) {
|
||||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Warnf("Cannot find directory %s", directory)
|
log.Warnf("Cannot find directory %s", directory)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
// optimized versions, no more marshalling
|
// optimized versions, no more marshalling
|
||||||
|
|
||||||
func BaseDirectory(path, added string) string {
|
func BaseDirectory(path, added string) string {
|
||||||
return fmt.Sprintf("<d:response><d:href>/%s</d:href><d:propstat><d:prop><d:resourcetype><d:collection/></d:resourcetype><d:getlastmodified>%s</d:getlastmodified></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape(path), added)
|
return fmt.Sprintf("<d:response><d:href>/%s</d:href><d:propstat><d:prop><d:resourcetype><d:collection/></d:resourcetype><d:getlastmodified>%s</d:getlastmodified><d:getcontenttype>httpd/unix-directory</d:getcontenttype></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape(path), added)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Directory(path, added string) string {
|
func Directory(path, added string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user