mirror of
https://github.com/rclone/rclone.git
synced 2025-02-02 03:29:51 +01:00
Add redirection for plugin urls
This commit is contained in:
parent
22674d1146
commit
cf68e61f40
@ -368,11 +368,11 @@ func (s *Server) serveRemote(w http.ResponseWriter, r *http.Request, path string
|
|||||||
|
|
||||||
// Match URLS of the form [fs]/remote
|
// Match URLS of the form [fs]/remote
|
||||||
var fsMatch = regexp.MustCompile(`^\[(.*?)\](.*)$`)
|
var fsMatch = regexp.MustCompile(`^\[(.*?)\](.*)$`)
|
||||||
|
var referrerPathReg = regexp.MustCompile("^(https?)://(.+):([0-9]+)?/(.*)$")
|
||||||
|
|
||||||
func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string) {
|
func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string) {
|
||||||
// Look to see if this has an fs in the path
|
// Look to see if this has an fs in the path
|
||||||
fsMatchResult := fsMatch.FindStringSubmatch(path)
|
fsMatchResult := fsMatch.FindStringSubmatch(path)
|
||||||
pluginsMatchResult := webgui.PluginsMatch.FindStringSubmatch(path)
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case fsMatchResult != nil && s.opt.Serve:
|
case fsMatchResult != nil && s.opt.Serve:
|
||||||
@ -387,6 +387,8 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string)
|
|||||||
s.serveRoot(w, r)
|
s.serveRoot(w, r)
|
||||||
return
|
return
|
||||||
case s.files != nil:
|
case s.files != nil:
|
||||||
|
pluginsMatchResult := webgui.PluginsMatch.FindStringSubmatch(path)
|
||||||
|
|
||||||
if s.opt.WebUI && pluginsMatchResult != nil {
|
if s.opt.WebUI && pluginsMatchResult != nil {
|
||||||
ok := webgui.ServePluginOK(w, r, pluginsMatchResult)
|
ok := webgui.ServePluginOK(w, r, pluginsMatchResult)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -395,6 +397,20 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request, path string)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Serve the files
|
// Serve the files
|
||||||
r.URL.Path = "/" + path
|
r.URL.Path = "/" + path
|
||||||
|
Loading…
Reference in New Issue
Block a user