mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 05:04:22 +00:00
fix(install): adapt -getApiToken CLI to multi-token service
settingService.GetApiToken was removed when API tokens moved to a multi-row ApiTokenService. Switch the install-time CLI to list tokens and create one named "install" if none exist, preserving the `apiToken: <value>` output the install.sh grep depends on.
This commit is contained in:
parent
68e8277f92
commit
8f7de576af
1 changed files with 18 additions and 9 deletions
27
main.go
27
main.go
|
|
@ -391,17 +391,26 @@ func GetListenIP(getListen bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetApiToken displays the current API token if getApiToken is true.
|
|
||||||
func GetApiToken(getApiToken bool) {
|
func GetApiToken(getApiToken bool) {
|
||||||
if getApiToken {
|
if !getApiToken {
|
||||||
settingService := service.SettingService{}
|
return
|
||||||
apiToken, err := settingService.GetApiToken()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("get apiToken failed, error info:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Println("apiToken:", apiToken)
|
|
||||||
}
|
}
|
||||||
|
apiTokenService := service.ApiTokenService{}
|
||||||
|
tokens, err := apiTokenService.List()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("get apiToken failed, error info:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(tokens) > 0 {
|
||||||
|
fmt.Println("apiToken:", tokens[0].Token)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
created, err := apiTokenService.Create("install")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("create apiToken failed, error info:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println("apiToken:", created.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
// migrateDb performs database migration operations for the 3x-ui panel.
|
// migrateDb performs database migration operations for the 3x-ui panel.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue