mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 00:09:16 +08:00
feat: Complete the node initialization logic (#7571)
This commit is contained in:
parent
5dbd16a28d
commit
8fe40b7a97
@ -8,10 +8,9 @@ type Setting struct {
|
||||
}
|
||||
|
||||
type NodeInfo struct {
|
||||
Scope string `json:"scope"`
|
||||
BaseDir string `json:"baseDir"`
|
||||
Version string `json:"version"`
|
||||
EncryptKey string `json:"encryptKey"`
|
||||
ServerCrt string `json:"serverCrt"`
|
||||
ServerKey string `json:"serverKey"`
|
||||
Scope string `json:"scope"`
|
||||
BaseDir string `json:"baseDir"`
|
||||
Version string `json:"version"`
|
||||
ServerCrt string `json:"serverCrt"`
|
||||
ServerKey string `json:"serverKey"`
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ type ILauncherRepo interface {
|
||||
Create(launcher *model.AppLauncher) error
|
||||
Save(launcher *model.AppLauncher) error
|
||||
Delete(opts ...DBOption) error
|
||||
|
||||
SyncAll(data []model.AppLauncher) error
|
||||
}
|
||||
|
||||
func NewILauncherRepo() ILauncherRepo {
|
||||
@ -53,3 +55,17 @@ func (u *LauncherRepo) Delete(opts ...DBOption) error {
|
||||
}
|
||||
return db.Delete(&model.AppLauncher{}).Error
|
||||
}
|
||||
|
||||
func (u *LauncherRepo) SyncAll(data []model.AppLauncher) error {
|
||||
tx := global.DB.Begin()
|
||||
if err := tx.Where("1 = 1").Delete(&model.AppLauncher{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(model.AppLauncher{}).Save(&data).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ type IBackupRepo interface {
|
||||
WithByFileName(fileName string) DBOption
|
||||
WithByCronID(cronjobID uint) DBOption
|
||||
WithFileNameStartWith(filePrefix string) DBOption
|
||||
|
||||
SyncAll(data []model.BackupAccount) error
|
||||
}
|
||||
|
||||
func NewIBackupRepo() IBackupRepo {
|
||||
@ -153,3 +155,17 @@ func (u *BackupRepo) GetRecord(opts ...DBOption) (*model.BackupRecord, error) {
|
||||
err := db.Find(record).Error
|
||||
return record, err
|
||||
}
|
||||
|
||||
func (u *BackupRepo) SyncAll(data []model.BackupAccount) error {
|
||||
tx := global.DB.Begin()
|
||||
if err := tx.Where("1 = 1").Delete(&model.BackupAccount{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if err := tx.Model(model.BackupAccount{}).Save(&data).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
@ -106,7 +106,6 @@ func (u *SettingService) ReloadConn() error {
|
||||
|
||||
global.CONF.System.BaseDir = nodeInfo.BaseDir
|
||||
global.CONF.System.Version = nodeInfo.Version
|
||||
global.CONF.System.EncryptKey = nodeInfo.EncryptKey
|
||||
global.IsMaster = nodeInfo.Scope == "master"
|
||||
return nil
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func initGlobalData() {
|
||||
if err := settingRepo.Update("SystemStatus", "Free"); err != nil {
|
||||
global.LOG.Fatalf("init service before start failed, err: %v", err)
|
||||
}
|
||||
|
||||
global.CONF.System.EncryptKey, _ = settingRepo.GetValueByKey("EncryptKey")
|
||||
_ = service.NewISettingService().ReloadConn()
|
||||
if global.IsMaster {
|
||||
global.CoreDB = common.LoadDBConnByPath(path.Join(global.CONF.System.DbPath, "core.db"), "core")
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
var AddTable = &gormigrate.Migration{
|
||||
ID: "20241009-add-table",
|
||||
ID: "20241226-add-table",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(
|
||||
&model.AppDetail{},
|
||||
@ -81,9 +81,6 @@ var InitSetting = &gormigrate.Migration{
|
||||
if err := tx.Create(&model.Setting{Key: "BaseDir", Value: nodeInfo.BaseDir}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: nodeInfo.EncryptKey}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
itemKey, _ := encrypt.StringEncrypt(nodeInfo.ServerKey)
|
||||
if err := tx.Create(&model.Setting{Key: "ServerKey", Value: itemKey}).Error; err != nil {
|
||||
return err
|
||||
@ -99,6 +96,9 @@ var InitSetting = &gormigrate.Migration{
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: common.RandStr(16)}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/agent/buserr"
|
||||
"github.com/1Panel-dev/1Panel/agent/constant"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/common"
|
||||
)
|
||||
|
||||
func RemoveTamper(website string) {}
|
||||
@ -48,7 +47,6 @@ func LoadNodeInfo() (bool, model.NodeInfo, error) {
|
||||
var info model.NodeInfo
|
||||
info.BaseDir = loadParams("BASE_DIR")
|
||||
info.Version = loadParams("ORIGINAL_VERSION")
|
||||
info.EncryptKey = common.RandStr(16)
|
||||
info.Scope = "master"
|
||||
return false, info, nil
|
||||
}
|
||||
|
@ -107,13 +107,14 @@ func (u *BackupService) GetLocalDir() (string, error) {
|
||||
}
|
||||
|
||||
func (u *BackupService) SearchWithPage(req dto.SearchPageWithType) (int64, interface{}, error) {
|
||||
count, accounts, err := backupRepo.Page(
|
||||
req.Page,
|
||||
req.PageSize,
|
||||
repo.WithByType(req.Type),
|
||||
repo.WithByName(req.Info),
|
||||
repo.WithOrderBy("created_at desc"),
|
||||
)
|
||||
options := []global.DBOption{repo.WithOrderBy("created_at desc")}
|
||||
if len(req.Type) != 0 {
|
||||
options = append(options, repo.WithByType(req.Type))
|
||||
}
|
||||
if len(req.Info) != 0 {
|
||||
options = append(options, repo.WithByType(req.Info))
|
||||
}
|
||||
count, accounts, err := backupRepo.Page(req.Page, req.PageSize, options...)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import { Backup } from '../interface/backup';
|
||||
import { TimeoutEnum } from '@/enums/http-enum';
|
||||
|
||||
// backup-agent
|
||||
export const listBackupOptions = () => {
|
||||
return http.get<Array<Backup.BackupOption>>(`/backups/options`);
|
||||
};
|
||||
export const handleBackup = (params: Backup.Backup) => {
|
||||
return http.post(`/backups/backup`, params, TimeoutEnum.T_1H);
|
||||
};
|
||||
export const listBackupOptions = () => {
|
||||
return http.get<Array<Backup.BackupOption>>(`/backups/options`);
|
||||
};
|
||||
export const handleRecover = (params: Backup.Recover) => {
|
||||
return http.post(`/backups/recover`, params, TimeoutEnum.T_1D);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user