From 81d1df9bb5d53b1c30208f28be20a0a6bc83d564 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 19 Nov 2023 02:55:19 +0100 Subject: [PATCH] Last batch of optimizations --- .github/workflows/{build.yml => build.yml.bak} | 0 .github/workflows/build_docker.yml | 2 +- internal/dav/listing.go | 12 +++++++----- internal/http/listing.go | 14 +++++++------- internal/net/router.go | 4 ++-- internal/universal/get.go | 4 ++-- 6 files changed, 19 insertions(+), 17 deletions(-) rename .github/workflows/{build.yml => build.yml.bak} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml.bak similarity index 100% rename from .github/workflows/build.yml rename to .github/workflows/build.yml.bak diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index e792dfc..1b4e1f6 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -14,7 +14,7 @@ env: jobs: build-and-push-image: - runs-on: ubuntu-latest + runs-on: self-hosted permissions: contents: read packages: write diff --git a/internal/dav/listing.go b/internal/dav/listing.go index 2cacc5d..e8c79e4 100644 --- a/internal/dav/listing.go +++ b/internal/dav/listing.go @@ -9,13 +9,12 @@ import ( "sort" "strings" - "github.com/debridmediamanager.com/zurg/internal/config" "github.com/debridmediamanager.com/zurg/internal/torrent" "github.com/debridmediamanager.com/zurg/pkg/dav" "github.com/debridmediamanager.com/zurg/pkg/logutil" ) -func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface) { +func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) { log := logutil.NewLogger().Named("dav") requestPath := path.Clean(r.URL.Path) @@ -28,7 +27,7 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To switch { case len(filteredSegments) == 1 && filteredSegments[0] == "": - output, err = handleRoot(c) + output, err = handleRoot(t) case len(filteredSegments) == 1: output, err = handleListOfTorrents(requestPath, t) case len(filteredSegments) == 2: @@ -57,10 +56,13 @@ func HandlePropfindRequest(w http.ResponseWriter, r *http.Request, t *torrent.To } } -func handleRoot(c config.ConfigInterface) ([]byte, error) { +func handleRoot(t *torrent.TorrentManager) ([]byte, error) { var responses []dav.Response responses = append(responses, dav.Directory("")) - for _, directory := range c.GetDirectories() { + + directories := t.DirectoryMap.Keys() + sort.Strings(directories) + for _, directory := range directories { responses = append(responses, dav.Directory(directory)) } rootResponse := dav.MultiStatus{ diff --git a/internal/http/listing.go b/internal/http/listing.go index 8015396..4073750 100644 --- a/internal/http/listing.go +++ b/internal/http/listing.go @@ -9,12 +9,11 @@ import ( "sort" "strings" - "github.com/debridmediamanager.com/zurg/internal/config" "github.com/debridmediamanager.com/zurg/internal/torrent" "github.com/debridmediamanager.com/zurg/pkg/logutil" ) -func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface) { +func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) { log := logutil.NewLogger().Named("http") requestPath := path.Clean(r.URL.Path) @@ -25,7 +24,7 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T filteredSegments := removeEmptySegments(strings.Split(requestPath, "/")) switch { case len(filteredSegments) == 1: - output, err = handleRoot(c) + output, err = handleRoot(t) case len(filteredSegments) == 2: output, err = handleListOfTorrents(requestPath, t) case len(filteredSegments) == 3: @@ -52,10 +51,11 @@ func HandleDirectoryListing(w http.ResponseWriter, r *http.Request, t *torrent.T } } -func handleRoot(c config.ConfigInterface) (*string, error) { - htmlDoc := "