Repairs
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/internal/dav"
|
||||
@@ -100,12 +101,20 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
|
||||
func (hs *Handlers) innerRootHandler(resp http.ResponseWriter, req *http.Request, handleFunc func(*torrent.TorrentManager) ([]byte, error), contentType string) {
|
||||
out, err := handleFunc(hs.torMgr)
|
||||
if err != nil {
|
||||
if err != nil && strings.Contains(contentType, "xml") {
|
||||
resp.WriteHeader(http.StatusNotImplemented)
|
||||
resp.Write([]byte("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:error xmlns:d=\"DAV:\" xmlns:s=\"DAV\"><s:exception>NotImplemented</s:exception><s:message>Not Implemented Method</s:message></d:error>"))
|
||||
return
|
||||
} else if err != nil {
|
||||
http.NotFound(resp, req)
|
||||
return
|
||||
}
|
||||
resp.Header().Set("Content-Type", contentType)
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
if strings.Contains(contentType, "xml") {
|
||||
resp.WriteHeader(http.StatusMultiStatus)
|
||||
} else {
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
}
|
||||
resp.Write(out)
|
||||
}
|
||||
|
||||
@@ -126,12 +135,20 @@ func (hs *Handlers) handleInfuseRoot(resp http.ResponseWriter, req *http.Request
|
||||
func (hs *Handlers) innerTorrentsListHandler(resp http.ResponseWriter, req *http.Request, handleFunc func(string, *torrent.TorrentManager) ([]byte, error), contentType string) {
|
||||
directory := chi.URLParam(req, "directory")
|
||||
out, err := handleFunc(directory, hs.torMgr)
|
||||
if err != nil {
|
||||
if err != nil && strings.Contains(contentType, "xml") {
|
||||
resp.WriteHeader(http.StatusNotImplemented)
|
||||
resp.Write([]byte("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:error xmlns:d=\"DAV:\" xmlns:s=\"DAV\"><s:exception>NotImplemented</s:exception><s:message>Not Implemented Method</s:message></d:error>"))
|
||||
return
|
||||
} else if err != nil {
|
||||
http.NotFound(resp, req)
|
||||
return
|
||||
}
|
||||
resp.Header().Set("Content-Type", contentType)
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
if strings.Contains(contentType, "xml") {
|
||||
resp.WriteHeader(http.StatusMultiStatus)
|
||||
} else {
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
}
|
||||
resp.Write(out)
|
||||
}
|
||||
|
||||
@@ -174,12 +191,20 @@ func (hs *Handlers) innerFilesListHandler(resp http.ResponseWriter, req *http.Re
|
||||
directory := chi.URLParam(req, "directory")
|
||||
torrentName := chi.URLParam(req, "torrent")
|
||||
out, err := handleFunc(directory, torrentName, hs.torMgr)
|
||||
if err != nil {
|
||||
if err != nil && strings.Contains(contentType, "xml") {
|
||||
resp.WriteHeader(http.StatusNotImplemented)
|
||||
resp.Write([]byte("<?xml version=\"1.0\" encoding=\"utf-8\"?><d:error xmlns:d=\"DAV:\" xmlns:s=\"DAV\"><s:exception>NotImplemented</s:exception><s:message>Not Implemented Method</s:message></d:error>"))
|
||||
return
|
||||
} else if err != nil {
|
||||
http.NotFound(resp, req)
|
||||
return
|
||||
}
|
||||
resp.Header().Set("Content-Type", contentType)
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
if strings.Contains(contentType, "xml") {
|
||||
resp.WriteHeader(http.StatusMultiStatus)
|
||||
} else {
|
||||
resp.WriteHeader(http.StatusOK)
|
||||
}
|
||||
resp.Write(out)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user