Browse Source

fix: 解决数据库文件不存在时启用失败的问题 (#1544)

pull/1546/head
ssongliu 1 year ago committed by GitHub
parent
commit
35334c1650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      backend/init/hook/hook.go
  2. 6
      backend/init/migration/migrations/init.go
  3. 2
      backend/server/server.go
  4. 6
      cmd/server/cmd/user-info.go

4
backend/init/hook/hook.go

@ -17,11 +17,11 @@ func Init() {
global.LOG.Errorf("load service port from setting failed, err: %v", err) global.LOG.Errorf("load service port from setting failed, err: %v", err)
} }
global.CONF.System.Port = portSetting.Value global.CONF.System.Port = portSetting.Value
enptrySetting, err := settingRepo.Get(settingRepo.WithByKey("EncryptKey")) encryptSetting, err := settingRepo.Get(settingRepo.WithByKey("EncryptKey"))
if err != nil { if err != nil {
global.LOG.Errorf("load service encrypt key from setting failed, err: %v", err) global.LOG.Errorf("load service encrypt key from setting failed, err: %v", err)
} }
global.CONF.System.EncryptKey = enptrySetting.Value global.CONF.System.EncryptKey = encryptSetting.Value
sslSetting, err := settingRepo.Get(settingRepo.WithByKey("SSL")) sslSetting, err := settingRepo.Get(settingRepo.WithByKey("SSL"))
if err != nil { if err != nil {
global.LOG.Errorf("load service ssl from setting failed, err: %v", err) global.LOG.Errorf("load service ssl from setting failed, err: %v", err)

6
backend/init/migration/migrations/init.go

@ -441,6 +441,12 @@ var EncryptHostPassword = &gormigrate.Migration{
return err return err
} }
var encryptSetting model.Setting
if err := tx.Where("key = ?", "EncryptKey").Find(&encryptSetting).Error; err != nil {
return err
}
global.CONF.System.EncryptKey = encryptSetting.Value
for _, host := range hosts { for _, host := range hosts {
if len(host.Password) != 0 { if len(host.Password) != 0 {
pass, err := encrypt.StringEncrypt(host.Password) pass, err := encrypt.StringEncrypt(host.Password)

2
backend/server/server.go

@ -34,7 +34,6 @@ func Start() {
log.Init() log.Init()
app.Init() app.Init()
db.Init() db.Init()
hook.Init()
migration.Init() migration.Init()
validator.Init() validator.Init()
gob.Register(psession.SessionUser{}) gob.Register(psession.SessionUser{})
@ -43,6 +42,7 @@ func Start() {
gin.SetMode("debug") gin.SetMode("debug")
cron.Run() cron.Run()
business.Init() business.Init()
hook.Init()
rootRouter := router.Routers() rootRouter := router.Routers()
address := fmt.Sprintf(":%s", global.CONF.System.Port) address := fmt.Sprintf(":%s", global.CONF.System.Port)

6
cmd/server/cmd/user-info.go

@ -25,11 +25,11 @@ var userinfoCmd = &cobra.Command{
port := getSettingByKey(db, "ServerPort") port := getSettingByKey(db, "ServerPort")
ssl := getSettingByKey(db, "SSL") ssl := getSettingByKey(db, "SSL")
entrance := getSettingByKey(db, "SecurityEntrance") entrance := getSettingByKey(db, "SecurityEntrance")
enptrySetting := getSettingByKey(db, "EncryptKey") encryptSetting := getSettingByKey(db, "EncryptKey")
p := "" p := ""
if len(enptrySetting) == 16 { if len(encryptSetting) == 16 {
global.CONF.System.EncryptKey = enptrySetting global.CONF.System.EncryptKey = encryptSetting
p, _ = encrypt.StringDecrypt(password) p, _ = encrypt.StringDecrypt(password)
} else { } else {
p = password p = password

Loading…
Cancel
Save