Refactor torrent manager

This commit is contained in:
Ben Sarmiento
2023-11-09 02:34:04 +01:00
parent 9dfd6c32d5
commit 15a0ba95d8
14 changed files with 436 additions and 516 deletions

View File

@@ -11,22 +11,14 @@ import (
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/dav"
"github.com/debridmediamanager.com/zurg/pkg/logutil"
"github.com/hashicorp/golang-lru/v2/expirable"
)
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface, cache *expirable.LRU[string, string]) {
func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface) {
log := logutil.NewLogger().Named("dav")
requestPath := path.Clean(r.URL.Path)
requestPath = strings.Trim(requestPath, "/")
if data, exists := cache.Get(requestPath); exists {
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
w.WriteHeader(http.StatusMultiStatus)
fmt.Fprint(w, data)
return
}
var output []byte
var err error
@@ -53,8 +45,6 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To
if output != nil {
respBody := fmt.Sprintf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n%s\n", output)
cache.Add(requestPath, respBody)
w.Header().Set("Content-Type", "text/xml; charset=\"utf-8\"")
w.WriteHeader(http.StatusMultiStatus)
fmt.Fprint(w, respBody)