mirror of
https://github.com/rclone/rclone.git
synced 2025-08-13 23:38:51 +02:00
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:
committed by
Nick Craig-Wood
parent
0386d22cc9
commit
84e2806c4b
@ -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":
|
||||
|
Reference in New Issue
Block a user