mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 20:52:15 +08:00
chore: auto download external UI when 'external-ui' is set and not empty
This commit is contained in:
parent
5bf22422d9
commit
50d0cd363c
@ -230,7 +230,7 @@ func clean() {
|
|||||||
|
|
||||||
// MaxPackageFileSize is a maximum package file length in bytes. The largest
|
// MaxPackageFileSize is a maximum package file length in bytes. The largest
|
||||||
// package whose size is limited by this constant currently has the size of
|
// package whose size is limited by this constant currently has the size of
|
||||||
// approximately 9 MiB.
|
// approximately 32 MiB.
|
||||||
const MaxPackageFileSize = 32 * 1024 * 1024
|
const MaxPackageFileSize = 32 * 1024 * 1024
|
||||||
|
|
||||||
// Download package file and save it to disk
|
// Download package file and save it to disk
|
||||||
|
@ -29,11 +29,6 @@ func UpdateUI() error {
|
|||||||
xdMutex.Lock()
|
xdMutex.Lock()
|
||||||
defer xdMutex.Unlock()
|
defer xdMutex.Unlock()
|
||||||
|
|
||||||
err := prepare_ui()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := downloadForBytes(ExternalUIURL)
|
data, err := downloadForBytes(ExternalUIURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't download file: %w", err)
|
return fmt.Errorf("can't download file: %w", err)
|
||||||
@ -64,7 +59,7 @@ func UpdateUI() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepare_ui() error {
|
func PrepareUIPath() error {
|
||||||
if ExternalUIPath == "" || ExternalUIURL == "" {
|
if ExternalUIPath == "" || ExternalUIURL == "" {
|
||||||
return ErrIncompleteConf
|
return ErrIncompleteConf
|
||||||
}
|
}
|
||||||
@ -79,7 +74,6 @@ func prepare_ui() error {
|
|||||||
} else {
|
} else {
|
||||||
ExternalUIFolder = ExternalUIPath
|
ExternalUIFolder = ExternalUIPath
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,6 +677,11 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
|||||||
updater.ExternalUIURL = cfg.ExternalUIURL
|
updater.ExternalUIURL = cfg.ExternalUIURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := updater.PrepareUIPath()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorln("PrepareUIPath error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
return &General{
|
return &General{
|
||||||
Inbound: Inbound{
|
Inbound: Inbound{
|
||||||
Port: cfg.Port,
|
Port: cfg.Port,
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/metacubex/mihomo/component/resolver"
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
SNI "github.com/metacubex/mihomo/component/sniffer"
|
SNI "github.com/metacubex/mihomo/component/sniffer"
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
|
"github.com/metacubex/mihomo/component/updater"
|
||||||
"github.com/metacubex/mihomo/config"
|
"github.com/metacubex/mihomo/config"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
"github.com/metacubex/mihomo/constant/features"
|
"github.com/metacubex/mihomo/constant/features"
|
||||||
@ -113,6 +114,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
|||||||
runtime.GC()
|
runtime.GC()
|
||||||
tunnel.OnRunning()
|
tunnel.OnRunning()
|
||||||
hcCompatibleProvider(cfg.Providers)
|
hcCompatibleProvider(cfg.Providers)
|
||||||
|
initExternalUI()
|
||||||
|
|
||||||
log.SetLevel(cfg.General.LogLevel)
|
log.SetLevel(cfg.General.LogLevel)
|
||||||
}
|
}
|
||||||
@ -385,6 +387,18 @@ func updateTunnels(tunnels []LC.Tunnel) {
|
|||||||
listener.PatchTunnel(tunnels, tunnel.Tunnel)
|
listener.PatchTunnel(tunnels, tunnel.Tunnel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initExternalUI() {
|
||||||
|
if updater.ExternalUIFolder != "" {
|
||||||
|
dirEntries, _ := os.ReadDir(updater.ExternalUIFolder)
|
||||||
|
if len(dirEntries) > 0 {
|
||||||
|
log.Infoln("UI already exists")
|
||||||
|
} else {
|
||||||
|
log.Infoln("UI not exists, downloading")
|
||||||
|
updater.UpdateUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func updateGeneral(general *config.General) {
|
func updateGeneral(general *config.General) {
|
||||||
tunnel.SetMode(general.Mode)
|
tunnel.SetMode(general.Mode)
|
||||||
tunnel.SetFindProcessMode(general.FindProcessMode)
|
tunnel.SetFindProcessMode(general.FindProcessMode)
|
||||||
|
@ -402,7 +402,7 @@ func updateConfigs(w http.ResponseWriter, r *http.Request) {
|
|||||||
func updateGeoDatabases(w http.ResponseWriter, r *http.Request) {
|
func updateGeoDatabases(w http.ResponseWriter, r *http.Request) {
|
||||||
err := updater.UpdateGeoDatabases()
|
err := updater.UpdateGeoDatabases()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("[REST-API] update GEO databases failed: %v", err)
|
log.Errorln("[GEO] update GEO databases failed: %v", err)
|
||||||
render.Status(r, http.StatusInternalServerError)
|
render.Status(r, http.StatusInternalServerError)
|
||||||
render.JSON(w, r, newError(err.Error()))
|
render.JSON(w, r, newError(err.Error()))
|
||||||
return
|
return
|
||||||
@ -410,7 +410,7 @@ func updateGeoDatabases(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
cfg, err := executor.ParseWithPath(C.Path.Config())
|
cfg, err := executor.ParseWithPath(C.Path.Config())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("[REST-API] update GEO databases failed: %v", err)
|
log.Errorln("[GEO] update GEO databases failed: %v", err)
|
||||||
render.Status(r, http.StatusInternalServerError)
|
render.Status(r, http.StatusInternalServerError)
|
||||||
render.JSON(w, r, newError("Error parsing configuration"))
|
render.JSON(w, r, newError("Error parsing configuration"))
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user