mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-11-04 23:36:09 +08:00 
			
		
		
		
	pref: Adjust node editing logic (#7217)
This commit is contained in:
		
							parent
							
								
									9b0916f0ed
								
							
						
					
					
						commit
						841d1a31bf
					
				
					 27 changed files with 404 additions and 278 deletions
				
			
		| 
						 | 
				
			
			@ -65,3 +65,25 @@ func (b *BaseApi) Upgrade(c *gin.Context) {
 | 
			
		|||
	}
 | 
			
		||||
	helper.SuccessWithData(c, nil)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// @Tags System Setting
 | 
			
		||||
// @Summary Upgrade
 | 
			
		||||
// @Description 系统回滚
 | 
			
		||||
// @Accept json
 | 
			
		||||
// @Param request body dto.OperateByID true "request"
 | 
			
		||||
// @Success 200
 | 
			
		||||
// @Security ApiKeyAuth
 | 
			
		||||
// @Router /core/settings/rollback [post]
 | 
			
		||||
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"upgrade_logs","output_column":"old_version","output_value":"version"}],"formatZH":"回滚系统 => [version]","formatEN":"rollback system => [version]"}
 | 
			
		||||
func (b *BaseApi) Rollback(c *gin.Context) {
 | 
			
		||||
	var req dto.OperateByID
 | 
			
		||||
	if err := helper.CheckBindAndValidate(&req, c); err != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := upgradeService.Rollback(req); err != nil {
 | 
			
		||||
		helper.InternalServer(c, err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	helper.SuccessWithData(c, nil)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,17 +8,17 @@ import (
 | 
			
		|||
type LauncherRepo struct{}
 | 
			
		||||
 | 
			
		||||
type ILauncherRepo interface {
 | 
			
		||||
	Get(opts ...DBOption) (model.AppLauncher, error)
 | 
			
		||||
	List(opts ...DBOption) ([]model.AppLauncher, error)
 | 
			
		||||
	Get(opts ...global.DBOption) (model.AppLauncher, error)
 | 
			
		||||
	List(opts ...global.DBOption) ([]model.AppLauncher, error)
 | 
			
		||||
	Create(launcher *model.AppLauncher) error
 | 
			
		||||
	Delete(opts ...DBOption) error
 | 
			
		||||
	Delete(opts ...global.DBOption) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewILauncherRepo() ILauncherRepo {
 | 
			
		||||
	return &LauncherRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *LauncherRepo) Get(opts ...DBOption) (model.AppLauncher, error) {
 | 
			
		||||
func (u *LauncherRepo) Get(opts ...global.DBOption) (model.AppLauncher, error) {
 | 
			
		||||
	var launcher model.AppLauncher
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ func (u *LauncherRepo) Get(opts ...DBOption) (model.AppLauncher, error) {
 | 
			
		|||
	err := db.First(&launcher).Error
 | 
			
		||||
	return launcher, err
 | 
			
		||||
}
 | 
			
		||||
func (u *LauncherRepo) List(opts ...DBOption) ([]model.AppLauncher, error) {
 | 
			
		||||
func (u *LauncherRepo) List(opts ...global.DBOption) ([]model.AppLauncher, error) {
 | 
			
		||||
	var ops []model.AppLauncher
 | 
			
		||||
	db := global.DB.Model(&model.AppLauncher{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ func (u *LauncherRepo) Create(launcher *model.AppLauncher) error {
 | 
			
		|||
	return global.DB.Create(launcher).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *LauncherRepo) Delete(opts ...DBOption) error {
 | 
			
		||||
func (u *LauncherRepo) Delete(opts ...global.DBOption) error {
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,19 +8,19 @@ import (
 | 
			
		|||
type BackupRepo struct{}
 | 
			
		||||
 | 
			
		||||
type IBackupRepo interface {
 | 
			
		||||
	Get(opts ...DBOption) (model.BackupAccount, error)
 | 
			
		||||
	List(opts ...DBOption) ([]model.BackupAccount, error)
 | 
			
		||||
	Page(limit, offset int, opts ...DBOption) (int64, []model.BackupAccount, error)
 | 
			
		||||
	Get(opts ...global.DBOption) (model.BackupAccount, error)
 | 
			
		||||
	List(opts ...global.DBOption) ([]model.BackupAccount, error)
 | 
			
		||||
	Page(limit, offset int, opts ...global.DBOption) (int64, []model.BackupAccount, error)
 | 
			
		||||
	Create(backup *model.BackupAccount) error
 | 
			
		||||
	Save(backup *model.BackupAccount) error
 | 
			
		||||
	Delete(opts ...DBOption) error
 | 
			
		||||
	Delete(opts ...global.DBOption) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewIBackupRepo() IBackupRepo {
 | 
			
		||||
	return &BackupRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *BackupRepo) Get(opts ...DBOption) (model.BackupAccount, error) {
 | 
			
		||||
func (u *BackupRepo) Get(opts ...global.DBOption) (model.BackupAccount, error) {
 | 
			
		||||
	var backup model.BackupAccount
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ func (u *BackupRepo) Get(opts ...DBOption) (model.BackupAccount, error) {
 | 
			
		|||
	return backup, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *BackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.BackupAccount, error) {
 | 
			
		||||
func (u *BackupRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.BackupAccount, error) {
 | 
			
		||||
	var ops []model.BackupAccount
 | 
			
		||||
	db := global.DB.Model(&model.BackupAccount{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -42,7 +42,7 @@ func (u *BackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.Back
 | 
			
		|||
	return count, ops, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *BackupRepo) List(opts ...DBOption) ([]model.BackupAccount, error) {
 | 
			
		||||
func (u *BackupRepo) List(opts ...global.DBOption) ([]model.BackupAccount, error) {
 | 
			
		||||
	var ops []model.BackupAccount
 | 
			
		||||
	db := global.DB.Model(&model.BackupAccount{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -60,7 +60,7 @@ func (u *BackupRepo) Save(backup *model.BackupAccount) error {
 | 
			
		|||
	return global.DB.Save(backup).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *BackupRepo) Delete(opts ...DBOption) error {
 | 
			
		||||
func (u *BackupRepo) Delete(opts ...global.DBOption) error {
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,25 +3,28 @@ package repo
 | 
			
		|||
import (
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/model"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type CommandRepo struct{}
 | 
			
		||||
 | 
			
		||||
type ICommandRepo interface {
 | 
			
		||||
	List(opts ...DBOption) ([]model.Command, error)
 | 
			
		||||
	Page(limit, offset int, opts ...DBOption) (int64, []model.Command, error)
 | 
			
		||||
	List(opts ...global.DBOption) ([]model.Command, error)
 | 
			
		||||
	Page(limit, offset int, opts ...global.DBOption) (int64, []model.Command, error)
 | 
			
		||||
	Create(command *model.Command) error
 | 
			
		||||
	Update(id uint, vars map[string]interface{}) error
 | 
			
		||||
	UpdateGroup(group, newGroup uint) error
 | 
			
		||||
	Delete(opts ...DBOption) error
 | 
			
		||||
	Get(opts ...DBOption) (model.Command, error)
 | 
			
		||||
	Delete(opts ...global.DBOption) error
 | 
			
		||||
	Get(opts ...global.DBOption) (model.Command, error)
 | 
			
		||||
 | 
			
		||||
	WithByInfo(info string) global.DBOption
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewICommandRepo() ICommandRepo {
 | 
			
		||||
	return &CommandRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *CommandRepo) Get(opts ...DBOption) (model.Command, error) {
 | 
			
		||||
func (u *CommandRepo) Get(opts ...global.DBOption) (model.Command, error) {
 | 
			
		||||
	var command model.Command
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +34,7 @@ func (u *CommandRepo) Get(opts ...DBOption) (model.Command, error) {
 | 
			
		|||
	return command, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Command, error) {
 | 
			
		||||
func (u *CommandRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.Command, error) {
 | 
			
		||||
	var users []model.Command
 | 
			
		||||
	db := global.DB.Model(&model.Command{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +46,7 @@ func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Com
 | 
			
		|||
	return count, users, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *CommandRepo) List(opts ...DBOption) ([]model.Command, error) {
 | 
			
		||||
func (u *CommandRepo) List(opts ...global.DBOption) ([]model.Command, error) {
 | 
			
		||||
	var commands []model.Command
 | 
			
		||||
	db := global.DB.Model(&model.Command{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -64,10 +67,19 @@ func (h *CommandRepo) UpdateGroup(group, newGroup uint) error {
 | 
			
		|||
	return global.DB.Model(&model.Command{}).Where("group_id = ?", group).Updates(map[string]interface{}{"group_id": newGroup}).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *CommandRepo) Delete(opts ...DBOption) error {
 | 
			
		||||
func (u *CommandRepo) Delete(opts ...global.DBOption) error {
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
	}
 | 
			
		||||
	return db.Delete(&model.Command{}).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *CommandRepo) WithByInfo(info string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(info) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("name like ? or command like ?", "%"+info+"%", "%"+info+"%")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,22 +4,24 @@ import (
 | 
			
		|||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/constant"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DBOption func(*gorm.DB) *gorm.DB
 | 
			
		||||
 | 
			
		||||
type ICommonRepo interface {
 | 
			
		||||
	WithByID(id uint) DBOption
 | 
			
		||||
	WithByIDs(ids []uint) DBOption
 | 
			
		||||
	WithByName(name string) DBOption
 | 
			
		||||
	WithLikeName(name string) DBOption
 | 
			
		||||
	WithByType(ty string) DBOption
 | 
			
		||||
	WithByKey(key string) DBOption
 | 
			
		||||
	WithOrderBy(orderStr string) DBOption
 | 
			
		||||
	WithByStatus(status string) DBOption
 | 
			
		||||
	WithByID(id uint) global.DBOption
 | 
			
		||||
	WithByGroupID(id uint) global.DBOption
 | 
			
		||||
 | 
			
		||||
	WithOrderRuleBy(orderBy, order string) DBOption
 | 
			
		||||
	WithByName(name string) global.DBOption
 | 
			
		||||
	WithByType(ty string) global.DBOption
 | 
			
		||||
	WithByKey(key string) global.DBOption
 | 
			
		||||
	WithOrderBy(orderStr string) global.DBOption
 | 
			
		||||
	WithByStatus(status string) global.DBOption
 | 
			
		||||
	WithByGroupBelong(group string) global.DBOption
 | 
			
		||||
 | 
			
		||||
	WithByIDs(ids []uint) global.DBOption
 | 
			
		||||
 | 
			
		||||
	WithOrderRuleBy(orderBy, order string) global.DBOption
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CommonRepo struct{}
 | 
			
		||||
| 
						 | 
				
			
			@ -28,57 +30,56 @@ func NewICommonRepo() ICommonRepo {
 | 
			
		|||
	return &CommonRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *CommonRepo) WithByID(id uint) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithByID(id uint) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithByIDs(ids []uint) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithByGroupID(id uint) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("group_id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *CommonRepo) WithByIDs(ids []uint) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("id in (?)", ids)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithByName(name string) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithByName(name string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(name) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("`name` = ?", name)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithLikeName(name string) DBOption {
 | 
			
		||||
 | 
			
		||||
func (c *CommonRepo) WithByType(ty string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(name) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithByType(ty string) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(ty) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("`type` = ?", ty)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithByKey(key string) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithByKey(key string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("key = ?", key)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithByStatus(status string) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithByStatus(status string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("status = ?", status)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *CommonRepo) WithOrderBy(orderStr string) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithByGroupBelong(group string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("group_belong = ?", group)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *CommonRepo) WithOrderBy(orderStr string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Order(orderStr)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption {
 | 
			
		||||
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) global.DBOption {
 | 
			
		||||
	switch order {
 | 
			
		||||
	case constant.OrderDesc:
 | 
			
		||||
		order = "desc"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,16 +9,13 @@ import (
 | 
			
		|||
type GroupRepo struct{}
 | 
			
		||||
 | 
			
		||||
type IGroupRepo interface {
 | 
			
		||||
	Get(opts ...DBOption) (model.Group, error)
 | 
			
		||||
	GetList(opts ...DBOption) ([]model.Group, error)
 | 
			
		||||
	Get(opts ...global.DBOption) (model.Group, error)
 | 
			
		||||
	GetList(opts ...global.DBOption) ([]model.Group, error)
 | 
			
		||||
	Create(group *model.Group) error
 | 
			
		||||
	Update(id uint, vars map[string]interface{}) error
 | 
			
		||||
	Delete(opts ...DBOption) error
 | 
			
		||||
	Delete(opts ...global.DBOption) error
 | 
			
		||||
 | 
			
		||||
	WithByID(id uint) DBOption
 | 
			
		||||
	WithByGroupID(id uint) DBOption
 | 
			
		||||
	WithByGroupType(ty string) DBOption
 | 
			
		||||
	WithByDefault(isDefalut bool) DBOption
 | 
			
		||||
	WithByDefault(isDefalut bool) global.DBOption
 | 
			
		||||
	CancelDefault(groupType string) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -26,31 +23,13 @@ func NewIGroupRepo() IGroupRepo {
 | 
			
		|||
	return &GroupRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GroupRepo) WithByID(id uint) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GroupRepo) WithByGroupID(id uint) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("group_id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GroupRepo) WithByGroupType(ty string) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("`type` = ?", ty)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *GroupRepo) WithByDefault(isDefalut bool) DBOption {
 | 
			
		||||
func (c *GroupRepo) WithByDefault(isDefalut bool) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("is_default = ?", isDefalut)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *GroupRepo) Get(opts ...DBOption) (model.Group, error) {
 | 
			
		||||
func (u *GroupRepo) Get(opts ...global.DBOption) (model.Group, error) {
 | 
			
		||||
	var group model.Group
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -60,7 +39,7 @@ func (u *GroupRepo) Get(opts ...DBOption) (model.Group, error) {
 | 
			
		|||
	return group, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *GroupRepo) GetList(opts ...DBOption) ([]model.Group, error) {
 | 
			
		||||
func (u *GroupRepo) GetList(opts ...global.DBOption) ([]model.Group, error) {
 | 
			
		||||
	var groups []model.Group
 | 
			
		||||
	db := global.DB.Model(&model.Group{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -78,7 +57,7 @@ func (u *GroupRepo) Update(id uint, vars map[string]interface{}) error {
 | 
			
		|||
	return global.DB.Model(&model.Group{}).Where("id = ?", id).Updates(vars).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *GroupRepo) Delete(opts ...DBOption) error {
 | 
			
		||||
func (u *GroupRepo) Delete(opts ...global.DBOption) error {
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,25 +9,25 @@ import (
 | 
			
		|||
type HostRepo struct{}
 | 
			
		||||
 | 
			
		||||
type IHostRepo interface {
 | 
			
		||||
	Get(opts ...DBOption) (model.Host, error)
 | 
			
		||||
	GetList(opts ...DBOption) ([]model.Host, error)
 | 
			
		||||
	Page(limit, offset int, opts ...DBOption) (int64, []model.Host, error)
 | 
			
		||||
	Get(opts ...global.DBOption) (model.Host, error)
 | 
			
		||||
	GetList(opts ...global.DBOption) ([]model.Host, error)
 | 
			
		||||
	Page(limit, offset int, opts ...global.DBOption) (int64, []model.Host, error)
 | 
			
		||||
	Create(host *model.Host) error
 | 
			
		||||
	Update(id uint, vars map[string]interface{}) error
 | 
			
		||||
	UpdateGroup(group, newGroup uint) error
 | 
			
		||||
	Delete(opts ...DBOption) error
 | 
			
		||||
	Delete(opts ...global.DBOption) error
 | 
			
		||||
 | 
			
		||||
	WithByInfo(info string) DBOption
 | 
			
		||||
	WithByPort(port uint) DBOption
 | 
			
		||||
	WithByUser(user string) DBOption
 | 
			
		||||
	WithByAddr(addr string) DBOption
 | 
			
		||||
	WithByInfo(info string) global.DBOption
 | 
			
		||||
	WithByPort(port uint) global.DBOption
 | 
			
		||||
	WithByUser(user string) global.DBOption
 | 
			
		||||
	WithByAddr(addr string) global.DBOption
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewIHostRepo() IHostRepo {
 | 
			
		||||
	return &HostRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) Get(opts ...DBOption) (model.Host, error) {
 | 
			
		||||
func (h *HostRepo) Get(opts ...global.DBOption) (model.Host, error) {
 | 
			
		||||
	var host model.Host
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +37,7 @@ func (h *HostRepo) Get(opts ...DBOption) (model.Host, error) {
 | 
			
		|||
	return host, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) GetList(opts ...DBOption) ([]model.Host, error) {
 | 
			
		||||
func (h *HostRepo) GetList(opts ...global.DBOption) ([]model.Host, error) {
 | 
			
		||||
	var hosts []model.Host
 | 
			
		||||
	db := global.DB.Model(&model.Host{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ func (h *HostRepo) GetList(opts ...DBOption) ([]model.Host, error) {
 | 
			
		|||
	return hosts, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host, error) {
 | 
			
		||||
func (h *HostRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.Host, error) {
 | 
			
		||||
	var users []model.Host
 | 
			
		||||
	db := global.DB.Model(&model.Host{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +59,7 @@ func (h *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host,
 | 
			
		|||
	return count, users, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) WithByInfo(info string) DBOption {
 | 
			
		||||
func (h *HostRepo) WithByInfo(info string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(info) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
| 
						 | 
				
			
			@ -69,29 +69,21 @@ func (h *HostRepo) WithByInfo(info string) DBOption {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) WithByPort(port uint) DBOption {
 | 
			
		||||
func (h *HostRepo) WithByPort(port uint) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("port = ?", port)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (h *HostRepo) WithByUser(user string) DBOption {
 | 
			
		||||
func (h *HostRepo) WithByUser(user string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("user = ?", user)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (h *HostRepo) WithByAddr(addr string) DBOption {
 | 
			
		||||
func (h *HostRepo) WithByAddr(addr string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("addr = ?", addr)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (h *HostRepo) WithByGroup(group string) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(group) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("group_belong = ?", group)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) Create(host *model.Host) error {
 | 
			
		||||
	return global.DB.Create(host).Error
 | 
			
		||||
| 
						 | 
				
			
			@ -105,7 +97,7 @@ func (h *HostRepo) UpdateGroup(group, newGroup uint) error {
 | 
			
		|||
	return global.DB.Model(&model.Host{}).Where("group_id = ?", group).Updates(map[string]interface{}{"group_id": newGroup}).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *HostRepo) Delete(opts ...DBOption) error {
 | 
			
		||||
func (h *HostRepo) Delete(opts ...global.DBOption) error {
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,16 +11,15 @@ type LogRepo struct{}
 | 
			
		|||
type ILogRepo interface {
 | 
			
		||||
	CleanLogin() error
 | 
			
		||||
	CreateLoginLog(user *model.LoginLog) error
 | 
			
		||||
	PageLoginLog(limit, offset int, opts ...DBOption) (int64, []model.LoginLog, error)
 | 
			
		||||
	PageLoginLog(limit, offset int, opts ...global.DBOption) (int64, []model.LoginLog, error)
 | 
			
		||||
 | 
			
		||||
	CleanOperation() error
 | 
			
		||||
	CreateOperationLog(user *model.OperationLog) error
 | 
			
		||||
	PageOperationLog(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error)
 | 
			
		||||
	PageOperationLog(limit, offset int, opts ...global.DBOption) (int64, []model.OperationLog, error)
 | 
			
		||||
 | 
			
		||||
	WithByIP(ip string) DBOption
 | 
			
		||||
	WithByStatus(status string) DBOption
 | 
			
		||||
	WithByGroup(group string) DBOption
 | 
			
		||||
	WithByLikeOperation(operation string) DBOption
 | 
			
		||||
	WithByIP(ip string) global.DBOption
 | 
			
		||||
	WithBySource(source string) global.DBOption
 | 
			
		||||
	WithByLikeOperation(operation string) global.DBOption
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewILogRepo() ILogRepo {
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +34,7 @@ func (u *LogRepo) CreateLoginLog(log *model.LoginLog) error {
 | 
			
		|||
	return global.DB.Create(log).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *LogRepo) PageLoginLog(page, size int, opts ...DBOption) (int64, []model.LoginLog, error) {
 | 
			
		||||
func (u *LogRepo) PageLoginLog(page, size int, opts ...global.DBOption) (int64, []model.LoginLog, error) {
 | 
			
		||||
	var ops []model.LoginLog
 | 
			
		||||
	db := global.DB.Model(&model.LoginLog{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -55,7 +54,7 @@ func (u *LogRepo) CreateOperationLog(log *model.OperationLog) error {
 | 
			
		|||
	return global.DB.Create(log).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *LogRepo) PageOperationLog(page, size int, opts ...DBOption) (int64, []model.OperationLog, error) {
 | 
			
		||||
func (u *LogRepo) PageOperationLog(page, size int, opts ...global.DBOption) (int64, []model.OperationLog, error) {
 | 
			
		||||
	var ops []model.OperationLog
 | 
			
		||||
	db := global.DB.Model(&model.OperationLog{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +66,7 @@ func (u *LogRepo) PageOperationLog(page, size int, opts ...DBOption) (int64, []m
 | 
			
		|||
	return count, ops, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *LogRepo) WithByStatus(status string) DBOption {
 | 
			
		||||
func (c *LogRepo) WithByStatus(status string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(status) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
| 
						 | 
				
			
			@ -75,23 +74,21 @@ func (c *LogRepo) WithByStatus(status string) DBOption {
 | 
			
		|||
		return g.Where("status = ?", status)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *LogRepo) WithByGroup(group string) DBOption {
 | 
			
		||||
func (c *LogRepo) WithBySource(source string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(group) == 0 {
 | 
			
		||||
		if len(source) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("source = ?", group)
 | 
			
		||||
		return g.Where("source = ?", source)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *LogRepo) WithByIP(ip string) DBOption {
 | 
			
		||||
func (c *LogRepo) WithByIP(ip string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(ip) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
		}
 | 
			
		||||
		return g.Where("ip LIKE ?", "%"+ip+"%")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *LogRepo) WithByLikeOperation(operation string) DBOption {
 | 
			
		||||
 | 
			
		||||
func (c *LogRepo) WithByLikeOperation(operation string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		if len(operation) == 0 {
 | 
			
		||||
			return g
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,8 +8,8 @@ import (
 | 
			
		|||
type SettingRepo struct{}
 | 
			
		||||
 | 
			
		||||
type ISettingRepo interface {
 | 
			
		||||
	List(opts ...DBOption) ([]model.Setting, error)
 | 
			
		||||
	Get(opts ...DBOption) (model.Setting, error)
 | 
			
		||||
	List(opts ...global.DBOption) ([]model.Setting, error)
 | 
			
		||||
	Get(opts ...global.DBOption) (model.Setting, error)
 | 
			
		||||
	Create(key, value string) error
 | 
			
		||||
	Update(key, value string) error
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ func NewISettingRepo() ISettingRepo {
 | 
			
		|||
	return &SettingRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *SettingRepo) List(opts ...DBOption) ([]model.Setting, error) {
 | 
			
		||||
func (u *SettingRepo) List(opts ...global.DBOption) ([]model.Setting, error) {
 | 
			
		||||
	var settings []model.Setting
 | 
			
		||||
	db := global.DB.Model(&model.Setting{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -36,7 +36,7 @@ func (u *SettingRepo) Create(key, value string) error {
 | 
			
		|||
	return global.DB.Create(setting).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *SettingRepo) Get(opts ...DBOption) (model.Setting, error) {
 | 
			
		||||
func (u *SettingRepo) Get(opts ...global.DBOption) (model.Setting, error) {
 | 
			
		||||
	var settings model.Setting
 | 
			
		||||
	db := global.DB.Model(&model.Setting{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,20 +13,20 @@ type TaskRepo struct {
 | 
			
		|||
 | 
			
		||||
type ITaskRepo interface {
 | 
			
		||||
	Save(ctx context.Context, task *model.Task) error
 | 
			
		||||
	GetFirst(opts ...DBOption) (model.Task, error)
 | 
			
		||||
	Page(page, size int, opts ...DBOption) (int64, []model.Task, error)
 | 
			
		||||
	GetFirst(opts ...global.DBOption) (model.Task, error)
 | 
			
		||||
	Page(page, size int, opts ...global.DBOption) (int64, []model.Task, error)
 | 
			
		||||
	Update(ctx context.Context, task *model.Task) error
 | 
			
		||||
 | 
			
		||||
	WithByID(id string) DBOption
 | 
			
		||||
	WithResourceID(id uint) DBOption
 | 
			
		||||
	WithOperate(taskOperate string) DBOption
 | 
			
		||||
	WithByID(id string) global.DBOption
 | 
			
		||||
	WithResourceID(id uint) global.DBOption
 | 
			
		||||
	WithOperate(taskOperate string) global.DBOption
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewITaskRepo() ITaskRepo {
 | 
			
		||||
	return &TaskRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getTaskDb(opts ...DBOption) *gorm.DB {
 | 
			
		||||
func getTaskDb(opts ...global.DBOption) *gorm.DB {
 | 
			
		||||
	db := global.TaskDB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
| 
						 | 
				
			
			@ -34,7 +34,7 @@ func getTaskDb(opts ...DBOption) *gorm.DB {
 | 
			
		|||
	return db
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getTaskTx(ctx context.Context, opts ...DBOption) *gorm.DB {
 | 
			
		||||
func getTaskTx(ctx context.Context, opts ...global.DBOption) *gorm.DB {
 | 
			
		||||
	tx, ok := ctx.Value("db").(*gorm.DB)
 | 
			
		||||
	if ok {
 | 
			
		||||
		for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -45,19 +45,19 @@ func getTaskTx(ctx context.Context, opts ...DBOption) *gorm.DB {
 | 
			
		|||
	return getTaskDb(opts...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t TaskRepo) WithByID(id string) DBOption {
 | 
			
		||||
func (t TaskRepo) WithByID(id string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t TaskRepo) WithOperate(taskOperate string) DBOption {
 | 
			
		||||
func (t TaskRepo) WithOperate(taskOperate string) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("operate = ?", taskOperate)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t TaskRepo) WithResourceID(id uint) DBOption {
 | 
			
		||||
func (t TaskRepo) WithResourceID(id uint) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("resource_id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +67,7 @@ func (t TaskRepo) Save(ctx context.Context, task *model.Task) error {
 | 
			
		|||
	return getTaskTx(ctx).Save(&task).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t TaskRepo) GetFirst(opts ...DBOption) (model.Task, error) {
 | 
			
		||||
func (t TaskRepo) GetFirst(opts ...global.DBOption) (model.Task, error) {
 | 
			
		||||
	var task model.Task
 | 
			
		||||
	db := getTaskDb(opts...).Model(&model.Task{})
 | 
			
		||||
	if err := db.First(&task).Error; err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ func (t TaskRepo) GetFirst(opts ...DBOption) (model.Task, error) {
 | 
			
		|||
	return task, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t TaskRepo) Page(page, size int, opts ...DBOption) (int64, []model.Task, error) {
 | 
			
		||||
func (t TaskRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.Task, error) {
 | 
			
		||||
	var tasks []model.Task
 | 
			
		||||
	db := getTaskDb(opts...).Model(&model.Task{})
 | 
			
		||||
	count := int64(0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,22 +9,20 @@ import (
 | 
			
		|||
type UpgradeLogRepo struct{}
 | 
			
		||||
 | 
			
		||||
type IUpgradeLogRepo interface {
 | 
			
		||||
	Get(opts ...DBOption) (model.UpgradeLog, error)
 | 
			
		||||
	List(opts ...DBOption) ([]model.UpgradeLog, error)
 | 
			
		||||
	Get(opts ...global.DBOption) (model.UpgradeLog, error)
 | 
			
		||||
	List(opts ...global.DBOption) ([]model.UpgradeLog, error)
 | 
			
		||||
	Create(log *model.UpgradeLog) error
 | 
			
		||||
	Page(limit, offset int, opts ...DBOption) (int64, []model.UpgradeLog, error)
 | 
			
		||||
	Delete(opts ...DBOption) error
 | 
			
		||||
	Page(limit, offset int, opts ...global.DBOption) (int64, []model.UpgradeLog, error)
 | 
			
		||||
	Delete(opts ...global.DBOption) error
 | 
			
		||||
 | 
			
		||||
	WithByNodeID(nodeID uint) DBOption
 | 
			
		||||
	WithByIDs(ids []uint) DBOption
 | 
			
		||||
	WithByID(id uint) DBOption
 | 
			
		||||
	WithByNodeID(nodeID uint) global.DBOption
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewIUpgradeLogRepo() IUpgradeLogRepo {
 | 
			
		||||
	return &UpgradeLogRepo{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UpgradeLogRepo) Get(opts ...DBOption) (model.UpgradeLog, error) {
 | 
			
		||||
func (u *UpgradeLogRepo) Get(opts ...global.DBOption) (model.UpgradeLog, error) {
 | 
			
		||||
	var log model.UpgradeLog
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -34,7 +32,7 @@ func (u *UpgradeLogRepo) Get(opts ...DBOption) (model.UpgradeLog, error) {
 | 
			
		|||
	return log, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UpgradeLogRepo) List(opts ...DBOption) ([]model.UpgradeLog, error) {
 | 
			
		||||
func (u *UpgradeLogRepo) List(opts ...global.DBOption) ([]model.UpgradeLog, error) {
 | 
			
		||||
	var logs []model.UpgradeLog
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +54,7 @@ func (u *UpgradeLogRepo) Save(log *model.UpgradeLog) error {
 | 
			
		|||
	return global.DB.Save(log).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UpgradeLogRepo) Delete(opts ...DBOption) error {
 | 
			
		||||
func (u *UpgradeLogRepo) Delete(opts ...global.DBOption) error {
 | 
			
		||||
	db := global.DB
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
		db = opt(db)
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +62,7 @@ func (u *UpgradeLogRepo) Delete(opts ...DBOption) error {
 | 
			
		|||
	return db.Delete(&model.UpgradeLog{}).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UpgradeLogRepo) Page(page, size int, opts ...DBOption) (int64, []model.UpgradeLog, error) {
 | 
			
		||||
func (u *UpgradeLogRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.UpgradeLog, error) {
 | 
			
		||||
	var ops []model.UpgradeLog
 | 
			
		||||
	db := global.DB.Model(&model.UpgradeLog{})
 | 
			
		||||
	for _, opt := range opts {
 | 
			
		||||
| 
						 | 
				
			
			@ -76,18 +74,8 @@ func (u *UpgradeLogRepo) Page(page, size int, opts ...DBOption) (int64, []model.
 | 
			
		|||
	return count, ops, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *UpgradeLogRepo) WithByNodeID(nodeID uint) DBOption {
 | 
			
		||||
func (c *UpgradeLogRepo) WithByNodeID(nodeID uint) global.DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("node_id = ?", nodeID)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *UpgradeLogRepo) WithByID(id uint) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("id = ?", id)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
func (c *UpgradeLogRepo) WithByIDs(ids []uint) DBOption {
 | 
			
		||||
	return func(g *gorm.DB) *gorm.DB {
 | 
			
		||||
		return g.Where("id in (?)", ids)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,8 +2,8 @@ package service
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/dto"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/repo"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/constant"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
	"github.com/jinzhu/copier"
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -66,15 +66,15 @@ func (u *CommandService) SearchForTree(req dto.OperateByType) ([]dto.CommandTree
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (u *CommandService) SearchWithPage(req dto.SearchCommandWithPage) (int64, interface{}, error) {
 | 
			
		||||
	options := []repo.DBOption{
 | 
			
		||||
	options := []global.DBOption{
 | 
			
		||||
		commonRepo.WithOrderRuleBy(req.OrderBy, req.Order),
 | 
			
		||||
		commonRepo.WithByType(req.Type),
 | 
			
		||||
	}
 | 
			
		||||
	if len(req.Info) != 0 {
 | 
			
		||||
		options = append(options, commonRepo.WithLikeName(req.Info))
 | 
			
		||||
		options = append(options, commandRepo.WithByInfo(req.Info))
 | 
			
		||||
	}
 | 
			
		||||
	if req.GroupID != 0 {
 | 
			
		||||
		options = append(options, groupRepo.WithByGroupID(req.GroupID))
 | 
			
		||||
		options = append(options, commonRepo.WithByGroupID(req.GroupID))
 | 
			
		||||
	}
 | 
			
		||||
	total, commands, err := commandRepo.Page(req.Page, req.PageSize, options...)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,14 +3,15 @@ package service
 | 
			
		|||
import "github.com/1Panel-dev/1Panel/core/app/repo"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	hostRepo     = repo.NewIHostRepo()
 | 
			
		||||
	commandRepo  = repo.NewICommandRepo()
 | 
			
		||||
	commonRepo   = repo.NewICommonRepo()
 | 
			
		||||
	settingRepo  = repo.NewISettingRepo()
 | 
			
		||||
	backupRepo   = repo.NewIBackupRepo()
 | 
			
		||||
	logRepo      = repo.NewILogRepo()
 | 
			
		||||
	groupRepo    = repo.NewIGroupRepo()
 | 
			
		||||
	launcherRepo = repo.NewILauncherRepo()
 | 
			
		||||
	hostRepo       = repo.NewIHostRepo()
 | 
			
		||||
	commandRepo    = repo.NewICommandRepo()
 | 
			
		||||
	commonRepo     = repo.NewICommonRepo()
 | 
			
		||||
	settingRepo    = repo.NewISettingRepo()
 | 
			
		||||
	backupRepo     = repo.NewIBackupRepo()
 | 
			
		||||
	logRepo        = repo.NewILogRepo()
 | 
			
		||||
	groupRepo      = repo.NewIGroupRepo()
 | 
			
		||||
	launcherRepo   = repo.NewILauncherRepo()
 | 
			
		||||
	upgradeLogRepo = repo.NewIUpgradeLogRepo()
 | 
			
		||||
 | 
			
		||||
	taskRepo = repo.NewITaskRepo()
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,9 +7,9 @@ import (
 | 
			
		|||
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/dto"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/model"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/repo"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/buserr"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/constant"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
	httpUtils "github.com/1Panel-dev/1Panel/core/utils/http"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/utils/xpack"
 | 
			
		||||
	"github.com/jinzhu/copier"
 | 
			
		||||
| 
						 | 
				
			
			@ -30,11 +30,13 @@ func NewIGroupService() IGroupService {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (u *GroupService) List(req dto.OperateByType) ([]dto.GroupInfo, error) {
 | 
			
		||||
	options := []repo.DBOption{
 | 
			
		||||
		commonRepo.WithByType(req.Type),
 | 
			
		||||
	options := []global.DBOption{
 | 
			
		||||
		commonRepo.WithOrderBy("is_default desc"),
 | 
			
		||||
		commonRepo.WithOrderBy("created_at desc"),
 | 
			
		||||
	}
 | 
			
		||||
	if len(req.Type) != 0 {
 | 
			
		||||
		options = append(options, commonRepo.WithByType(req.Type))
 | 
			
		||||
	}
 | 
			
		||||
	var (
 | 
			
		||||
		groups []model.Group
 | 
			
		||||
		err    error
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,8 +6,8 @@ import (
 | 
			
		|||
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/dto"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/model"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/repo"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/constant"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/utils/encrypt"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/utils/ssh"
 | 
			
		||||
	"github.com/jinzhu/copier"
 | 
			
		||||
| 
						 | 
				
			
			@ -151,12 +151,12 @@ func (u *HostService) GetHostInfo(id uint) (*model.Host, error) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (u *HostService) SearchWithPage(req dto.SearchHostWithPage) (int64, interface{}, error) {
 | 
			
		||||
	var options []repo.DBOption
 | 
			
		||||
	var options []global.DBOption
 | 
			
		||||
	if len(req.Info) != 0 {
 | 
			
		||||
		options = append(options, commonRepo.WithLikeName(req.Info))
 | 
			
		||||
		options = append(options, hostRepo.WithByInfo(req.Info))
 | 
			
		||||
	}
 | 
			
		||||
	if req.GroupID != 0 {
 | 
			
		||||
		options = append(options, groupRepo.WithByGroupID(req.GroupID))
 | 
			
		||||
		options = append(options, commonRepo.WithByGroupID(req.GroupID))
 | 
			
		||||
	}
 | 
			
		||||
	total, hosts, err := hostRepo.Page(req.Page, req.PageSize, options...)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -74,12 +74,19 @@ func (u *LogService) ListSystemLogFile() ([]string, error) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (u *LogService) PageLoginLog(req dto.SearchLgLogWithPage) (int64, interface{}, error) {
 | 
			
		||||
	options := []global.DBOption{
 | 
			
		||||
		commonRepo.WithOrderBy("created_at desc"),
 | 
			
		||||
	}
 | 
			
		||||
	if len(req.IP) != 0 {
 | 
			
		||||
		options = append(options, logRepo.WithByIP(req.IP))
 | 
			
		||||
	}
 | 
			
		||||
	if len(req.Status) != 0 {
 | 
			
		||||
		options = append(options, commonRepo.WithByStatus(req.Status))
 | 
			
		||||
	}
 | 
			
		||||
	total, ops, err := logRepo.PageLoginLog(
 | 
			
		||||
		req.Page,
 | 
			
		||||
		req.PageSize,
 | 
			
		||||
		logRepo.WithByIP(req.IP),
 | 
			
		||||
		logRepo.WithByStatus(req.Status),
 | 
			
		||||
		commonRepo.WithOrderBy("created_at desc"),
 | 
			
		||||
		options...,
 | 
			
		||||
	)
 | 
			
		||||
	var dtoOps []dto.LoginLog
 | 
			
		||||
	for _, op := range ops {
 | 
			
		||||
| 
						 | 
				
			
			@ -97,13 +104,21 @@ func (u *LogService) CreateOperationLog(operation *model.OperationLog) error {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (u *LogService) PageOperationLog(req dto.SearchOpLogWithPage) (int64, interface{}, error) {
 | 
			
		||||
	options := []global.DBOption{
 | 
			
		||||
		commonRepo.WithOrderBy("created_at desc"),
 | 
			
		||||
		logRepo.WithByLikeOperation(req.Operation),
 | 
			
		||||
	}
 | 
			
		||||
	if len(req.Source) != 0 {
 | 
			
		||||
		options = append(options, logRepo.WithBySource(req.Source))
 | 
			
		||||
	}
 | 
			
		||||
	if len(req.Status) != 0 {
 | 
			
		||||
		options = append(options, commonRepo.WithByStatus(req.Status))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	total, ops, err := logRepo.PageOperationLog(
 | 
			
		||||
		req.Page,
 | 
			
		||||
		req.PageSize,
 | 
			
		||||
		logRepo.WithByGroup(req.Source),
 | 
			
		||||
		logRepo.WithByLikeOperation(req.Operation),
 | 
			
		||||
		logRepo.WithByStatus(req.Status),
 | 
			
		||||
		commonRepo.WithOrderBy("created_at desc"),
 | 
			
		||||
		options...,
 | 
			
		||||
	)
 | 
			
		||||
	var dtoOps []dto.OperationLog
 | 
			
		||||
	for _, op := range ops {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ package service
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/dto"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/repo"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type TaskLogService struct{}
 | 
			
		||||
| 
						 | 
				
			
			@ -16,7 +16,7 @@ func NewITaskService() ITaskLogService {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error) {
 | 
			
		||||
	opts := []repo.DBOption{
 | 
			
		||||
	opts := []global.DBOption{
 | 
			
		||||
		commonRepo.WithOrderBy("created_at desc"),
 | 
			
		||||
	}
 | 
			
		||||
	if req.Status != "" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,7 @@ import (
 | 
			
		|||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/dto"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/app/model"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/constant"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/global"
 | 
			
		||||
	"github.com/1Panel-dev/1Panel/core/utils/cmd"
 | 
			
		||||
| 
						 | 
				
			
			@ -23,6 +24,7 @@ type UpgradeService struct{}
 | 
			
		|||
 | 
			
		||||
type IUpgradeService interface {
 | 
			
		||||
	Upgrade(req dto.Upgrade) error
 | 
			
		||||
	Rollback(req dto.OperateByID) error
 | 
			
		||||
	LoadNotes(req dto.Upgrade) (string, error)
 | 
			
		||||
	SearchUpgrade() (*dto.UpgradeInfo, error)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -127,6 +129,9 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
 | 
			
		|||
			_ = settingRepo.Update("SystemStatus", "Free")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		itemLog := model.UpgradeLog{NodeID: 0, OldVersion: global.CONF.System.Version, NewVersion: req.Version, BackupFile: originalDir}
 | 
			
		||||
		_ = upgradeLogRepo.Create(&itemLog)
 | 
			
		||||
 | 
			
		||||
		global.LOG.Info("backup original data successful, now start to upgrade!")
 | 
			
		||||
 | 
			
		||||
		if err := files.CopyItem(false, true, path.Join(tmpDir, "1panel*"), "/usr/local/bin"); err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -161,6 +166,15 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
 | 
			
		|||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UpgradeService) Rollback(req dto.OperateByID) error {
 | 
			
		||||
	log, _ := upgradeLogRepo.Get(commonRepo.WithByID(req.ID))
 | 
			
		||||
	if log.ID == 0 {
 | 
			
		||||
		return constant.ErrRecordNotFound
 | 
			
		||||
	}
 | 
			
		||||
	u.handleRollback(log.BackupFile, 3)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (u *UpgradeService) handleBackup(originalDir string) error {
 | 
			
		||||
	if err := files.CopyItem(false, true, "/usr/local/bin/1panel*", originalDir); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,3 +26,5 @@ var (
 | 
			
		|||
 | 
			
		||||
	BackupAccountTokenEntryID cron.EntryID
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DBOption func(*gorm.DB) *gorm.DB
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -168,7 +168,7 @@ var InitHost = &gormigrate.Migration{
 | 
			
		|||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		host := model.Host{
 | 
			
		||||
			Name: "localhost", Addr: "127.0.0.1", User: "root", Port: 22, AuthMode: "password", GroupID: hostGroup.ID,
 | 
			
		||||
			Name: "local", Addr: "127.0.0.1", User: "root", Port: 22, AuthMode: "password", GroupID: hostGroup.ID,
 | 
			
		||||
		}
 | 
			
		||||
		if err := tx.Create(&host).Error; err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,69 +32,26 @@
 | 
			
		|||
            <span>({{ $t('setting.upgradeCheck') }})</span>
 | 
			
		||||
        </el-button>
 | 
			
		||||
        <el-tag v-if="version === 'Waiting'" round style="margin-left: 10px">{{ $t('setting.upgrading') }}</el-tag>
 | 
			
		||||
 | 
			
		||||
        <Upgrade ref="upgradeRef" @search="search" />
 | 
			
		||||
    </div>
 | 
			
		||||
    <el-drawer
 | 
			
		||||
        :close-on-click-modal="false"
 | 
			
		||||
        :close-on-press-escape="false"
 | 
			
		||||
        :key="refresh"
 | 
			
		||||
        v-model="drawerVisible"
 | 
			
		||||
        size="50%"
 | 
			
		||||
        append-to-body
 | 
			
		||||
    >
 | 
			
		||||
        <template #header>
 | 
			
		||||
            <DrawerHeader :header="$t('commons.button.upgrade')" :back="handleClose" />
 | 
			
		||||
        </template>
 | 
			
		||||
        <div class="panel-MdEditor">
 | 
			
		||||
            <el-alert :closable="false">
 | 
			
		||||
                <span class="line-height">{{ $t('setting.versionHelper') }}</span>
 | 
			
		||||
                <li class="line-height">{{ $t('setting.versionHelper1') }}</li>
 | 
			
		||||
                <li class="line-height">{{ $t('setting.versionHelper2') }}</li>
 | 
			
		||||
            </el-alert>
 | 
			
		||||
            <div class="default-theme" style="margin-left: 20px">
 | 
			
		||||
                <h2 class="inline-block">{{ $t('app.version') }}</h2>
 | 
			
		||||
            </div>
 | 
			
		||||
            <el-radio-group class="inline-block tag" v-model="upgradeVersion" @change="changeOption">
 | 
			
		||||
                <el-radio v-if="upgradeInfo.newVersion" :value="upgradeInfo.newVersion">
 | 
			
		||||
                    {{ upgradeInfo.newVersion }}
 | 
			
		||||
                </el-radio>
 | 
			
		||||
                <el-radio v-if="upgradeInfo.latestVersion" :value="upgradeInfo.latestVersion">
 | 
			
		||||
                    {{ upgradeInfo.latestVersion }}
 | 
			
		||||
                </el-radio>
 | 
			
		||||
                <el-radio v-if="upgradeInfo.testVersion" :value="upgradeInfo.testVersion">
 | 
			
		||||
                    {{ upgradeInfo.testVersion }}
 | 
			
		||||
                </el-radio>
 | 
			
		||||
            </el-radio-group>
 | 
			
		||||
            <MdEditor v-model="upgradeInfo.releaseNote" previewOnly :theme="isDarkTheme ? 'dark' : 'light'" />
 | 
			
		||||
        </div>
 | 
			
		||||
        <template #footer>
 | 
			
		||||
            <span class="dialog-footer">
 | 
			
		||||
                <el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button>
 | 
			
		||||
                <el-button type="primary" @click="onUpgrade">{{ $t('setting.upgradeNow') }}</el-button>
 | 
			
		||||
            </span>
 | 
			
		||||
        </template>
 | 
			
		||||
    </el-drawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import DrawerHeader from '@/components/drawer-header/index.vue';
 | 
			
		||||
import { getSettingInfo, loadReleaseNotes, loadUpgradeInfo, upgrade } from '@/api/modules/setting';
 | 
			
		||||
import MdEditor from 'md-editor-v3';
 | 
			
		||||
import { getSettingInfo, loadUpgradeInfo } from '@/api/modules/setting';
 | 
			
		||||
import Upgrade from '@/components/system-upgrade/upgrade/index.vue';
 | 
			
		||||
import i18n from '@/lang';
 | 
			
		||||
import 'md-editor-v3/lib/style.css';
 | 
			
		||||
import { MsgSuccess } from '@/utils/message';
 | 
			
		||||
import { onMounted, ref } from 'vue';
 | 
			
		||||
import { GlobalStore } from '@/store';
 | 
			
		||||
import { ElMessageBox } from 'element-plus';
 | 
			
		||||
import { storeToRefs } from 'pinia';
 | 
			
		||||
 | 
			
		||||
const globalStore = GlobalStore();
 | 
			
		||||
const { isDarkTheme } = storeToRefs(globalStore);
 | 
			
		||||
const upgradeRef = ref();
 | 
			
		||||
 | 
			
		||||
const version = ref<string>('');
 | 
			
		||||
const isProductPro = ref();
 | 
			
		||||
const loading = ref(false);
 | 
			
		||||
const drawerVisible = ref(false);
 | 
			
		||||
const upgradeInfo = ref();
 | 
			
		||||
const refresh = ref();
 | 
			
		||||
const upgradeVersion = ref();
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
    footer: {
 | 
			
		||||
| 
						 | 
				
			
			@ -108,10 +65,6 @@ const search = async () => {
 | 
			
		|||
    version.value = res.data.systemVersion;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const handleClose = () => {
 | 
			
		||||
    drawerVisible.value = false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const toHalo = () => {
 | 
			
		||||
    window.open('https://www.lxware.cn/1panel' + '', '_blank', 'noopener,noreferrer');
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -135,7 +88,6 @@ const onLoadUpgradeInfo = async () => {
 | 
			
		|||
            loading.value = false;
 | 
			
		||||
            if (res.data.testVersion || res.data.newVersion || res.data.latestVersion) {
 | 
			
		||||
                upgradeInfo.value = res.data;
 | 
			
		||||
                drawerVisible.value = true;
 | 
			
		||||
                if (upgradeInfo.value.newVersion) {
 | 
			
		||||
                    upgradeVersion.value = upgradeInfo.value.newVersion;
 | 
			
		||||
                    return;
 | 
			
		||||
| 
						 | 
				
			
			@ -148,6 +100,7 @@ const onLoadUpgradeInfo = async () => {
 | 
			
		|||
                    upgradeVersion.value = upgradeInfo.value.testVersion;
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                upgradeRef.value.acceptParams({ upgradeInfo: upgradeInfo.value, upgradeVersion: upgradeVersion.value });
 | 
			
		||||
            } else {
 | 
			
		||||
                MsgSuccess(i18n.global.t('setting.noUpgrade'));
 | 
			
		||||
                return;
 | 
			
		||||
| 
						 | 
				
			
			@ -158,26 +111,6 @@ const onLoadUpgradeInfo = async () => {
 | 
			
		|||
        });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const changeOption = async () => {
 | 
			
		||||
    const res = await loadReleaseNotes(upgradeVersion.value);
 | 
			
		||||
    upgradeInfo.value.releaseNote = res.data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const onUpgrade = async () => {
 | 
			
		||||
    ElMessageBox.confirm(i18n.global.t('setting.upgradeHelper', i18n.global.t('commons.button.upgrade')), {
 | 
			
		||||
        confirmButtonText: i18n.global.t('commons.button.confirm'),
 | 
			
		||||
        cancelButtonText: i18n.global.t('commons.button.cancel'),
 | 
			
		||||
        type: 'info',
 | 
			
		||||
    }).then(async () => {
 | 
			
		||||
        globalStore.isLoading = true;
 | 
			
		||||
        await upgrade(upgradeVersion.value);
 | 
			
		||||
        globalStore.isOnRestart = true;
 | 
			
		||||
        drawerVisible.value = false;
 | 
			
		||||
        MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
 | 
			
		||||
        search();
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
onMounted(() => {
 | 
			
		||||
    isProductPro.value = globalStore.isProductPro;
 | 
			
		||||
    search();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										127
									
								
								frontend/src/components/system-upgrade/upgrade/index.vue
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								frontend/src/components/system-upgrade/upgrade/index.vue
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,127 @@
 | 
			
		|||
<template>
 | 
			
		||||
    <el-drawer
 | 
			
		||||
        :close-on-click-modal="false"
 | 
			
		||||
        :close-on-press-escape="false"
 | 
			
		||||
        :key="refresh"
 | 
			
		||||
        v-model="drawerVisible"
 | 
			
		||||
        size="50%"
 | 
			
		||||
        append-to-body
 | 
			
		||||
    >
 | 
			
		||||
        <template #header>
 | 
			
		||||
            <DrawerHeader :header="$t('commons.button.upgrade')" :back="handleClose" />
 | 
			
		||||
        </template>
 | 
			
		||||
        <div class="panel-MdEditor">
 | 
			
		||||
            <el-alert :closable="false">
 | 
			
		||||
                <span class="line-height">{{ $t('setting.versionHelper') }}</span>
 | 
			
		||||
                <li class="line-height">{{ $t('setting.versionHelper1') }}</li>
 | 
			
		||||
                <li class="line-height">{{ $t('setting.versionHelper2') }}</li>
 | 
			
		||||
            </el-alert>
 | 
			
		||||
            <div class="default-theme" style="margin-left: 20px">
 | 
			
		||||
                <h2 class="inline-block">{{ $t('app.version') }}</h2>
 | 
			
		||||
            </div>
 | 
			
		||||
            <el-radio-group class="inline-block tag" v-model="upgradeVersion" @change="changeOption">
 | 
			
		||||
                <el-radio v-if="upgradeInfo.newVersion" :value="upgradeInfo.newVersion">
 | 
			
		||||
                    {{ upgradeInfo.newVersion }}
 | 
			
		||||
                </el-radio>
 | 
			
		||||
                <el-radio v-if="upgradeInfo.latestVersion" :value="upgradeInfo.latestVersion">
 | 
			
		||||
                    {{ upgradeInfo.latestVersion }}
 | 
			
		||||
                </el-radio>
 | 
			
		||||
                <el-radio v-if="upgradeInfo.testVersion" :value="upgradeInfo.testVersion">
 | 
			
		||||
                    {{ upgradeInfo.testVersion }}
 | 
			
		||||
                </el-radio>
 | 
			
		||||
            </el-radio-group>
 | 
			
		||||
            <MdEditor v-model="upgradeInfo.releaseNote" previewOnly :theme="isDarkTheme ? 'dark' : 'light'" />
 | 
			
		||||
        </div>
 | 
			
		||||
        <template #footer>
 | 
			
		||||
            <span class="dialog-footer">
 | 
			
		||||
                <el-button @click="drawerVisible = false">{{ $t('commons.button.cancel') }}</el-button>
 | 
			
		||||
                <el-button type="primary" @click="onUpgrade">{{ $t('setting.upgradeNow') }}</el-button>
 | 
			
		||||
            </span>
 | 
			
		||||
        </template>
 | 
			
		||||
    </el-drawer>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import DrawerHeader from '@/components/drawer-header/index.vue';
 | 
			
		||||
import { loadReleaseNotes, upgrade } from '@/api/modules/setting';
 | 
			
		||||
import MdEditor from 'md-editor-v3';
 | 
			
		||||
import i18n from '@/lang';
 | 
			
		||||
import 'md-editor-v3/lib/style.css';
 | 
			
		||||
import { MsgSuccess } from '@/utils/message';
 | 
			
		||||
import { ref } from 'vue';
 | 
			
		||||
import { GlobalStore } from '@/store';
 | 
			
		||||
import { ElMessageBox } from 'element-plus';
 | 
			
		||||
import { storeToRefs } from 'pinia';
 | 
			
		||||
 | 
			
		||||
const globalStore = GlobalStore();
 | 
			
		||||
const { isDarkTheme } = storeToRefs(globalStore);
 | 
			
		||||
 | 
			
		||||
const drawerVisible = ref(false);
 | 
			
		||||
const upgradeInfo = ref();
 | 
			
		||||
const refresh = ref();
 | 
			
		||||
const upgradeVersion = ref();
 | 
			
		||||
 | 
			
		||||
interface DialogProps {
 | 
			
		||||
    upgradeInfo: number;
 | 
			
		||||
    upgradeVersion: string;
 | 
			
		||||
}
 | 
			
		||||
const acceptParams = (params: DialogProps): void => {
 | 
			
		||||
    console.log(params);
 | 
			
		||||
    upgradeInfo.value = params.upgradeInfo;
 | 
			
		||||
    upgradeVersion.value = params.upgradeVersion;
 | 
			
		||||
    drawerVisible.value = true;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const emit = defineEmits(['search']);
 | 
			
		||||
 | 
			
		||||
const handleClose = () => {
 | 
			
		||||
    drawerVisible.value = false;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const changeOption = async () => {
 | 
			
		||||
    const res = await loadReleaseNotes(upgradeVersion.value);
 | 
			
		||||
    upgradeInfo.value.releaseNote = res.data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const onUpgrade = async () => {
 | 
			
		||||
    ElMessageBox.confirm(i18n.global.t('setting.upgradeHelper', i18n.global.t('commons.button.upgrade')), {
 | 
			
		||||
        confirmButtonText: i18n.global.t('commons.button.confirm'),
 | 
			
		||||
        cancelButtonText: i18n.global.t('commons.button.cancel'),
 | 
			
		||||
        type: 'info',
 | 
			
		||||
    }).then(async () => {
 | 
			
		||||
        globalStore.isLoading = true;
 | 
			
		||||
        await upgrade(upgradeVersion.value);
 | 
			
		||||
        globalStore.isOnRestart = true;
 | 
			
		||||
        drawerVisible.value = false;
 | 
			
		||||
        MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
 | 
			
		||||
        emit('search');
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
defineExpose({
 | 
			
		||||
    acceptParams,
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="scss" scoped>
 | 
			
		||||
.line-height {
 | 
			
		||||
    line-height: 25px;
 | 
			
		||||
}
 | 
			
		||||
.panel-MdEditor {
 | 
			
		||||
    height: calc(100vh - 330px);
 | 
			
		||||
    .tag {
 | 
			
		||||
        margin-top: -6px;
 | 
			
		||||
        margin-left: 20px;
 | 
			
		||||
        vertical-align: middle;
 | 
			
		||||
    }
 | 
			
		||||
    :deep(.md-editor-preview) {
 | 
			
		||||
        font-size: 14px;
 | 
			
		||||
    }
 | 
			
		||||
    :deep(.default-theme h2) {
 | 
			
		||||
        color: var(--dark-gold-base-color);
 | 
			
		||||
        margin: 13px, 0;
 | 
			
		||||
        padding: 0;
 | 
			
		||||
        font-size: 16px;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
| 
						 | 
				
			
			@ -985,6 +985,8 @@ const message = {
 | 
			
		|||
        fanSpeed: 'Fan Speed',
 | 
			
		||||
    },
 | 
			
		||||
    terminal: {
 | 
			
		||||
        local: 'Local',
 | 
			
		||||
        localHelper: 'The `local` name is used only for system local identification',
 | 
			
		||||
        conn: 'connection',
 | 
			
		||||
        connLocalErr: 'Unable to automatically authenticate, please fill in the local server login information!',
 | 
			
		||||
        testConn: 'Test connection',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -940,6 +940,8 @@ const message = {
 | 
			
		|||
        fanSpeed: '風扇轉速',
 | 
			
		||||
    },
 | 
			
		||||
    terminal: {
 | 
			
		||||
        local: '本機',
 | 
			
		||||
        localHelper: 'local 名稱僅用於系統本機標識',
 | 
			
		||||
        conn: '連接',
 | 
			
		||||
        connLocalErr: '無法自動認證,請填寫本地服務器的登錄信息!',
 | 
			
		||||
        testConn: '連接測試',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -941,6 +941,8 @@ const message = {
 | 
			
		|||
        fanSpeed: '风扇转速',
 | 
			
		||||
    },
 | 
			
		||||
    terminal: {
 | 
			
		||||
        local: '本机',
 | 
			
		||||
        localHelper: 'local 名称仅用于系统本机标识',
 | 
			
		||||
        conn: '连接',
 | 
			
		||||
        connLocalErr: '无法自动认证,请填写本地服务器的登录信息!',
 | 
			
		||||
        testConn: '连接测试',
 | 
			
		||||
| 
						 | 
				
			
			@ -1499,7 +1501,7 @@ const message = {
 | 
			
		|||
        rollbackHelper:
 | 
			
		||||
            '即将回滚本次恢复,回滚将替换所有本次恢复的文件,过程中可能需要重启 Docker 以及 1Panel 服务,是否继续?',
 | 
			
		||||
 | 
			
		||||
        upgradeRecord: '升级记录',
 | 
			
		||||
        upgradeRecord: '更新记录',
 | 
			
		||||
        upgrading: '正在升级中,请稍候...',
 | 
			
		||||
        upgradeHelper: '升级操作需要重启 1Panel 服务,是否继续?',
 | 
			
		||||
        noUpgrade: '当前已经是最新版本',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,10 +2,7 @@
 | 
			
		|||
    <DrawerPro v-model="drawerVisible" :header="$t('terminal.host')" :back="handleClose" size="large">
 | 
			
		||||
        <el-form ref="hostInfoRef" label-position="top" :model="dialogData.rowData" :rules="rules" v-loading="loading">
 | 
			
		||||
            <el-form-item :label="$t('terminal.ip')" prop="addr">
 | 
			
		||||
                <el-tag v-if="dialogData.rowData!.addr === '127.0.0.1' && dialogData.title === 'edit'">
 | 
			
		||||
                    {{ dialogData.rowData!.addr }}
 | 
			
		||||
                </el-tag>
 | 
			
		||||
                <el-input @change="isOK = false" v-else clearable v-model.trim="dialogData.rowData!.addr" />
 | 
			
		||||
                <el-input @change="isOK = false" clearable v-model.trim="dialogData.rowData!.addr" />
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.login.username')" prop="user">
 | 
			
		||||
                <el-input @change="isOK = false" clearable v-model="dialogData.rowData!.user" />
 | 
			
		||||
| 
						 | 
				
			
			@ -53,11 +50,18 @@
 | 
			
		|||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.table.group')" prop="groupID">
 | 
			
		||||
                <el-select filterable v-model="dialogData.rowData!.groupID" clearable style="width: 100%">
 | 
			
		||||
                    <el-option v-for="item in groupList" :key="item.id" :label="item.name" :value="item.id" />
 | 
			
		||||
                    <div v-for="item in groupList" :key="item.id">
 | 
			
		||||
                        <el-option
 | 
			
		||||
                            v-if="item.name === 'default'"
 | 
			
		||||
                            :label="$t('commons.table.default')"
 | 
			
		||||
                            :value="item.id"
 | 
			
		||||
                        />
 | 
			
		||||
                        <el-option v-else :label="item.name" :value="item.id" />
 | 
			
		||||
                    </div>
 | 
			
		||||
                </el-select>
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.table.title')" prop="name">
 | 
			
		||||
                <el-input clearable v-model="dialogData.rowData!.name" />
 | 
			
		||||
            <el-form-item :label="$t('commons.table.name')" prop="name">
 | 
			
		||||
                <el-input :disabled="itemName === 'local'" clearable v-model="dialogData.rowData!.name" />
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.table.description')" prop="description">
 | 
			
		||||
                <el-input clearable type="textarea" v-model="dialogData.rowData!.description" />
 | 
			
		||||
| 
						 | 
				
			
			@ -98,6 +102,7 @@ const drawerVisible = ref(false);
 | 
			
		|||
const dialogData = ref<DialogProps>({
 | 
			
		||||
    title: '',
 | 
			
		||||
});
 | 
			
		||||
const itemName = ref();
 | 
			
		||||
 | 
			
		||||
const groupList = ref();
 | 
			
		||||
const acceptParams = (params: DialogProps): void => {
 | 
			
		||||
| 
						 | 
				
			
			@ -119,7 +124,14 @@ const rules = reactive({
 | 
			
		|||
    port: [Rules.requiredInput, Rules.port],
 | 
			
		||||
    user: [Rules.requiredInput],
 | 
			
		||||
    authMode: [Rules.requiredSelect],
 | 
			
		||||
    name: [{ validator: checkName, trigger: 'blur' }],
 | 
			
		||||
});
 | 
			
		||||
function checkName(rule: any, value: any, callback: any) {
 | 
			
		||||
    if (value === 'local') {
 | 
			
		||||
        return callback(new Error(i18n.global.t('terminal.localHelper')));
 | 
			
		||||
    }
 | 
			
		||||
    callback();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const loadGroups = async () => {
 | 
			
		||||
    const res = await GetGroupList('host');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,8 +10,7 @@
 | 
			
		|||
                type="warning"
 | 
			
		||||
            />
 | 
			
		||||
            <el-form-item :label="$t('terminal.ip')" prop="addr">
 | 
			
		||||
                <el-input @change="isOK = false" v-if="!isLocal" clearable v-model.trim="hostInfo.addr" />
 | 
			
		||||
                <el-tag v-if="isLocal">{{ hostInfo.addr }}</el-tag>
 | 
			
		||||
                <el-input @change="isOK = false" clearable v-model.trim="hostInfo.addr" />
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.login.username')" prop="user">
 | 
			
		||||
                <el-input @change="isOK = false" clearable v-model="hostInfo.user" />
 | 
			
		||||
| 
						 | 
				
			
			@ -43,8 +42,17 @@
 | 
			
		|||
            <el-form-item class="mt-2.5" :label="$t('commons.table.port')" prop="port">
 | 
			
		||||
                <el-input @change="isOK = false" clearable v-model.number="hostInfo.port" />
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.table.title')" prop="name">
 | 
			
		||||
                <el-input clearable v-model="hostInfo.name" />
 | 
			
		||||
            <el-form-item :label="$t('commons.table.group')" prop="groupID">
 | 
			
		||||
                <el-select filterable v-model="hostInfo.groupID" clearable style="width: 100%">
 | 
			
		||||
                    <div v-for="item in groupList" :key="item.id">
 | 
			
		||||
                        <el-option
 | 
			
		||||
                            v-if="item.name === 'default'"
 | 
			
		||||
                            :label="$t('commons.table.default')"
 | 
			
		||||
                            :value="item.id"
 | 
			
		||||
                        />
 | 
			
		||||
                        <el-option v-else :label="item.name" :value="item.id" />
 | 
			
		||||
                    </div>
 | 
			
		||||
                </el-select>
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
            <el-form-item :label="$t('commons.table.description')" prop="description">
 | 
			
		||||
                <el-input clearable v-model="hostInfo.description" />
 | 
			
		||||
| 
						 | 
				
			
			@ -72,12 +80,15 @@ import { addHost, testByInfo } from '@/api/modules/terminal';
 | 
			
		|||
import i18n from '@/lang';
 | 
			
		||||
import { reactive, ref } from 'vue';
 | 
			
		||||
import { MsgError, MsgSuccess } from '@/utils/message';
 | 
			
		||||
import { GetGroupList } from '@/api/modules/group';
 | 
			
		||||
 | 
			
		||||
const dialogVisible = ref();
 | 
			
		||||
const isOK = ref(false);
 | 
			
		||||
type FormInstance = InstanceType<typeof ElForm>;
 | 
			
		||||
const hostRef = ref<FormInstance>();
 | 
			
		||||
 | 
			
		||||
const groupList = ref();
 | 
			
		||||
 | 
			
		||||
let hostInfo = reactive<Host.HostOperate>({
 | 
			
		||||
    id: 0,
 | 
			
		||||
    name: '',
 | 
			
		||||
| 
						 | 
				
			
			@ -122,6 +133,7 @@ const acceptParams = (props: DialogProps) => {
 | 
			
		|||
        hostInfo.addr = '127.0.0.1';
 | 
			
		||||
        hostInfo.user = 'root';
 | 
			
		||||
    }
 | 
			
		||||
    loadGroups();
 | 
			
		||||
    dialogVisible.value = true;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -163,6 +175,17 @@ const submitAddHost = (formEl: FormInstance | undefined, ops: string) => {
 | 
			
		|||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const loadGroups = async () => {
 | 
			
		||||
    const res = await GetGroupList('host');
 | 
			
		||||
    groupList.value = res.data;
 | 
			
		||||
    for (const item of groupList.value) {
 | 
			
		||||
        if (item.isDefault) {
 | 
			
		||||
            hostInfo.groupID = item.id;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
defineExpose({
 | 
			
		||||
    acceptParams,
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue