Add downloads dir to http, not sure if working
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
const (
|
||||
ALL_TORRENTS = "__all__"
|
||||
UNPLAYABLE_TORRENTS = "__unplayable__"
|
||||
DOWNLOADS = "__downloads__"
|
||||
)
|
||||
|
||||
func loadV1Config(content []byte, log *logutil.Logger) (*ZurgConfigV1, error) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager/zurg/pkg/dav"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
)
|
||||
|
||||
func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
@@ -27,7 +26,7 @@ func ServeRootDirectoryForInfuse(torMgr *torrent.TorrentManager) ([]byte, error)
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -48,7 +47,7 @@ func ServeTorrentsListForInfuse(directory string, torMgr *torrent.TorrentManager
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager/zurg/pkg/dav"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
)
|
||||
|
||||
func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
@@ -29,7 +28,7 @@ func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -51,7 +50,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager, log *lo
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -92,7 +91,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
)
|
||||
|
||||
func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
@@ -25,11 +24,14 @@ func ServeRootDirectory(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
directoryPath := url.PathEscape(directory)
|
||||
buf.WriteString(fmt.Sprintf("<li><a href=\"/http/%s/\">%s</a></li>", directoryPath, directory))
|
||||
}
|
||||
if torMgr.Config.GetConfig().UseDownloadCache {
|
||||
buf.WriteString(fmt.Sprintf("<li><a href=\"/http/%s/\">%s</a></li>", config.DOWNLOADS, config.DOWNLOADS))
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -49,7 +51,7 @@ func ServeTorrentsList(directory string, torMgr *torrent.TorrentManager, log *lo
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager, log *logutil.Logger) ([]byte, error) {
|
||||
func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cannot find directory %s", directory)
|
||||
@@ -88,3 +90,16 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func ServeDownloadsList(torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
if !torMgr.Config.GetConfig().UseDownloadCache {
|
||||
buf.WriteString("Enable download cache in config to use this feature")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
buf.WriteString("<ol>")
|
||||
for _, download := range torMgr.DownloadCache.Items() {
|
||||
buf.WriteString(fmt.Sprintf("<li><a href=\"%s\">%s</a></li>", download.Download, download.Filename))
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ func (zr *ZurgRouter) infuseDavRootHandler(resp http.ResponseWriter, req *http.R
|
||||
zr.handleRootRequest(resp, req, params, dav.ServeRootDirectoryForInfuse, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (zr *ZurgRouter) handleTorrentsListRequest(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) ([]byte, error), contentType string) {
|
||||
directory := params.ByName("directory")
|
||||
out, err := handleFunc(directory, zr.torMgr, zr.log)
|
||||
out, err := handleFunc(directory, zr.torMgr)
|
||||
if err != nil {
|
||||
http.Error(resp, "Not Found", http.StatusNotFound)
|
||||
return
|
||||
@@ -118,7 +118,14 @@ func (zr *ZurgRouter) handleTorrentsListRequest(resp http.ResponseWriter, req *h
|
||||
}
|
||||
|
||||
func (zr *ZurgRouter) httpTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||
zr.handleTorrentsListRequest(resp, req, params, intHttp.ServeTorrentsList, "text/html; charset=\"utf-8\"")
|
||||
directory := params.ByName("directory")
|
||||
handlerFunc := intHttp.ServeTorrentsList
|
||||
if directory == config.DOWNLOADS {
|
||||
handlerFunc = func(_ string, torMgr *torrent.TorrentManager) ([]byte, error) {
|
||||
return intHttp.ServeDownloadsList(torMgr)
|
||||
}
|
||||
}
|
||||
zr.handleTorrentsListRequest(resp, req, params, handlerFunc, "text/html; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func (zr *ZurgRouter) davTorrentsListHandler(resp http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
||||
@@ -129,10 +136,10 @@ func (zr *ZurgRouter) infuseDavTorrentsListHandler(resp http.ResponseWriter, req
|
||||
zr.handleTorrentsListRequest(resp, req, params, dav.ServeTorrentsListForInfuse, "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
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) {
|
||||
func (zr *ZurgRouter) handleFilesListRequest(resp http.ResponseWriter, req *http.Request, params httprouter.Params, handleFunc func(string, string, *torrent.TorrentManager) ([]byte, error), contentType string) {
|
||||
directory := params.ByName("directory")
|
||||
torrentName := params.ByName("torrent")
|
||||
out, err := handleFunc(directory, torrentName, zr.torMgr, zr.log)
|
||||
out, err := handleFunc(directory, torrentName, zr.torMgr)
|
||||
if err != nil {
|
||||
http.Error(resp, "Not Found", http.StatusNotFound)
|
||||
return
|
||||
@@ -179,7 +186,7 @@ func (zr *ZurgRouter) davCheckSingleFileHandler(resp http.ResponseWriter, req *h
|
||||
directory := params.ByName("directory")
|
||||
torrentName := params.ByName("torrent")
|
||||
fileName := params.ByName("file")
|
||||
out, err := dav.HandleSingleFile(directory, torrentName, fileName, zr.torMgr, zr.log)
|
||||
out, err := dav.HandleSingleFile(directory, torrentName, fileName, zr.torMgr)
|
||||
if err != nil {
|
||||
fmt.Println(">>>>>>>>>>>>>>>>>>>. not found", err)
|
||||
http.Error(resp, "Not Found", http.StatusNotFound)
|
||||
|
||||
Reference in New Issue
Block a user