plugins: restructure and add tests for pluginsctl/* calls

This commit is contained in:
Chaitanya Bankanhal
2020-08-20 23:31:38 +05:30
committed by Nick Craig-Wood
parent cf68e61f40
commit 09b79679cd
5 changed files with 547 additions and 404 deletions

View File

@@ -6,7 +6,6 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/rclone/rclone/fs/rc/webgui"
"log"
"mime"
"net/http"
@@ -18,6 +17,8 @@ import (
"sync"
"time"
"github.com/rclone/rclone/fs/rc/webgui"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -368,7 +369,6 @@ func (s *Server) serveRemote(w http.ResponseWriter, r *http.Request, path string
// Match URLS of the form [fs]/remote
var fsMatch = regexp.MustCompile(`^\[(.*?)\](.*)$`)
var referrerPathReg = regexp.MustCompile("^(https?)://(.+):([0-9]+)?/(.*)$")
func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string) {
// Look to see if this has an fs in the path
@@ -397,20 +397,8 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string)
return
}
return
} else if s.opt.WebUI {
referrer := r.Referer()
referrerPathMatch := referrerPathReg.FindStringSubmatch(referrer)
if referrerPathMatch != nil {
referrerPluginMatch := webgui.PluginsMatch.FindStringSubmatch(referrerPathMatch[4])
if referrerPluginMatch != nil {
path = fmt.Sprintf("/plugins/%s/%s/%s", referrerPluginMatch[1], referrerPluginMatch[2], path)
http.Redirect(w, r, path, http.StatusMovedPermanently)
//s.pluginsHandler.ServeHTTP(w, r)
return
}
}
} else if s.opt.WebUI && webgui.ServePluginWithReferrerOK(w, r, path) {
return
}
// Serve the files
r.URL.Path = "/" + path