chore: updateUI API return 501 when config incomplete
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -582,9 +581,6 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||
N.KeepAliveInterval = time.Duration(cfg.KeepAliveInterval) * time.Second
|
||||
}
|
||||
|
||||
if cfg.ExternalUIURL != "" {
|
||||
ExternalUIURL = cfg.ExternalUIURL
|
||||
}
|
||||
ExternalUIPath = cfg.ExternalUI
|
||||
// checkout externalUI exist
|
||||
if ExternalUIPath != "" {
|
||||
@ -602,15 +598,12 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||
// checkout UIpath/name exist
|
||||
if cfg.ExternalUIName != "" {
|
||||
ExternalUIName = cfg.ExternalUIName
|
||||
ExternalUIFolder = filepath.Clean(path.Join(ExternalUIPath, cfg.ExternalUIName))
|
||||
if _, err := os.Stat(ExternalUIPath); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(ExternalUIPath, os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ExternalUIFolder = ExternalUIPath
|
||||
}
|
||||
if cfg.ExternalUIURL != "" {
|
||||
ExternalUIURL = cfg.ExternalUIURL
|
||||
}
|
||||
|
||||
cfg.Tun.RedirectToTun = cfg.EBpf.RedirectToTun
|
||||
return &General{
|
||||
|
@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -19,15 +20,18 @@ var (
|
||||
ExternalUIFolder string
|
||||
ExternalUIName string
|
||||
)
|
||||
|
||||
var (
|
||||
ErrImcompleteConf = errors.New("ExternalUI configure incomplete")
|
||||
)
|
||||
var xdMutex sync.Mutex
|
||||
|
||||
func UpdateUI() error {
|
||||
xdMutex.Lock()
|
||||
defer xdMutex.Unlock()
|
||||
|
||||
if ExternalUIPath == "" || ExternalUIFolder == "" {
|
||||
return fmt.Errorf("ExternalUI configure incomplete")
|
||||
err := prepare()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data, err := downloadForBytes(ExternalUIURL)
|
||||
@ -60,6 +64,25 @@ func UpdateUI() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func prepare() error {
|
||||
if ExternalUIPath == "" || ExternalUIURL == "" {
|
||||
return ErrImcompleteConf
|
||||
}
|
||||
|
||||
if ExternalUIName != "" {
|
||||
ExternalUIFolder = filepath.Clean(path.Join(ExternalUIPath, ExternalUIName))
|
||||
if _, err := os.Stat(ExternalUIPath); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(ExternalUIPath, os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ExternalUIFolder = ExternalUIPath
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func unzip(src, dest string) (string, error) {
|
||||
r, err := zip.OpenReader(src)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user