Skip to content

Commit

Permalink
Add webBasePath update feature to CLI (#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaisamV committed May 25, 2024
1 parent bd2d7bc commit c422214
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -357,7 +366,7 @@ func main() {
if reset {
resetSetting()
} else {
updateSetting(port, username, password)
updateSetting(port, username, password, webBasePath)
}
if show {
showSetting(show)
Expand Down
10 changes: 10 additions & 0 deletions web/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c422214

Please sign in to comment.