delete functionality
This commit is contained in:
@@ -10,26 +10,21 @@ import (
|
||||
|
||||
"github.com/debridmediamanager.com/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/dav"
|
||||
"github.com/debridmediamanager.com/zurg/pkg/logutil"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) {
|
||||
log := logutil.NewLogger().Named("dav")
|
||||
|
||||
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, log *zap.SugaredLogger) {
|
||||
requestPath := path.Clean(r.URL.Path)
|
||||
requestPath = strings.Trim(requestPath, "/")
|
||||
filteredSegments := splitIntoSegments(requestPath)
|
||||
|
||||
var err error
|
||||
|
||||
filteredSegments := strings.Split(requestPath, "/")
|
||||
|
||||
switch {
|
||||
case len(filteredSegments) == 1 && filteredSegments[0] == "":
|
||||
err = handleRoot(w, t)
|
||||
case len(filteredSegments) == 0:
|
||||
err = handleListDirectories(w, t)
|
||||
case len(filteredSegments) == 1:
|
||||
err = handleListOfTorrents(w, requestPath, t)
|
||||
err = handleListTorrents(w, requestPath, t)
|
||||
case len(filteredSegments) == 2:
|
||||
err = handleSingleTorrent(w, requestPath, t)
|
||||
err = handleListFiles(w, requestPath, t)
|
||||
default:
|
||||
log.Warnf("Request %s %s not found", r.Method, requestPath)
|
||||
http.Error(w, "Not Found", http.StatusNotFound)
|
||||
@@ -49,7 +44,7 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
|
||||
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
|
||||
}
|
||||
|
||||
func handleRoot(w http.ResponseWriter, t *torrent.TorrentManager) error {
|
||||
func handleListDirectories(w http.ResponseWriter, t *torrent.TorrentManager) error {
|
||||
fmt.Fprint(w, "<?xml?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
// initial response is the directory itself
|
||||
fmt.Fprint(w, dav.Directory("", ""))
|
||||
@@ -64,7 +59,7 @@ func handleRoot(w http.ResponseWriter, t *torrent.TorrentManager) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleListOfTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) error {
|
||||
func handleListTorrents(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) error {
|
||||
basePath := path.Base(requestPath)
|
||||
torrents, ok := t.DirectoryMap.Get(basePath)
|
||||
if !ok {
|
||||
@@ -73,7 +68,7 @@ func handleListOfTorrents(w http.ResponseWriter, requestPath string, t *torrent.
|
||||
|
||||
fmt.Fprint(w, "<?xml?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
// initial response is the directory itself
|
||||
fmt.Fprint(w, dav.Directory(basePath+"/", ""))
|
||||
fmt.Fprint(w, dav.Directory(basePath, ""))
|
||||
|
||||
var allTorrents []*torrent.Torrent
|
||||
torrents.IterCb(func(_ string, tor *torrent.Torrent) {
|
||||
@@ -91,7 +86,8 @@ func handleListOfTorrents(w http.ResponseWriter, requestPath string, t *torrent.
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSingleTorrent(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) error {
|
||||
func handleListFiles(w http.ResponseWriter, requestPath string, t *torrent.TorrentManager) error {
|
||||
requestPath = strings.TrimPrefix(requestPath, "/")
|
||||
basePath := path.Base(path.Dir(requestPath))
|
||||
torrents, ok := t.DirectoryMap.Get(basePath)
|
||||
if !ok {
|
||||
@@ -105,7 +101,7 @@ func handleSingleTorrent(w http.ResponseWriter, requestPath string, t *torrent.T
|
||||
|
||||
fmt.Fprint(w, "<?xml?><d:multistatus xmlns:d=\"DAV:\">")
|
||||
// initial response is the directory itself
|
||||
fmt.Fprint(w, dav.Directory(requestPath+"/", tor.LatestAdded))
|
||||
fmt.Fprint(w, dav.Directory(requestPath, tor.LatestAdded))
|
||||
|
||||
filenames := tor.SelectedFiles.Keys()
|
||||
sort.Strings(filenames)
|
||||
|
||||
Reference in New Issue
Block a user