rc: Rclone-WebUI integration with rclone

This adds experimental support for web gui integration so that rclone can fetch and run a web based GUI using the --rc-web-ui and related flags.

It downloads and caches a webui zip file which it then unpacks and opens in the browser.
This commit is contained in:
Chaitanya Bankanhal
2019-08-04 11:32:37 +00:00
committed by Nick Craig-Wood
parent 0386d22cc9
commit 84e2806c4b
5 changed files with 227 additions and 11 deletions

View File

@ -8,6 +8,7 @@ import (
"mime"
"net/http"
"net/url"
"path/filepath"
"regexp"
"sort"
"strings"
@ -56,10 +57,17 @@ func newServer(opt *rc.Options, mux *http.ServeMux) *Server {
_ = mime.AddExtensionType(".wasm", "application/wasm")
_ = mime.AddExtensionType(".js", "application/javascript")
cachePath := filepath.Join(config.CacheDir, "webgui")
extractPath := filepath.Join(cachePath, "current/build")
// File handling
if opt.Files != "" {
if opt.WebUI {
fs.Logf(nil, "--rc-files overrides --rc-web-gui command\n")
}
fs.Logf(nil, "Serving files from %q", opt.Files)
s.files = http.FileServer(http.Dir(opt.Files))
} else if opt.WebUI {
s.files = http.FileServer(http.Dir(extractPath))
}
return s
}
@ -123,8 +131,9 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Origin", "*")
// echo back access control headers client needs
reqAccessHeaders := r.Header.Get("Access-Control-Request-Headers")
w.Header().Add("Access-Control-Allow-Headers", reqAccessHeaders)
//reqAccessHeaders := r.Header.Get("Access-Control-Request-Headers")
w.Header().Add("Access-Control-Request-Method", "POST, OPTIONS, GET, HEAD")
w.Header().Add("Access-Control-Allow-Headers", "authorization, Content-Type")
switch r.Method {
case "POST":