Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaisam <maisam.vahidsafa@gmail.com>2024-05-25 11:15:06 +0300
committerGitHub <noreply@github.com>2024-05-25 11:15:06 +0300
commitc422214ae8e1da9d9ed210f85f63356f8943a2cf (patch)
tree2aba053e243d0d589e7e32576b0f82b9c710bff3
parentbd2d7bce62eb39009e1dfa819e32a5be725c1a4b (diff)
Add webBasePath update feature to CLI (#2300)
-rw-r--r--main.go13
-rw-r--r--web/service/setting.go10
2 files changed, 21 insertions, 2 deletions
diff --git a/main.go b/main.go
index 2a8f8c7e..f4ce0846 100644
--- a/main.go
+++ b/main.go
@@ -216,7 +216,7 @@ func updateTgbotSetting(tgBotToken string, tgBotChatid string, tgBotRuntime stri
}
}
-func updateSetting(port int, username string, password string) {
+func updateSetting(port int, username string, password string, webBasePath string) {
err := database.InitDB(config.GetDBPath())
if err != nil {
fmt.Println(err)
@@ -243,6 +243,15 @@ func updateSetting(port int, username string, password string) {
fmt.Println("set username and password success")
}
}
+
+ if webBasePath != "" {
+ err := settingService.SetBasePath(webBasePath)
+ if err != nil {
+ fmt.Println("set base URI path failed:", err)
+ } else {
+ fmt.Println("set base URI path success")
+ }
+ }
}
func migrateDb() {
@@ -357,7 +366,7 @@ func main() {
if reset {
resetSetting()
} else {
- updateSetting(port, username, password)
+ updateSetting(port, username, password, webBasePath)
}
if show {
showSetting(show)
diff --git a/web/service/setting.go b/web/service/setting.go
index 9e740059..69b1fece 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -352,6 +352,16 @@ func (s *SettingService) GetSecret() ([]byte, error) {
return []byte(secret), err
}
+func (s *SettingService) SetBasePath(basePath string) error {
+ if !strings.HasPrefix(basePath, "/") {
+ basePath = "/" + basePath
+ }
+ if !strings.HasSuffix(basePath, "/") {
+ basePath += "/"
+ }
+ return s.setString("webBasePath", basePath)
+}
+
func (s *SettingService) GetBasePath() (string, error) {
basePath, err := s.getString("webBasePath")
if err != nil {