mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-15 19:22:53 +08:00
chore: auto download external UI when 'external-ui' is set and not empty
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
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
|
||||
// package whose size is limited by this constant currently has the size of
|
||||
// approximately 9 MiB.
|
||||
// approximately 32 MiB.
|
||||
const MaxPackageFileSize = 32 * 1024 * 1024
|
||||
|
||||
// Download package file and save it to disk
|
||||
|
|
|
@ -29,11 +29,6 @@ func UpdateUI() error {
|
|||
xdMutex.Lock()
|
||||
defer xdMutex.Unlock()
|
||||
|
||||
err := prepare_ui()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := downloadForBytes(ExternalUIURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't download file: %w", err)
|
||||
|
@ -64,7 +59,7 @@ func UpdateUI() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func prepare_ui() error {
|
||||
func PrepareUIPath() error {
|
||||
if ExternalUIPath == "" || ExternalUIURL == "" {
|
||||
return ErrIncompleteConf
|
||||
}
|
||||
|
@ -79,7 +74,6 @@ func prepare_ui() error {
|
|||
} else {
|
||||
ExternalUIFolder = ExternalUIPath
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -677,6 +677,11 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
|||
updater.ExternalUIURL = cfg.ExternalUIURL
|
||||
}
|
||||
|
||||
err := updater.PrepareUIPath()
|
||||
if err != nil {
|
||||
log.Errorln("PrepareUIPath error: %s", err)
|
||||
}
|
||||
|
||||
return &General{
|
||||
Inbound: Inbound{
|
||||
Port: cfg.Port,
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/metacubex/mihomo/component/resolver"
|
||||
SNI "github.com/metacubex/mihomo/component/sniffer"
|
||||
"github.com/metacubex/mihomo/component/trie"
|
||||
"github.com/metacubex/mihomo/component/updater"
|
||||
"github.com/metacubex/mihomo/config"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
"github.com/metacubex/mihomo/constant/features"
|
||||
|
@ -113,6 +114,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
|
|||
runtime.GC()
|
||||
tunnel.OnRunning()
|
||||
hcCompatibleProvider(cfg.Providers)
|
||||
initExternalUI()
|
||||
|
||||
log.SetLevel(cfg.General.LogLevel)
|
||||
}
|
||||
|
@ -385,6 +387,18 @@ func updateTunnels(tunnels []LC.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) {
|
||||
tunnel.SetMode(general.Mode)
|
||||
tunnel.SetFindProcessMode(general.FindProcessMode)
|
||||
|
|
|
@ -402,7 +402,7 @@ func updateConfigs(w http.ResponseWriter, r *http.Request) {
|
|||
func updateGeoDatabases(w http.ResponseWriter, r *http.Request) {
|
||||
err := updater.UpdateGeoDatabases()
|
||||
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.JSON(w, r, newError(err.Error()))
|
||||
return
|
||||
|
@ -410,7 +410,7 @@ func updateGeoDatabases(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
cfg, err := executor.ParseWithPath(C.Path.Config())
|
||||
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.JSON(w, r, newError("Error parsing configuration"))
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user