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

pull/1546/head
ssongliu 2023-07-05 16:10:19 +08:00 committed by GitHub
parent 006c27fee5
commit 35334c1650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -17,11 +17,11 @@ func Init() {
global.LOG.Errorf("load service port from setting failed, err: %v", err)
}
global.CONF.System.Port = portSetting.Value
enptrySetting, err := settingRepo.Get(settingRepo.WithByKey("EncryptKey"))
encryptSetting, err := settingRepo.Get(settingRepo.WithByKey("EncryptKey"))
if err != nil {
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"))
if err != nil {
global.LOG.Errorf("load service ssl from setting failed, err: %v", err)

View File

@ -441,6 +441,12 @@ var EncryptHostPassword = &gormigrate.Migration{
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 {
if len(host.Password) != 0 {
pass, err := encrypt.StringEncrypt(host.Password)

View File

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

View File

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