mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
pref: Adjust node editing logic (#7217)
This commit is contained in:
parent
9b0916f0ed
commit
841d1a31bf
@ -65,3 +65,25 @@ func (b *BaseApi) Upgrade(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
helper.SuccessWithData(c, nil)
|
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 LauncherRepo struct{}
|
||||||
|
|
||||||
type ILauncherRepo interface {
|
type ILauncherRepo interface {
|
||||||
Get(opts ...DBOption) (model.AppLauncher, error)
|
Get(opts ...global.DBOption) (model.AppLauncher, error)
|
||||||
List(opts ...DBOption) ([]model.AppLauncher, error)
|
List(opts ...global.DBOption) ([]model.AppLauncher, error)
|
||||||
Create(launcher *model.AppLauncher) error
|
Create(launcher *model.AppLauncher) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...global.DBOption) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewILauncherRepo() ILauncherRepo {
|
func NewILauncherRepo() ILauncherRepo {
|
||||||
return &LauncherRepo{}
|
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
|
var launcher model.AppLauncher
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -27,7 +27,7 @@ func (u *LauncherRepo) Get(opts ...DBOption) (model.AppLauncher, error) {
|
|||||||
err := db.First(&launcher).Error
|
err := db.First(&launcher).Error
|
||||||
return launcher, err
|
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
|
var ops []model.AppLauncher
|
||||||
db := global.DB.Model(&model.AppLauncher{})
|
db := global.DB.Model(&model.AppLauncher{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -41,7 +41,7 @@ func (u *LauncherRepo) Create(launcher *model.AppLauncher) error {
|
|||||||
return global.DB.Create(launcher).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
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
|
@ -8,19 +8,19 @@ import (
|
|||||||
type BackupRepo struct{}
|
type BackupRepo struct{}
|
||||||
|
|
||||||
type IBackupRepo interface {
|
type IBackupRepo interface {
|
||||||
Get(opts ...DBOption) (model.BackupAccount, error)
|
Get(opts ...global.DBOption) (model.BackupAccount, error)
|
||||||
List(opts ...DBOption) ([]model.BackupAccount, error)
|
List(opts ...global.DBOption) ([]model.BackupAccount, error)
|
||||||
Page(limit, offset int, opts ...DBOption) (int64, []model.BackupAccount, error)
|
Page(limit, offset int, opts ...global.DBOption) (int64, []model.BackupAccount, error)
|
||||||
Create(backup *model.BackupAccount) error
|
Create(backup *model.BackupAccount) error
|
||||||
Save(backup *model.BackupAccount) error
|
Save(backup *model.BackupAccount) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...global.DBOption) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIBackupRepo() IBackupRepo {
|
func NewIBackupRepo() IBackupRepo {
|
||||||
return &BackupRepo{}
|
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
|
var backup model.BackupAccount
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -30,7 +30,7 @@ func (u *BackupRepo) Get(opts ...DBOption) (model.BackupAccount, error) {
|
|||||||
return backup, err
|
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
|
var ops []model.BackupAccount
|
||||||
db := global.DB.Model(&model.BackupAccount{})
|
db := global.DB.Model(&model.BackupAccount{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -42,7 +42,7 @@ func (u *BackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.Back
|
|||||||
return count, ops, err
|
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
|
var ops []model.BackupAccount
|
||||||
db := global.DB.Model(&model.BackupAccount{})
|
db := global.DB.Model(&model.BackupAccount{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -60,7 +60,7 @@ func (u *BackupRepo) Save(backup *model.BackupAccount) error {
|
|||||||
return global.DB.Save(backup).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
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
|
@ -3,25 +3,28 @@ package repo
|
|||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/core/app/model"
|
"github.com/1Panel-dev/1Panel/core/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommandRepo struct{}
|
type CommandRepo struct{}
|
||||||
|
|
||||||
type ICommandRepo interface {
|
type ICommandRepo interface {
|
||||||
List(opts ...DBOption) ([]model.Command, error)
|
List(opts ...global.DBOption) ([]model.Command, error)
|
||||||
Page(limit, offset int, opts ...DBOption) (int64, []model.Command, error)
|
Page(limit, offset int, opts ...global.DBOption) (int64, []model.Command, error)
|
||||||
Create(command *model.Command) error
|
Create(command *model.Command) error
|
||||||
Update(id uint, vars map[string]interface{}) error
|
Update(id uint, vars map[string]interface{}) error
|
||||||
UpdateGroup(group, newGroup uint) error
|
UpdateGroup(group, newGroup uint) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...global.DBOption) error
|
||||||
Get(opts ...DBOption) (model.Command, error)
|
Get(opts ...global.DBOption) (model.Command, error)
|
||||||
|
|
||||||
|
WithByInfo(info string) global.DBOption
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewICommandRepo() ICommandRepo {
|
func NewICommandRepo() ICommandRepo {
|
||||||
return &CommandRepo{}
|
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
|
var command model.Command
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -31,7 +34,7 @@ func (u *CommandRepo) Get(opts ...DBOption) (model.Command, error) {
|
|||||||
return command, err
|
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
|
var users []model.Command
|
||||||
db := global.DB.Model(&model.Command{})
|
db := global.DB.Model(&model.Command{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -43,7 +46,7 @@ func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Com
|
|||||||
return count, users, err
|
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
|
var commands []model.Command
|
||||||
db := global.DB.Model(&model.Command{})
|
db := global.DB.Model(&model.Command{})
|
||||||
for _, opt := range opts {
|
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
|
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
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
}
|
}
|
||||||
return db.Delete(&model.Command{}).Error
|
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"
|
"fmt"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/core/constant"
|
"github.com/1Panel-dev/1Panel/core/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBOption func(*gorm.DB) *gorm.DB
|
|
||||||
|
|
||||||
type ICommonRepo interface {
|
type ICommonRepo interface {
|
||||||
WithByID(id uint) DBOption
|
WithByID(id uint) global.DBOption
|
||||||
WithByIDs(ids []uint) DBOption
|
WithByGroupID(id uint) global.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
|
|
||||||
|
|
||||||
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{}
|
type CommonRepo struct{}
|
||||||
@ -28,57 +30,56 @@ func NewICommonRepo() ICommonRepo {
|
|||||||
return &CommonRepo{}
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("id = ?", id)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("id in (?)", ids)
|
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 {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
if len(name) == 0 {
|
|
||||||
return g
|
|
||||||
}
|
|
||||||
return g.Where("`name` = ?", name)
|
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 {
|
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)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("key = ?", key)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("status = ?", status)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Order(orderStr)
|
return g.Order(orderStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption {
|
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) global.DBOption {
|
||||||
switch order {
|
switch order {
|
||||||
case constant.OrderDesc:
|
case constant.OrderDesc:
|
||||||
order = "desc"
|
order = "desc"
|
||||||
|
@ -9,16 +9,13 @@ import (
|
|||||||
type GroupRepo struct{}
|
type GroupRepo struct{}
|
||||||
|
|
||||||
type IGroupRepo interface {
|
type IGroupRepo interface {
|
||||||
Get(opts ...DBOption) (model.Group, error)
|
Get(opts ...global.DBOption) (model.Group, error)
|
||||||
GetList(opts ...DBOption) ([]model.Group, error)
|
GetList(opts ...global.DBOption) ([]model.Group, error)
|
||||||
Create(group *model.Group) error
|
Create(group *model.Group) error
|
||||||
Update(id uint, vars map[string]interface{}) error
|
Update(id uint, vars map[string]interface{}) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...global.DBOption) error
|
||||||
|
|
||||||
WithByID(id uint) DBOption
|
WithByDefault(isDefalut bool) global.DBOption
|
||||||
WithByGroupID(id uint) DBOption
|
|
||||||
WithByGroupType(ty string) DBOption
|
|
||||||
WithByDefault(isDefalut bool) DBOption
|
|
||||||
CancelDefault(groupType string) error
|
CancelDefault(groupType string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,31 +23,13 @@ func NewIGroupRepo() IGroupRepo {
|
|||||||
return &GroupRepo{}
|
return &GroupRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GroupRepo) WithByID(id uint) DBOption {
|
func (c *GroupRepo) WithByDefault(isDefalut bool) global.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 {
|
|
||||||
return func(g *gorm.DB) *gorm.DB {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("is_default = ?", isDefalut)
|
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
|
var group model.Group
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -60,7 +39,7 @@ func (u *GroupRepo) Get(opts ...DBOption) (model.Group, error) {
|
|||||||
return group, err
|
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
|
var groups []model.Group
|
||||||
db := global.DB.Model(&model.Group{})
|
db := global.DB.Model(&model.Group{})
|
||||||
for _, opt := range opts {
|
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
|
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
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
|
@ -9,25 +9,25 @@ import (
|
|||||||
type HostRepo struct{}
|
type HostRepo struct{}
|
||||||
|
|
||||||
type IHostRepo interface {
|
type IHostRepo interface {
|
||||||
Get(opts ...DBOption) (model.Host, error)
|
Get(opts ...global.DBOption) (model.Host, error)
|
||||||
GetList(opts ...DBOption) ([]model.Host, error)
|
GetList(opts ...global.DBOption) ([]model.Host, error)
|
||||||
Page(limit, offset int, opts ...DBOption) (int64, []model.Host, error)
|
Page(limit, offset int, opts ...global.DBOption) (int64, []model.Host, error)
|
||||||
Create(host *model.Host) error
|
Create(host *model.Host) error
|
||||||
Update(id uint, vars map[string]interface{}) error
|
Update(id uint, vars map[string]interface{}) error
|
||||||
UpdateGroup(group, newGroup uint) error
|
UpdateGroup(group, newGroup uint) error
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...global.DBOption) error
|
||||||
|
|
||||||
WithByInfo(info string) DBOption
|
WithByInfo(info string) global.DBOption
|
||||||
WithByPort(port uint) DBOption
|
WithByPort(port uint) global.DBOption
|
||||||
WithByUser(user string) DBOption
|
WithByUser(user string) global.DBOption
|
||||||
WithByAddr(addr string) DBOption
|
WithByAddr(addr string) global.DBOption
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIHostRepo() IHostRepo {
|
func NewIHostRepo() IHostRepo {
|
||||||
return &HostRepo{}
|
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
|
var host model.Host
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -37,7 +37,7 @@ func (h *HostRepo) Get(opts ...DBOption) (model.Host, error) {
|
|||||||
return host, err
|
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
|
var hosts []model.Host
|
||||||
db := global.DB.Model(&model.Host{})
|
db := global.DB.Model(&model.Host{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -47,7 +47,7 @@ func (h *HostRepo) GetList(opts ...DBOption) ([]model.Host, error) {
|
|||||||
return hosts, err
|
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
|
var users []model.Host
|
||||||
db := global.DB.Model(&model.Host{})
|
db := global.DB.Model(&model.Host{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -59,7 +59,7 @@ func (h *HostRepo) Page(page, size int, opts ...DBOption) (int64, []model.Host,
|
|||||||
return count, users, err
|
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 {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
if len(info) == 0 {
|
if len(info) == 0 {
|
||||||
return g
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("port = ?", port)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("user = ?", user)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("addr = ?", addr)
|
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 {
|
func (h *HostRepo) Create(host *model.Host) error {
|
||||||
return global.DB.Create(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
|
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
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
|
@ -11,16 +11,15 @@ type LogRepo struct{}
|
|||||||
type ILogRepo interface {
|
type ILogRepo interface {
|
||||||
CleanLogin() error
|
CleanLogin() error
|
||||||
CreateLoginLog(user *model.LoginLog) 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
|
CleanOperation() error
|
||||||
CreateOperationLog(user *model.OperationLog) 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
|
WithByIP(ip string) global.DBOption
|
||||||
WithByStatus(status string) DBOption
|
WithBySource(source string) global.DBOption
|
||||||
WithByGroup(group string) DBOption
|
WithByLikeOperation(operation string) global.DBOption
|
||||||
WithByLikeOperation(operation string) DBOption
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewILogRepo() ILogRepo {
|
func NewILogRepo() ILogRepo {
|
||||||
@ -35,7 +34,7 @@ func (u *LogRepo) CreateLoginLog(log *model.LoginLog) error {
|
|||||||
return global.DB.Create(log).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
|
var ops []model.LoginLog
|
||||||
db := global.DB.Model(&model.LoginLog{})
|
db := global.DB.Model(&model.LoginLog{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -55,7 +54,7 @@ func (u *LogRepo) CreateOperationLog(log *model.OperationLog) error {
|
|||||||
return global.DB.Create(log).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
|
var ops []model.OperationLog
|
||||||
db := global.DB.Model(&model.OperationLog{})
|
db := global.DB.Model(&model.OperationLog{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -67,7 +66,7 @@ func (u *LogRepo) PageOperationLog(page, size int, opts ...DBOption) (int64, []m
|
|||||||
return count, ops, err
|
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 {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
if len(status) == 0 {
|
if len(status) == 0 {
|
||||||
return g
|
return g
|
||||||
@ -75,23 +74,21 @@ func (c *LogRepo) WithByStatus(status string) DBOption {
|
|||||||
return g.Where("status = ?", status)
|
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 {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
if len(group) == 0 {
|
if len(source) == 0 {
|
||||||
return g
|
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 {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
if len(ip) == 0 {
|
|
||||||
return g
|
|
||||||
}
|
|
||||||
return g.Where("ip LIKE ?", "%"+ip+"%")
|
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 {
|
return func(g *gorm.DB) *gorm.DB {
|
||||||
if len(operation) == 0 {
|
if len(operation) == 0 {
|
||||||
return g
|
return g
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
type SettingRepo struct{}
|
type SettingRepo struct{}
|
||||||
|
|
||||||
type ISettingRepo interface {
|
type ISettingRepo interface {
|
||||||
List(opts ...DBOption) ([]model.Setting, error)
|
List(opts ...global.DBOption) ([]model.Setting, error)
|
||||||
Get(opts ...DBOption) (model.Setting, error)
|
Get(opts ...global.DBOption) (model.Setting, error)
|
||||||
Create(key, value string) error
|
Create(key, value string) error
|
||||||
Update(key, value string) error
|
Update(key, value string) error
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ func NewISettingRepo() ISettingRepo {
|
|||||||
return &SettingRepo{}
|
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
|
var settings []model.Setting
|
||||||
db := global.DB.Model(&model.Setting{})
|
db := global.DB.Model(&model.Setting{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -36,7 +36,7 @@ func (u *SettingRepo) Create(key, value string) error {
|
|||||||
return global.DB.Create(setting).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
|
var settings model.Setting
|
||||||
db := global.DB.Model(&model.Setting{})
|
db := global.DB.Model(&model.Setting{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
|
@ -13,20 +13,20 @@ type TaskRepo struct {
|
|||||||
|
|
||||||
type ITaskRepo interface {
|
type ITaskRepo interface {
|
||||||
Save(ctx context.Context, task *model.Task) error
|
Save(ctx context.Context, task *model.Task) error
|
||||||
GetFirst(opts ...DBOption) (model.Task, error)
|
GetFirst(opts ...global.DBOption) (model.Task, error)
|
||||||
Page(page, size int, opts ...DBOption) (int64, []model.Task, error)
|
Page(page, size int, opts ...global.DBOption) (int64, []model.Task, error)
|
||||||
Update(ctx context.Context, task *model.Task) error
|
Update(ctx context.Context, task *model.Task) error
|
||||||
|
|
||||||
WithByID(id string) DBOption
|
WithByID(id string) global.DBOption
|
||||||
WithResourceID(id uint) DBOption
|
WithResourceID(id uint) global.DBOption
|
||||||
WithOperate(taskOperate string) DBOption
|
WithOperate(taskOperate string) global.DBOption
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewITaskRepo() ITaskRepo {
|
func NewITaskRepo() ITaskRepo {
|
||||||
return &TaskRepo{}
|
return &TaskRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTaskDb(opts ...DBOption) *gorm.DB {
|
func getTaskDb(opts ...global.DBOption) *gorm.DB {
|
||||||
db := global.TaskDB
|
db := global.TaskDB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
@ -34,7 +34,7 @@ func getTaskDb(opts ...DBOption) *gorm.DB {
|
|||||||
return 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)
|
tx, ok := ctx.Value("db").(*gorm.DB)
|
||||||
if ok {
|
if ok {
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -45,19 +45,19 @@ func getTaskTx(ctx context.Context, opts ...DBOption) *gorm.DB {
|
|||||||
return getTaskDb(opts...)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("id = ?", id)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("operate = ?", taskOperate)
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("resource_id = ?", id)
|
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
|
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
|
var task model.Task
|
||||||
db := getTaskDb(opts...).Model(&model.Task{})
|
db := getTaskDb(opts...).Model(&model.Task{})
|
||||||
if err := db.First(&task).Error; err != nil {
|
if err := db.First(&task).Error; err != nil {
|
||||||
@ -76,7 +76,7 @@ func (t TaskRepo) GetFirst(opts ...DBOption) (model.Task, error) {
|
|||||||
return task, nil
|
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
|
var tasks []model.Task
|
||||||
db := getTaskDb(opts...).Model(&model.Task{})
|
db := getTaskDb(opts...).Model(&model.Task{})
|
||||||
count := int64(0)
|
count := int64(0)
|
||||||
|
@ -9,22 +9,20 @@ import (
|
|||||||
type UpgradeLogRepo struct{}
|
type UpgradeLogRepo struct{}
|
||||||
|
|
||||||
type IUpgradeLogRepo interface {
|
type IUpgradeLogRepo interface {
|
||||||
Get(opts ...DBOption) (model.UpgradeLog, error)
|
Get(opts ...global.DBOption) (model.UpgradeLog, error)
|
||||||
List(opts ...DBOption) ([]model.UpgradeLog, error)
|
List(opts ...global.DBOption) ([]model.UpgradeLog, error)
|
||||||
Create(log *model.UpgradeLog) error
|
Create(log *model.UpgradeLog) error
|
||||||
Page(limit, offset int, opts ...DBOption) (int64, []model.UpgradeLog, error)
|
Page(limit, offset int, opts ...global.DBOption) (int64, []model.UpgradeLog, error)
|
||||||
Delete(opts ...DBOption) error
|
Delete(opts ...global.DBOption) error
|
||||||
|
|
||||||
WithByNodeID(nodeID uint) DBOption
|
WithByNodeID(nodeID uint) global.DBOption
|
||||||
WithByIDs(ids []uint) DBOption
|
|
||||||
WithByID(id uint) DBOption
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIUpgradeLogRepo() IUpgradeLogRepo {
|
func NewIUpgradeLogRepo() IUpgradeLogRepo {
|
||||||
return &UpgradeLogRepo{}
|
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
|
var log model.UpgradeLog
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -34,7 +32,7 @@ func (u *UpgradeLogRepo) Get(opts ...DBOption) (model.UpgradeLog, error) {
|
|||||||
return log, err
|
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
|
var logs []model.UpgradeLog
|
||||||
db := global.DB
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -56,7 +54,7 @@ func (u *UpgradeLogRepo) Save(log *model.UpgradeLog) error {
|
|||||||
return global.DB.Save(log).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
|
db := global.DB
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
db = opt(db)
|
db = opt(db)
|
||||||
@ -64,7 +62,7 @@ func (u *UpgradeLogRepo) Delete(opts ...DBOption) error {
|
|||||||
return db.Delete(&model.UpgradeLog{}).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
|
var ops []model.UpgradeLog
|
||||||
db := global.DB.Model(&model.UpgradeLog{})
|
db := global.DB.Model(&model.UpgradeLog{})
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -76,18 +74,8 @@ func (u *UpgradeLogRepo) Page(page, size int, opts ...DBOption) (int64, []model.
|
|||||||
return count, ops, err
|
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 func(g *gorm.DB) *gorm.DB {
|
||||||
return g.Where("node_id = ?", nodeID)
|
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 (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
"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/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"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) {
|
func (u *CommandService) SearchWithPage(req dto.SearchCommandWithPage) (int64, interface{}, error) {
|
||||||
options := []repo.DBOption{
|
options := []global.DBOption{
|
||||||
commonRepo.WithOrderRuleBy(req.OrderBy, req.Order),
|
commonRepo.WithOrderRuleBy(req.OrderBy, req.Order),
|
||||||
commonRepo.WithByType(req.Type),
|
commonRepo.WithByType(req.Type),
|
||||||
}
|
}
|
||||||
if len(req.Info) != 0 {
|
if len(req.Info) != 0 {
|
||||||
options = append(options, commonRepo.WithLikeName(req.Info))
|
options = append(options, commandRepo.WithByInfo(req.Info))
|
||||||
}
|
}
|
||||||
if req.GroupID != 0 {
|
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...)
|
total, commands, err := commandRepo.Page(req.Page, req.PageSize, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -3,14 +3,15 @@ package service
|
|||||||
import "github.com/1Panel-dev/1Panel/core/app/repo"
|
import "github.com/1Panel-dev/1Panel/core/app/repo"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hostRepo = repo.NewIHostRepo()
|
hostRepo = repo.NewIHostRepo()
|
||||||
commandRepo = repo.NewICommandRepo()
|
commandRepo = repo.NewICommandRepo()
|
||||||
commonRepo = repo.NewICommonRepo()
|
commonRepo = repo.NewICommonRepo()
|
||||||
settingRepo = repo.NewISettingRepo()
|
settingRepo = repo.NewISettingRepo()
|
||||||
backupRepo = repo.NewIBackupRepo()
|
backupRepo = repo.NewIBackupRepo()
|
||||||
logRepo = repo.NewILogRepo()
|
logRepo = repo.NewILogRepo()
|
||||||
groupRepo = repo.NewIGroupRepo()
|
groupRepo = repo.NewIGroupRepo()
|
||||||
launcherRepo = repo.NewILauncherRepo()
|
launcherRepo = repo.NewILauncherRepo()
|
||||||
|
upgradeLogRepo = repo.NewIUpgradeLogRepo()
|
||||||
|
|
||||||
taskRepo = repo.NewITaskRepo()
|
taskRepo = repo.NewITaskRepo()
|
||||||
)
|
)
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
"github.com/1Panel-dev/1Panel/core/app/dto"
|
||||||
"github.com/1Panel-dev/1Panel/core/app/model"
|
"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/buserr"
|
||||||
"github.com/1Panel-dev/1Panel/core/constant"
|
"github.com/1Panel-dev/1Panel/core/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
httpUtils "github.com/1Panel-dev/1Panel/core/utils/http"
|
httpUtils "github.com/1Panel-dev/1Panel/core/utils/http"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
@ -30,11 +30,13 @@ func NewIGroupService() IGroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *GroupService) List(req dto.OperateByType) ([]dto.GroupInfo, error) {
|
func (u *GroupService) List(req dto.OperateByType) ([]dto.GroupInfo, error) {
|
||||||
options := []repo.DBOption{
|
options := []global.DBOption{
|
||||||
commonRepo.WithByType(req.Type),
|
|
||||||
commonRepo.WithOrderBy("is_default desc"),
|
commonRepo.WithOrderBy("is_default desc"),
|
||||||
commonRepo.WithOrderBy("created_at desc"),
|
commonRepo.WithOrderBy("created_at desc"),
|
||||||
}
|
}
|
||||||
|
if len(req.Type) != 0 {
|
||||||
|
options = append(options, commonRepo.WithByType(req.Type))
|
||||||
|
}
|
||||||
var (
|
var (
|
||||||
groups []model.Group
|
groups []model.Group
|
||||||
err error
|
err error
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
"github.com/1Panel-dev/1Panel/core/app/dto"
|
||||||
"github.com/1Panel-dev/1Panel/core/app/model"
|
"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/constant"
|
||||||
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
|
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/ssh"
|
"github.com/1Panel-dev/1Panel/core/utils/ssh"
|
||||||
"github.com/jinzhu/copier"
|
"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) {
|
func (u *HostService) SearchWithPage(req dto.SearchHostWithPage) (int64, interface{}, error) {
|
||||||
var options []repo.DBOption
|
var options []global.DBOption
|
||||||
if len(req.Info) != 0 {
|
if len(req.Info) != 0 {
|
||||||
options = append(options, commonRepo.WithLikeName(req.Info))
|
options = append(options, hostRepo.WithByInfo(req.Info))
|
||||||
}
|
}
|
||||||
if req.GroupID != 0 {
|
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...)
|
total, hosts, err := hostRepo.Page(req.Page, req.PageSize, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,12 +74,19 @@ func (u *LogService) ListSystemLogFile() ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *LogService) PageLoginLog(req dto.SearchLgLogWithPage) (int64, interface{}, 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(
|
total, ops, err := logRepo.PageLoginLog(
|
||||||
req.Page,
|
req.Page,
|
||||||
req.PageSize,
|
req.PageSize,
|
||||||
logRepo.WithByIP(req.IP),
|
options...,
|
||||||
logRepo.WithByStatus(req.Status),
|
|
||||||
commonRepo.WithOrderBy("created_at desc"),
|
|
||||||
)
|
)
|
||||||
var dtoOps []dto.LoginLog
|
var dtoOps []dto.LoginLog
|
||||||
for _, op := range ops {
|
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) {
|
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(
|
total, ops, err := logRepo.PageOperationLog(
|
||||||
req.Page,
|
req.Page,
|
||||||
req.PageSize,
|
req.PageSize,
|
||||||
logRepo.WithByGroup(req.Source),
|
options...,
|
||||||
logRepo.WithByLikeOperation(req.Operation),
|
|
||||||
logRepo.WithByStatus(req.Status),
|
|
||||||
commonRepo.WithOrderBy("created_at desc"),
|
|
||||||
)
|
)
|
||||||
var dtoOps []dto.OperationLog
|
var dtoOps []dto.OperationLog
|
||||||
for _, op := range ops {
|
for _, op := range ops {
|
||||||
|
@ -2,7 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
"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{}
|
type TaskLogService struct{}
|
||||||
@ -16,7 +16,7 @@ func NewITaskService() ITaskLogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error) {
|
func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error) {
|
||||||
opts := []repo.DBOption{
|
opts := []global.DBOption{
|
||||||
commonRepo.WithOrderBy("created_at desc"),
|
commonRepo.WithOrderBy("created_at desc"),
|
||||||
}
|
}
|
||||||
if req.Status != "" {
|
if req.Status != "" {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
"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/constant"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
||||||
@ -23,6 +24,7 @@ type UpgradeService struct{}
|
|||||||
|
|
||||||
type IUpgradeService interface {
|
type IUpgradeService interface {
|
||||||
Upgrade(req dto.Upgrade) error
|
Upgrade(req dto.Upgrade) error
|
||||||
|
Rollback(req dto.OperateByID) error
|
||||||
LoadNotes(req dto.Upgrade) (string, error)
|
LoadNotes(req dto.Upgrade) (string, error)
|
||||||
SearchUpgrade() (*dto.UpgradeInfo, error)
|
SearchUpgrade() (*dto.UpgradeInfo, error)
|
||||||
}
|
}
|
||||||
@ -127,6 +129,9 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
|||||||
_ = settingRepo.Update("SystemStatus", "Free")
|
_ = settingRepo.Update("SystemStatus", "Free")
|
||||||
return
|
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!")
|
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 {
|
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
|
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 {
|
func (u *UpgradeService) handleBackup(originalDir string) error {
|
||||||
if err := files.CopyItem(false, true, "/usr/local/bin/1panel*", originalDir); err != nil {
|
if err := files.CopyItem(false, true, "/usr/local/bin/1panel*", originalDir); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -26,3 +26,5 @@ var (
|
|||||||
|
|
||||||
BackupAccountTokenEntryID cron.EntryID
|
BackupAccountTokenEntryID cron.EntryID
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DBOption func(*gorm.DB) *gorm.DB
|
||||||
|
@ -168,7 +168,7 @@ var InitHost = &gormigrate.Migration{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
host := model.Host{
|
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 {
|
if err := tx.Create(&host).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -32,69 +32,26 @@
|
|||||||
<span>({{ $t('setting.upgradeCheck') }})</span>
|
<span>({{ $t('setting.upgradeCheck') }})</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-tag v-if="version === 'Waiting'" round style="margin-left: 10px">{{ $t('setting.upgrading') }}</el-tag>
|
<el-tag v-if="version === 'Waiting'" round style="margin-left: 10px">{{ $t('setting.upgrading') }}</el-tag>
|
||||||
|
|
||||||
|
<Upgrade ref="upgradeRef" @search="search" />
|
||||||
</div>
|
</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>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import DrawerHeader from '@/components/drawer-header/index.vue';
|
import { getSettingInfo, loadUpgradeInfo } from '@/api/modules/setting';
|
||||||
import { getSettingInfo, loadReleaseNotes, loadUpgradeInfo, upgrade } from '@/api/modules/setting';
|
import Upgrade from '@/components/system-upgrade/upgrade/index.vue';
|
||||||
import MdEditor from 'md-editor-v3';
|
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import 'md-editor-v3/lib/style.css';
|
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { GlobalStore } from '@/store';
|
import { GlobalStore } from '@/store';
|
||||||
import { ElMessageBox } from 'element-plus';
|
|
||||||
import { storeToRefs } from 'pinia';
|
|
||||||
|
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
const { isDarkTheme } = storeToRefs(globalStore);
|
const upgradeRef = ref();
|
||||||
|
|
||||||
const version = ref<string>('');
|
const version = ref<string>('');
|
||||||
const isProductPro = ref();
|
const isProductPro = ref();
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const drawerVisible = ref(false);
|
|
||||||
const upgradeInfo = ref();
|
const upgradeInfo = ref();
|
||||||
const refresh = ref();
|
|
||||||
const upgradeVersion = ref();
|
const upgradeVersion = ref();
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
footer: {
|
footer: {
|
||||||
@ -108,10 +65,6 @@ const search = async () => {
|
|||||||
version.value = res.data.systemVersion;
|
version.value = res.data.systemVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
drawerVisible.value = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toHalo = () => {
|
const toHalo = () => {
|
||||||
window.open('https://www.lxware.cn/1panel' + '', '_blank', 'noopener,noreferrer');
|
window.open('https://www.lxware.cn/1panel' + '', '_blank', 'noopener,noreferrer');
|
||||||
};
|
};
|
||||||
@ -135,7 +88,6 @@ const onLoadUpgradeInfo = async () => {
|
|||||||
loading.value = false;
|
loading.value = false;
|
||||||
if (res.data.testVersion || res.data.newVersion || res.data.latestVersion) {
|
if (res.data.testVersion || res.data.newVersion || res.data.latestVersion) {
|
||||||
upgradeInfo.value = res.data;
|
upgradeInfo.value = res.data;
|
||||||
drawerVisible.value = true;
|
|
||||||
if (upgradeInfo.value.newVersion) {
|
if (upgradeInfo.value.newVersion) {
|
||||||
upgradeVersion.value = upgradeInfo.value.newVersion;
|
upgradeVersion.value = upgradeInfo.value.newVersion;
|
||||||
return;
|
return;
|
||||||
@ -148,6 +100,7 @@ const onLoadUpgradeInfo = async () => {
|
|||||||
upgradeVersion.value = upgradeInfo.value.testVersion;
|
upgradeVersion.value = upgradeInfo.value.testVersion;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
upgradeRef.value.acceptParams({ upgradeInfo: upgradeInfo.value, upgradeVersion: upgradeVersion.value });
|
||||||
} else {
|
} else {
|
||||||
MsgSuccess(i18n.global.t('setting.noUpgrade'));
|
MsgSuccess(i18n.global.t('setting.noUpgrade'));
|
||||||
return;
|
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(() => {
|
onMounted(() => {
|
||||||
isProductPro.value = globalStore.isProductPro;
|
isProductPro.value = globalStore.isProductPro;
|
||||||
search();
|
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',
|
fanSpeed: 'Fan Speed',
|
||||||
},
|
},
|
||||||
terminal: {
|
terminal: {
|
||||||
|
local: 'Local',
|
||||||
|
localHelper: 'The `local` name is used only for system local identification',
|
||||||
conn: 'connection',
|
conn: 'connection',
|
||||||
connLocalErr: 'Unable to automatically authenticate, please fill in the local server login information!',
|
connLocalErr: 'Unable to automatically authenticate, please fill in the local server login information!',
|
||||||
testConn: 'Test connection',
|
testConn: 'Test connection',
|
||||||
|
@ -940,6 +940,8 @@ const message = {
|
|||||||
fanSpeed: '風扇轉速',
|
fanSpeed: '風扇轉速',
|
||||||
},
|
},
|
||||||
terminal: {
|
terminal: {
|
||||||
|
local: '本機',
|
||||||
|
localHelper: 'local 名稱僅用於系統本機標識',
|
||||||
conn: '連接',
|
conn: '連接',
|
||||||
connLocalErr: '無法自動認證,請填寫本地服務器的登錄信息!',
|
connLocalErr: '無法自動認證,請填寫本地服務器的登錄信息!',
|
||||||
testConn: '連接測試',
|
testConn: '連接測試',
|
||||||
|
@ -941,6 +941,8 @@ const message = {
|
|||||||
fanSpeed: '风扇转速',
|
fanSpeed: '风扇转速',
|
||||||
},
|
},
|
||||||
terminal: {
|
terminal: {
|
||||||
|
local: '本机',
|
||||||
|
localHelper: 'local 名称仅用于系统本机标识',
|
||||||
conn: '连接',
|
conn: '连接',
|
||||||
connLocalErr: '无法自动认证,请填写本地服务器的登录信息!',
|
connLocalErr: '无法自动认证,请填写本地服务器的登录信息!',
|
||||||
testConn: '连接测试',
|
testConn: '连接测试',
|
||||||
@ -1499,7 +1501,7 @@ const message = {
|
|||||||
rollbackHelper:
|
rollbackHelper:
|
||||||
'即将回滚本次恢复,回滚将替换所有本次恢复的文件,过程中可能需要重启 Docker 以及 1Panel 服务,是否继续?',
|
'即将回滚本次恢复,回滚将替换所有本次恢复的文件,过程中可能需要重启 Docker 以及 1Panel 服务,是否继续?',
|
||||||
|
|
||||||
upgradeRecord: '升级记录',
|
upgradeRecord: '更新记录',
|
||||||
upgrading: '正在升级中,请稍候...',
|
upgrading: '正在升级中,请稍候...',
|
||||||
upgradeHelper: '升级操作需要重启 1Panel 服务,是否继续?',
|
upgradeHelper: '升级操作需要重启 1Panel 服务,是否继续?',
|
||||||
noUpgrade: '当前已经是最新版本',
|
noUpgrade: '当前已经是最新版本',
|
||||||
|
@ -2,10 +2,7 @@
|
|||||||
<DrawerPro v-model="drawerVisible" :header="$t('terminal.host')" :back="handleClose" size="large">
|
<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 ref="hostInfoRef" label-position="top" :model="dialogData.rowData" :rules="rules" v-loading="loading">
|
||||||
<el-form-item :label="$t('terminal.ip')" prop="addr">
|
<el-form-item :label="$t('terminal.ip')" prop="addr">
|
||||||
<el-tag v-if="dialogData.rowData!.addr === '127.0.0.1' && dialogData.title === 'edit'">
|
<el-input @change="isOK = false" clearable v-model.trim="dialogData.rowData!.addr" />
|
||||||
{{ dialogData.rowData!.addr }}
|
|
||||||
</el-tag>
|
|
||||||
<el-input @change="isOK = false" v-else clearable v-model.trim="dialogData.rowData!.addr" />
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.login.username')" prop="user">
|
<el-form-item :label="$t('commons.login.username')" prop="user">
|
||||||
<el-input @change="isOK = false" clearable v-model="dialogData.rowData!.user" />
|
<el-input @change="isOK = false" clearable v-model="dialogData.rowData!.user" />
|
||||||
@ -53,11 +50,18 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.table.group')" prop="groupID">
|
<el-form-item :label="$t('commons.table.group')" prop="groupID">
|
||||||
<el-select filterable v-model="dialogData.rowData!.groupID" clearable style="width: 100%">
|
<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-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.table.title')" prop="name">
|
<el-form-item :label="$t('commons.table.name')" prop="name">
|
||||||
<el-input clearable v-model="dialogData.rowData!.name" />
|
<el-input :disabled="itemName === 'local'" clearable v-model="dialogData.rowData!.name" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.table.description')" prop="description">
|
<el-form-item :label="$t('commons.table.description')" prop="description">
|
||||||
<el-input clearable type="textarea" v-model="dialogData.rowData!.description" />
|
<el-input clearable type="textarea" v-model="dialogData.rowData!.description" />
|
||||||
@ -98,6 +102,7 @@ const drawerVisible = ref(false);
|
|||||||
const dialogData = ref<DialogProps>({
|
const dialogData = ref<DialogProps>({
|
||||||
title: '',
|
title: '',
|
||||||
});
|
});
|
||||||
|
const itemName = ref();
|
||||||
|
|
||||||
const groupList = ref();
|
const groupList = ref();
|
||||||
const acceptParams = (params: DialogProps): void => {
|
const acceptParams = (params: DialogProps): void => {
|
||||||
@ -119,7 +124,14 @@ const rules = reactive({
|
|||||||
port: [Rules.requiredInput, Rules.port],
|
port: [Rules.requiredInput, Rules.port],
|
||||||
user: [Rules.requiredInput],
|
user: [Rules.requiredInput],
|
||||||
authMode: [Rules.requiredSelect],
|
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 loadGroups = async () => {
|
||||||
const res = await GetGroupList('host');
|
const res = await GetGroupList('host');
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
type="warning"
|
type="warning"
|
||||||
/>
|
/>
|
||||||
<el-form-item :label="$t('terminal.ip')" prop="addr">
|
<el-form-item :label="$t('terminal.ip')" prop="addr">
|
||||||
<el-input @change="isOK = false" v-if="!isLocal" clearable v-model.trim="hostInfo.addr" />
|
<el-input @change="isOK = false" clearable v-model.trim="hostInfo.addr" />
|
||||||
<el-tag v-if="isLocal">{{ hostInfo.addr }}</el-tag>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.login.username')" prop="user">
|
<el-form-item :label="$t('commons.login.username')" prop="user">
|
||||||
<el-input @change="isOK = false" clearable v-model="hostInfo.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-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-input @change="isOK = false" clearable v-model.number="hostInfo.port" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.table.title')" prop="name">
|
<el-form-item :label="$t('commons.table.group')" prop="groupID">
|
||||||
<el-input clearable v-model="hostInfo.name" />
|
<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>
|
||||||
<el-form-item :label="$t('commons.table.description')" prop="description">
|
<el-form-item :label="$t('commons.table.description')" prop="description">
|
||||||
<el-input clearable v-model="hostInfo.description" />
|
<el-input clearable v-model="hostInfo.description" />
|
||||||
@ -72,12 +80,15 @@ import { addHost, testByInfo } from '@/api/modules/terminal';
|
|||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import { MsgError, MsgSuccess } from '@/utils/message';
|
import { MsgError, MsgSuccess } from '@/utils/message';
|
||||||
|
import { GetGroupList } from '@/api/modules/group';
|
||||||
|
|
||||||
const dialogVisible = ref();
|
const dialogVisible = ref();
|
||||||
const isOK = ref(false);
|
const isOK = ref(false);
|
||||||
type FormInstance = InstanceType<typeof ElForm>;
|
type FormInstance = InstanceType<typeof ElForm>;
|
||||||
const hostRef = ref<FormInstance>();
|
const hostRef = ref<FormInstance>();
|
||||||
|
|
||||||
|
const groupList = ref();
|
||||||
|
|
||||||
let hostInfo = reactive<Host.HostOperate>({
|
let hostInfo = reactive<Host.HostOperate>({
|
||||||
id: 0,
|
id: 0,
|
||||||
name: '',
|
name: '',
|
||||||
@ -122,6 +133,7 @@ const acceptParams = (props: DialogProps) => {
|
|||||||
hostInfo.addr = '127.0.0.1';
|
hostInfo.addr = '127.0.0.1';
|
||||||
hostInfo.user = 'root';
|
hostInfo.user = 'root';
|
||||||
}
|
}
|
||||||
|
loadGroups();
|
||||||
dialogVisible.value = true;
|
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({
|
defineExpose({
|
||||||
acceptParams,
|
acceptParams,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user