From a44c4d96d8044b270631fa5d8d2f6e81ba8ff1f8 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 21 Aug 2024 18:04:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20repo=20=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95=20(#6200)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/app/api/v2/helper/helper.go | 2 - agent/app/repo/app.go | 4 +- agent/app/repo/backup.go | 10 -- agent/app/repo/common.go | 131 +++++++++---------- agent/app/repo/database.go | 7 - agent/app/repo/database_mysql.go | 10 -- agent/app/repo/database_postgresql.go | 10 -- agent/app/repo/runtime.go | 7 - agent/app/repo/task.go | 15 +-- agent/app/repo/website.go | 14 -- agent/app/service/app.go | 4 +- agent/app/service/app_install.go | 2 +- agent/app/service/app_utils.go | 9 +- agent/app/service/backup.go | 10 +- agent/app/service/backup_app.go | 2 +- agent/app/service/clam.go | 2 +- agent/app/service/compose_template.go | 4 +- agent/app/service/container.go | 2 +- agent/app/service/cronjob.go | 2 +- agent/app/service/cronjob_helper.go | 2 +- agent/app/service/database.go | 4 +- agent/app/service/database_mysql.go | 6 +- agent/app/service/database_postgresql.go | 6 +- agent/app/service/file.go | 5 +- agent/app/service/image_repo.go | 4 +- agent/app/service/runtime.go | 4 +- agent/app/service/snapshot.go | 4 +- agent/app/service/task.go | 4 +- agent/app/service/website.go | 15 ++- agent/constant/errs.go | 6 - agent/i18n/lang/en.yaml | 5 - agent/i18n/lang/zh-Hant.yaml | 5 - agent/i18n/lang/zh.yaml | 7 +- core/app/repo/command.go | 26 +--- core/app/repo/common.go | 15 ++- core/app/repo/host.go | 9 +- core/app/repo/logs.go | 7 +- core/app/repo/setting.go | 4 +- core/app/service/command.go | 6 +- core/app/service/host.go | 2 +- core/app/service/setting.go | 2 +- frontend/src/components/group/index.vue | 29 ---- frontend/src/views/cronjob/operate/index.vue | 3 +- 43 files changed, 141 insertions(+), 286 deletions(-) diff --git a/agent/app/api/v2/helper/helper.go b/agent/app/api/v2/helper/helper.go index b798bcce2..043b74ba0 100644 --- a/agent/app/api/v2/helper/helper.go +++ b/agent/app/api/v2/helper/helper.go @@ -32,8 +32,6 @@ func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) { res.Message = i18n.GetMsgWithMap("ErrInvalidParams", nil) case errors.Is(constant.ErrStructTransform, err): res.Message = i18n.GetMsgWithMap("ErrStructTransform", map[string]interface{}{"detail": err}) - case errors.Is(constant.ErrInitialPassword, err): - res.Message = i18n.GetMsgWithMap("ErrInitialPassword", map[string]interface{}{"detail": err}) case errors.As(err, &buserr.BusinessError{}): res.Message = err.Error() default: diff --git a/agent/app/repo/app.go b/agent/app/repo/app.go index 8ab5729f2..6c232d7fe 100644 --- a/agent/app/repo/app.go +++ b/agent/app/repo/app.go @@ -17,7 +17,7 @@ type IAppRepo interface { OrderByRecommend() DBOption GetRecommend() DBOption WithResource(resource string) DBOption - WithLikeName(name string) DBOption + WithByLikeName(name string) DBOption Page(page, size int, opts ...DBOption) (int64, []model.App, error) GetFirst(opts ...DBOption) (model.App, error) GetBy(opts ...DBOption) ([]model.App, error) @@ -32,7 +32,7 @@ func NewIAppRepo() IAppRepo { return &AppRepo{} } -func (a AppRepo) WithLikeName(name string) DBOption { +func (a AppRepo) WithByLikeName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(name) == 0 { return g diff --git a/agent/app/repo/backup.go b/agent/app/repo/backup.go index 06b30f14c..32af7dd5e 100644 --- a/agent/app/repo/backup.go +++ b/agent/app/repo/backup.go @@ -16,7 +16,6 @@ type IBackupRepo interface { CreateRecord(record *model.BackupRecord) error DeleteRecord(ctx context.Context, opts ...DBOption) error UpdateRecord(record *model.BackupRecord) error - WithByDetailName(detailName string) DBOption WithByFileName(fileName string) DBOption WithByCronID(cronjobID uint) DBOption } @@ -47,15 +46,6 @@ func (u *BackupRepo) PageRecord(page, size int, opts ...DBOption) (int64, []mode return count, users, err } -func (u *BackupRepo) WithByDetailName(detailName string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(detailName) == 0 { - return g - } - return g.Where("detail_name = ?", detailName) - } -} - func (u *BackupRepo) WithByFileName(fileName string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(fileName) == 0 { diff --git a/agent/app/repo/common.go b/agent/app/repo/common.go index 9ae569049..6d13f0bc9 100644 --- a/agent/app/repo/common.go +++ b/agent/app/repo/common.go @@ -14,19 +14,22 @@ type DBOption func(*gorm.DB) *gorm.DB type ICommonRepo interface { WithByID(id uint) DBOption + WithByIDs(ids []uint) DBOption WithByName(name string) DBOption + WithByNames(names []string) DBOption + WithByLikeName(name string) DBOption + WithByDetailName(detailName string) DBOption + + WithByFrom(from string) DBOption WithByType(tp string) DBOption + WithTypes(types []string) DBOption + WithByStatus(status string) DBOption + WithOrderBy(orderStr string) DBOption WithOrderRuleBy(orderBy, order string) DBOption - WithByGroupID(groupID uint) DBOption - WithLikeName(name string) DBOption - WithIdsIn(ids []uint) DBOption - WithNamesIn(names []string) DBOption + WithByDate(startTime, endTime time.Time) DBOption WithByCreatedAt(startTime, endTime time.Time) DBOption - WithByStartDate(startTime time.Time) DBOption - WithByStatus(status string) DBOption - WithByFrom(from string) DBOption } type CommonRepo struct{} @@ -40,12 +43,62 @@ func (c *CommonRepo) WithByID(id uint) DBOption { return g.Where("id = ?", id) } } +func (c *CommonRepo) WithByIDs(ids []uint) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("id in (?)", ids) + } +} func (c *CommonRepo) WithByName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("name = ?", name) } } +func (c *CommonRepo) WithByNames(names []string) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("name in (?)", names) + } +} +func (c *CommonRepo) WithByLikeName(name string) DBOption { + return func(g *gorm.DB) *gorm.DB { + if len(name) == 0 { + return g + } + return g.Where("name like ?", "%"+name+"%") + } +} +func (c *CommonRepo) WithByDetailName(detailName string) DBOption { + return func(g *gorm.DB) *gorm.DB { + if len(detailName) == 0 { + return g + } + return g.Where("detail_name = ?", detailName) + } +} + +func (c *CommonRepo) WithByType(tp string) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("type = ?", tp) + } +} +func (c *CommonRepo) WithTypes(types []string) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("type in (?)", types) + } +} +func (c *CommonRepo) WithByStatus(status string) DBOption { + return func(g *gorm.DB) *gorm.DB { + if len(status) == 0 { + return g + } + return g.Where("status = ?", status) + } +} +func (c *CommonRepo) WithByFrom(from string) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("`from` = ?", from) + } +} func (c *CommonRepo) WithByDate(startTime, endTime time.Time) DBOption { return func(g *gorm.DB) *gorm.DB { @@ -59,57 +112,11 @@ func (c *CommonRepo) WithByCreatedAt(startTime, endTime time.Time) DBOption { } } -func (c *CommonRepo) WithByStartDate(startTime time.Time) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("start_time < ?", startTime) - } -} - -func (c *CommonRepo) WithByType(tp string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("type = ?", tp) - } -} - -func (c *CommonRepo) WithByGroupID(groupID uint) DBOption { - return func(g *gorm.DB) *gorm.DB { - if groupID == 0 { - return g - } - return g.Where("group_id = ?", groupID) - } -} - -func (c *CommonRepo) WithByStatus(status string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(status) == 0 { - return g - } - return g.Where("status = ?", status) - } -} - -func (c *CommonRepo) WithByFrom(from string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("`from` = ?", from) - } -} - -func (c *CommonRepo) WithLikeName(name string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(name) == 0 { - return g - } - return g.Where("name like ?", "%"+name+"%") - } -} - func (c *CommonRepo) WithOrderBy(orderStr string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Order(orderStr) } } - func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption { switch order { case constant.OrderDesc: @@ -125,24 +132,6 @@ func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption { } } -func (c *CommonRepo) WithNamesIn(names []string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("name in (?)", names) - } -} - -func (c *CommonRepo) WithIdsIn(ids []uint) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("id in (?)", ids) - } -} - -func (c *CommonRepo) WithIdsNotIn(ids []uint) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("id not in (?)", ids) - } -} - func getTx(ctx context.Context, opts ...DBOption) *gorm.DB { tx, ok := ctx.Value(constant.DB).(*gorm.DB) if ok { diff --git a/agent/app/repo/database.go b/agent/app/repo/database.go index 7905c9c4c..47aa09729 100644 --- a/agent/app/repo/database.go +++ b/agent/app/repo/database.go @@ -20,7 +20,6 @@ type IDatabaseRepo interface { Update(id uint, vars map[string]interface{}) error Delete(ctx context.Context, opts ...DBOption) error Get(opts ...DBOption) (model.Database, error) - WithByFrom(from string) DBOption WithoutByFrom(from string) DBOption WithAppInstallID(appInstallID uint) DBOption WithTypeList(dbType string) DBOption @@ -87,12 +86,6 @@ func (d *DatabaseRepo) GetList(opts ...DBOption) ([]model.Database, error) { return databases, nil } -func (d *DatabaseRepo) WithByFrom(from string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("`from` = ?", from) - } -} - func (d *DatabaseRepo) WithoutByFrom(from string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("`from` != ?", from) diff --git a/agent/app/repo/database_mysql.go b/agent/app/repo/database_mysql.go index 4d741bccd..60c6a4dd7 100644 --- a/agent/app/repo/database_mysql.go +++ b/agent/app/repo/database_mysql.go @@ -15,7 +15,6 @@ type MysqlRepo struct{} type IMysqlRepo interface { Get(opts ...DBOption) (model.DatabaseMysql, error) WithByMysqlName(mysqlName string) DBOption - WithByFrom(from string) DBOption List(opts ...DBOption) ([]model.DatabaseMysql, error) Page(limit, offset int, opts ...DBOption) (int64, []model.DatabaseMysql, error) Create(ctx context.Context, mysql *model.DatabaseMysql) error @@ -112,12 +111,3 @@ func (u *MysqlRepo) WithByMysqlName(mysqlName string) DBOption { return g.Where("mysql_name = ?", mysqlName) } } - -func (u *MysqlRepo) WithByFrom(from string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(from) != 0 { - return g.Where("`from` = ?", from) - } - return g - } -} diff --git a/agent/app/repo/database_postgresql.go b/agent/app/repo/database_postgresql.go index e1f3b1896..4affa1f22 100644 --- a/agent/app/repo/database_postgresql.go +++ b/agent/app/repo/database_postgresql.go @@ -15,7 +15,6 @@ type PostgresqlRepo struct{} type IPostgresqlRepo interface { Get(opts ...DBOption) (model.DatabasePostgresql, error) WithByPostgresqlName(postgresqlName string) DBOption - WithByFrom(from string) DBOption List(opts ...DBOption) ([]model.DatabasePostgresql, error) Page(limit, offset int, opts ...DBOption) (int64, []model.DatabasePostgresql, error) Create(ctx context.Context, postgresql *model.DatabasePostgresql) error @@ -112,12 +111,3 @@ func (u *PostgresqlRepo) WithByPostgresqlName(postgresqlName string) DBOption { return g.Where("postgresql_name = ?", postgresqlName) } } - -func (u *PostgresqlRepo) WithByFrom(from string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(from) != 0 { - return g.Where("`from` = ?", from) - } - return g - } -} diff --git a/agent/app/repo/runtime.go b/agent/app/repo/runtime.go index b148d4585..01b700176 100644 --- a/agent/app/repo/runtime.go +++ b/agent/app/repo/runtime.go @@ -12,7 +12,6 @@ type RuntimeRepo struct { } type IRuntimeRepo interface { - WithName(name string) DBOption WithImage(image string) DBOption WithNotId(id uint) DBOption WithStatus(status string) DBOption @@ -30,12 +29,6 @@ func NewIRunTimeRepo() IRuntimeRepo { return &RuntimeRepo{} } -func (r *RuntimeRepo) WithName(name string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("name = ?", name) - } -} - func (r *RuntimeRepo) WithStatus(status string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("status = ?", status) diff --git a/agent/app/repo/task.go b/agent/app/repo/task.go index f88ac4a0c..07f38004e 100644 --- a/agent/app/repo/task.go +++ b/agent/app/repo/task.go @@ -2,6 +2,7 @@ package repo import ( "context" + "github.com/1Panel-dev/1Panel/agent/app/model" "gorm.io/gorm" ) @@ -16,9 +17,7 @@ type ITaskRepo interface { Update(ctx context.Context, task *model.Task) error WithByID(id string) DBOption - WithType(taskType string) DBOption WithResourceID(id uint) DBOption - WithStatus(status string) DBOption WithOperate(taskOperate string) DBOption } @@ -32,24 +31,12 @@ func (t TaskRepo) WithByID(id string) DBOption { } } -func (t TaskRepo) WithType(taskType string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("type = ?", taskType) - } -} - func (t TaskRepo) WithOperate(taskOperate string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("operate = ?", taskOperate) } } -func (t TaskRepo) WithStatus(status string) DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("status = ?", status) - } -} - func (t TaskRepo) WithResourceID(id uint) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("resource_id = ?", id) diff --git a/agent/app/repo/website.go b/agent/app/repo/website.go index 98c4417ae..182945ea1 100644 --- a/agent/app/repo/website.go +++ b/agent/app/repo/website.go @@ -18,8 +18,6 @@ type IWebsiteRepo interface { WithDefaultServer() DBOption WithDomainLike(domain string) DBOption WithRuntimeID(runtimeID uint) DBOption - WithIDs(ids []uint) DBOption - WithTypes(types []string) DBOption WithParentID(websiteID uint) DBOption Page(page, size int, opts ...DBOption) (int64, []model.Website, error) @@ -48,18 +46,6 @@ func (w *WebsiteRepo) WithAppInstallId(appInstallID uint) DBOption { } } -func (w *WebsiteRepo) WithIDs(ids []uint) DBOption { - return func(db *gorm.DB) *gorm.DB { - return db.Where("id in (?)", ids) - } -} - -func (w *WebsiteRepo) WithTypes(types []string) DBOption { - return func(db *gorm.DB) *gorm.DB { - return db.Where("type in (?)", types) - } -} - func (w *WebsiteRepo) WithRuntimeID(runtimeID uint) DBOption { return func(db *gorm.DB) *gorm.DB { return db.Where("runtime_id = ?", runtimeID) diff --git a/agent/app/service/app.go b/agent/app/service/app.go index 622d6b7c2..bf80370cb 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -55,7 +55,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) { var opts []repo.DBOption opts = append(opts, appRepo.OrderByRecommend()) if req.Name != "" { - opts = append(opts, appRepo.WithLikeName(req.Name)) + opts = append(opts, appRepo.WithByLikeName(req.Name)) } if req.Type != "" { opts = append(opts, appRepo.WithType(req.Type)) @@ -83,7 +83,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) { for _, t := range appTags { appIds = append(appIds, t.AppId) } - opts = append(opts, commonRepo.WithIdsIn(appIds)) + opts = append(opts, commonRepo.WithByIDs(appIds)) } var res response.AppRes total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...) diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index b334ab885..eb28a5263 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -87,7 +87,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo ) if req.Name != "" { - opts = append(opts, commonRepo.WithLikeName(req.Name)) + opts = append(opts, commonRepo.WithByLikeName(req.Name)) } if len(req.Tags) != 0 { diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index 57046843b..73bf62f1d 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -33,7 +33,6 @@ import ( "github.com/subosito/gotenv" "gopkg.in/yaml.v3" - "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/utils/env" "github.com/1Panel-dev/1Panel/agent/app/dto/response" @@ -256,8 +255,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI if dbConfig.DbName != "" && dbConfig.DbUser != "" && dbConfig.Password != "" { switch database.Type { case constant.AppPostgresql, constant.AppPostgres: - iPostgresqlRepo := repo.NewIPostgresqlRepo() - oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal)) + oldPostgresqlDb, _ := postgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) resourceId = oldPostgresqlDb.ID if oldPostgresqlDb.ID > 0 { if oldPostgresqlDb.Username != dbConfig.DbUser || oldPostgresqlDb.Password != dbConfig.Password { @@ -279,8 +277,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI resourceId = pgdb.ID } case constant.AppMysql, constant.AppMariaDB: - iMysqlRepo := repo.NewIMysqlRepo() - oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal)) + oldMysqlDb, _ := mysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) resourceId = oldMysqlDb.ID if oldMysqlDb.ID > 0 { if oldMysqlDb.Username != dbConfig.DbUser || oldMysqlDb.Password != dbConfig.Password { @@ -432,7 +429,7 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error { _ = postgresqlRepo.Delete(ctx, postgresqlRepo.WithByPostgresqlName(install.Name)) } - _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), backupRepo.WithByDetailName(install.Name)) + _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), commonRepo.WithByDetailName(install.Name)) uploadDir := path.Join(global.CONF.System.BaseDir, fmt.Sprintf("1panel/uploads/app/%s/%s", install.App.Key, install.Name)) if _, err := os.Stat(uploadDir); err == nil { _ = os.RemoveAll(uploadDir) diff --git a/agent/app/service/backup.go b/agent/app/service/backup.go index 8335af6cc..7c4a2f703 100644 --- a/agent/app/service/backup.go +++ b/agent/app/service/backup.go @@ -66,7 +66,7 @@ func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, [ commonRepo.WithOrderBy("created_at desc"), commonRepo.WithByName(search.Name), commonRepo.WithByType(search.Type), - backupRepo.WithByDetailName(search.DetailName), + commonRepo.WithByDetailName(search.DetailName), ) if err != nil { return 0, nil, err @@ -153,10 +153,10 @@ func (u *BackupService) DownloadRecord(info dto.DownloadRecord) (string, error) func (u *BackupService) DeleteRecordByName(backupType, name, detailName string, withDeleteFile bool) error { if !withDeleteFile { - return backupRepo.DeleteRecord(context.Background(), commonRepo.WithByType(backupType), commonRepo.WithByName(name), backupRepo.WithByDetailName(detailName)) + return backupRepo.DeleteRecord(context.Background(), commonRepo.WithByType(backupType), commonRepo.WithByName(name), commonRepo.WithByDetailName(detailName)) } - records, err := backupRepo.ListRecord(commonRepo.WithByType(backupType), commonRepo.WithByName(name), backupRepo.WithByDetailName(detailName)) + records, err := backupRepo.ListRecord(commonRepo.WithByType(backupType), commonRepo.WithByName(name), commonRepo.WithByDetailName(detailName)) if err != nil { return err } @@ -176,7 +176,7 @@ func (u *BackupService) DeleteRecordByName(backupType, name, detailName string, } func (u *BackupService) BatchDeleteRecord(ids []uint) error { - records, err := backupRepo.ListRecord(commonRepo.WithIdsIn(ids)) + records, err := backupRepo.ListRecord(commonRepo.WithByIDs(ids)) if err != nil { return err } @@ -190,7 +190,7 @@ func (u *BackupService) BatchDeleteRecord(ids []uint) error { global.LOG.Errorf("remove file %s failed, err: %v", path.Join(record.FileDir, record.FileName), err) } } - return backupRepo.DeleteRecord(context.Background(), commonRepo.WithIdsIn(ids)) + return backupRepo.DeleteRecord(context.Background(), commonRepo.WithByIDs(ids)) } func (u *BackupService) ListFiles(req dto.OperateByID) []string { diff --git a/agent/app/service/backup_app.go b/agent/app/service/backup_app.go index 74836e0c8..660a47773 100644 --- a/agent/app/service/backup_app.go +++ b/agent/app/service/backup_app.go @@ -193,7 +193,7 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback if err != nil { return err } - database, err = databaseRepo.Get(databaseRepo.WithAppInstallID(resourceApp.ID), commonRepo.WithByType(resource.Key), databaseRepo.WithByFrom(constant.AppResourceLocal), commonRepo.WithByName(resourceApp.Name)) + database, err = databaseRepo.Get(databaseRepo.WithAppInstallID(resourceApp.ID), commonRepo.WithByType(resource.Key), commonRepo.WithByFrom(constant.AppResourceLocal), commonRepo.WithByName(resourceApp.Name)) if err != nil { return err } diff --git a/agent/app/service/clam.go b/agent/app/service/clam.go index 41dcf84c8..8bdead646 100644 --- a/agent/app/service/clam.go +++ b/agent/app/service/clam.go @@ -126,7 +126,7 @@ func (c *ClamService) Operate(operate string) error { } func (c *ClamService) SearchWithPage(req dto.SearchClamWithPage) (int64, interface{}, error) { - total, commands, err := clamRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) + total, commands, err := clamRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) if err != nil { return 0, nil, err } diff --git a/agent/app/service/compose_template.go b/agent/app/service/compose_template.go index dd4f91eca..2cbf4e69a 100644 --- a/agent/app/service/compose_template.go +++ b/agent/app/service/compose_template.go @@ -38,7 +38,7 @@ func (u *ComposeTemplateService) List() ([]dto.ComposeTemplateInfo, error) { } func (u *ComposeTemplateService) SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) { - total, composes, err := composeRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info)) + total, composes, err := composeRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info)) var dtoComposeTemplates []dto.ComposeTemplateInfo for _, compose := range composes { var item dto.ComposeTemplateInfo @@ -72,7 +72,7 @@ func (u *ComposeTemplateService) Delete(ids []uint) error { } return composeRepo.Delete(commonRepo.WithByID(ids[0])) } - return composeRepo.Delete(commonRepo.WithIdsIn(ids)) + return composeRepo.Delete(commonRepo.WithByIDs(ids)) } func (u *ComposeTemplateService) Update(id uint, upMap map[string]interface{}) error { diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 4f6004da4..9d7fefc9e 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -281,7 +281,7 @@ func (u *ContainerService) Inspect(req dto.InspectReq) (string, error) { case "image": inspectInfo, _, err = client.ImageInspectWithRaw(context.Background(), req.ID) case "network": - inspectInfo, err = client.NetworkInspect(context.TODO(), req.ID, types.NetworkInspectOptions{}) + inspectInfo, err = client.NetworkInspect(context.TODO(), req.ID, network.InspectOptions{}) case "volume": inspectInfo, err = client.VolumeInspect(context.TODO(), req.ID) } diff --git a/agent/app/service/cronjob.go b/agent/app/service/cronjob.go index 721365f9a..e893d4481 100644 --- a/agent/app/service/cronjob.go +++ b/agent/app/service/cronjob.go @@ -40,7 +40,7 @@ func NewICronjobService() ICronjobService { } func (u *CronjobService) SearchWithPage(search dto.PageCronjob) (int64, interface{}, error) { - total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, commonRepo.WithLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order)) + total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, commonRepo.WithByLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order)) var dtoCronjobs []dto.CronjobInfo for _, cronjob := range cronjobs { var item dto.CronjobInfo diff --git a/agent/app/service/cronjob_helper.go b/agent/app/service/cronjob_helper.go index c2eb514b5..01cf1f0e3 100644 --- a/agent/app/service/cronjob_helper.go +++ b/agent/app/service/cronjob_helper.go @@ -295,7 +295,7 @@ func (u *CronjobService) removeExpiredBackup(cronjob model.Cronjob, accountMap m if record.ID != 0 { opts = append(opts, commonRepo.WithByType(record.Type)) opts = append(opts, commonRepo.WithByName(record.Name)) - opts = append(opts, backupRepo.WithByDetailName(record.DetailName)) + opts = append(opts, commonRepo.WithByDetailName(record.DetailName)) } records, _ := backupRepo.ListRecord(opts...) if len(records) <= int(cronjob.RetainCopies) { diff --git a/agent/app/service/database.go b/agent/app/service/database.go index dbc65baab..7d380e542 100644 --- a/agent/app/service/database.go +++ b/agent/app/service/database.go @@ -42,7 +42,7 @@ func NewIDatabaseService() IDatabaseService { func (u *DatabaseService) SearchWithPage(search dto.DatabaseSearch) (int64, interface{}, error) { total, dbs, err := databaseRepo.Page(search.Page, search.PageSize, databaseRepo.WithTypeList(search.Type), - commonRepo.WithLikeName(search.Info), + commonRepo.WithByLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order), databaseRepo.WithoutByFrom("local"), ) @@ -215,7 +215,7 @@ func (u *DatabaseService) Create(req dto.DatabaseCreate) error { func (u *DatabaseService) DeleteCheck(id uint) ([]string, error) { var appInUsed []string - apps, _ := appInstallResourceRepo.GetBy(databaseRepo.WithByFrom("remote"), appInstallResourceRepo.WithLinkId(id)) + apps, _ := appInstallResourceRepo.GetBy(commonRepo.WithByFrom("remote"), appInstallResourceRepo.WithLinkId(id)) for _, app := range apps { appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId)) if appInstall.ID != 0 { diff --git a/agent/app/service/database_mysql.go b/agent/app/service/database_mysql.go index 52fabdd70..aa62cf066 100644 --- a/agent/app/service/database_mysql.go +++ b/agent/app/service/database_mysql.go @@ -55,7 +55,7 @@ func NewIMysqlService() IMysqlService { func (u *MysqlService) SearchWithPage(search dto.MysqlDBSearch) (int64, interface{}, error) { total, mysqls, err := mysqlRepo.Page(search.Page, search.PageSize, mysqlRepo.WithByMysqlName(search.Database), - commonRepo.WithLikeName(search.Info), + commonRepo.WithByLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order), ) var dtoMysqls []dto.MysqlDBInfo @@ -101,7 +101,7 @@ func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*mode return nil, buserr.New(constant.ErrCmdIllegal) } - mysql, _ := mysqlRepo.Get(commonRepo.WithByName(req.Name), mysqlRepo.WithByMysqlName(req.Database), databaseRepo.WithByFrom(req.From)) + mysql, _ := mysqlRepo.Get(commonRepo.WithByName(req.Name), mysqlRepo.WithByMysqlName(req.Database), commonRepo.WithByFrom(req.From)) if mysql.ID != 0 { return nil, constant.ErrRecordExist } @@ -284,7 +284,7 @@ func (u *MysqlService) Delete(ctx context.Context, req dto.MysqlDBDelete) error if _, err := os.Stat(backupDir); err == nil { _ = os.RemoveAll(backupDir) } - _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), backupRepo.WithByDetailName(db.Name)) + _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), commonRepo.WithByDetailName(db.Name)) global.LOG.Infof("delete database %s-%s backups successful", req.Database, db.Name) } diff --git a/agent/app/service/database_postgresql.go b/agent/app/service/database_postgresql.go index 4defd6381..68697c709 100644 --- a/agent/app/service/database_postgresql.go +++ b/agent/app/service/database_postgresql.go @@ -43,7 +43,7 @@ func NewIPostgresqlService() IPostgresqlService { func (u *PostgresqlService) SearchWithPage(search dto.PostgresqlDBSearch) (int64, interface{}, error) { total, postgresqls, err := postgresqlRepo.Page(search.Page, search.PageSize, postgresqlRepo.WithByPostgresqlName(search.Database), - commonRepo.WithLikeName(search.Info), + commonRepo.WithByLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order), ) var dtoPostgresqls []dto.PostgresqlDBInfo @@ -125,7 +125,7 @@ func (u *PostgresqlService) Create(ctx context.Context, req dto.PostgresqlDBCrea return nil, buserr.New(constant.ErrCmdIllegal) } - pgsql, _ := postgresqlRepo.Get(commonRepo.WithByName(req.Name), postgresqlRepo.WithByPostgresqlName(req.Database), databaseRepo.WithByFrom(req.From)) + pgsql, _ := postgresqlRepo.Get(commonRepo.WithByName(req.Name), postgresqlRepo.WithByPostgresqlName(req.Database), commonRepo.WithByFrom(req.From)) if pgsql.ID != 0 { return nil, constant.ErrRecordExist } @@ -309,7 +309,7 @@ func (u *PostgresqlService) Delete(ctx context.Context, req dto.PostgresqlDBDele if _, err := os.Stat(backupDir); err == nil { _ = os.RemoveAll(backupDir) } - _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), backupRepo.WithByDetailName(db.Name)) + _ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), commonRepo.WithByDetailName(db.Name)) global.LOG.Infof("delete database %s-%s backups successful", req.Database, db.Name) } diff --git a/agent/app/service/file.go b/agent/app/service/file.go index 8790c68a8..4a1c9ebc8 100644 --- a/agent/app/service/file.go +++ b/agent/app/service/file.go @@ -2,7 +2,6 @@ package service import ( "fmt" - "github.com/1Panel-dev/1Panel/agent/app/repo" "io" "io/fs" "os" @@ -13,6 +12,8 @@ import ( "time" "unicode/utf8" + "github.com/1Panel-dev/1Panel/agent/app/repo" + "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto/response" "github.com/1Panel-dev/1Panel/agent/buserr" @@ -472,7 +473,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi if req.TaskID != "" { opts = append(opts, taskRepo.WithByID(req.TaskID)) } else { - opts = append(opts, taskRepo.WithType(req.TaskType), taskRepo.WithOperate(req.TaskOperate), taskRepo.WithResourceID(req.ID)) + opts = append(opts, commonRepo.WithByType(req.TaskType), taskRepo.WithOperate(req.TaskOperate), taskRepo.WithResourceID(req.ID)) } taskModel, err := taskRepo.GetFirst(opts...) if err != nil { diff --git a/agent/app/service/image_repo.go b/agent/app/service/image_repo.go index 535e393b8..8061e5a4b 100644 --- a/agent/app/service/image_repo.go +++ b/agent/app/service/image_repo.go @@ -34,7 +34,7 @@ func NewIImageRepoService() IImageRepoService { } func (u *ImageRepoService) Page(req dto.SearchWithPage) (int64, interface{}, error) { - total, ops, err := imageRepoRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderBy("created_at desc")) + total, ops, err := imageRepoRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info), commonRepo.WithOrderBy("created_at desc")) var dtoOps []dto.ImageRepoInfo for _, op := range ops { var item dto.ImageRepoInfo @@ -137,7 +137,7 @@ func (u *ImageRepoService) BatchDelete(req dto.ImageRepoDelete) error { return errors.New("The default value cannot be edit !") } } - if err := imageRepoRepo.Delete(commonRepo.WithIdsIn(req.Ids)); err != nil { + if err := imageRepoRepo.Delete(commonRepo.WithByIDs(req.Ids)); err != nil { return err } return nil diff --git a/agent/app/service/runtime.go b/agent/app/service/runtime.go index c083c3f94..ae4730f11 100644 --- a/agent/app/service/runtime.go +++ b/agent/app/service/runtime.go @@ -56,7 +56,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e opts []repo.DBOption ) if create.Name != "" { - opts = append(opts, commonRepo.WithLikeName(create.Name)) + opts = append(opts, commonRepo.WithByLikeName(create.Name)) } if create.Type != "" { opts = append(opts, commonRepo.WithByType(create.Type)) @@ -151,7 +151,7 @@ func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.Runt res []response.RuntimeDTO ) if req.Name != "" { - opts = append(opts, commonRepo.WithLikeName(req.Name)) + opts = append(opts, commonRepo.WithByLikeName(req.Name)) } if req.Status != "" { opts = append(opts, runtimeRepo.WithStatus(req.Status)) diff --git a/agent/app/service/snapshot.go b/agent/app/service/snapshot.go index 38da15ab0..b398efe1c 100644 --- a/agent/app/service/snapshot.go +++ b/agent/app/service/snapshot.go @@ -47,7 +47,7 @@ func NewISnapshotService() ISnapshotService { } func (u *SnapshotService) SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) { - total, systemBackups, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info)) + total, systemBackups, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info)) if err != nil { return 0, nil, err } @@ -320,7 +320,7 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, logPath string, req dto } func (u *SnapshotService) Delete(req dto.SnapshotBatchDelete) error { - snaps, _ := snapshotRepo.GetList(commonRepo.WithIdsIn(req.Ids)) + snaps, _ := snapshotRepo.GetList(commonRepo.WithByIDs(req.Ids)) for _, snap := range snaps { if req.DeleteWithFile { accounts, err := NewBackupClientMap(strings.Split(snap.SourceAccountIDs, ",")) diff --git a/agent/app/service/task.go b/agent/app/service/task.go index b4948801e..ede051344 100644 --- a/agent/app/service/task.go +++ b/agent/app/service/task.go @@ -20,10 +20,10 @@ func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, e commonRepo.WithOrderBy("created_at desc"), } if req.Status != "" { - opts = append(opts, taskRepo.WithStatus(req.Status)) + opts = append(opts, commonRepo.WithByStatus(req.Status)) } if req.Type != "" { - opts = append(opts, taskRepo.WithType(req.Type)) + opts = append(opts, commonRepo.WithByType(req.Type)) } total, tasks, err := taskRepo.Page( diff --git a/agent/app/service/website.go b/agent/app/service/website.go index c4488d9aa..54ffc602b 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -143,7 +143,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons for _, domain := range domains { websiteIds = append(websiteIds, domain.WebsiteID) } - opts = append(opts, websiteRepo.WithIDs(websiteIds)) + opts = append(opts, commonRepo.WithByIDs(websiteIds)) } else { opts = append(opts, websiteRepo.WithDomainLike(req.Name)) } @@ -298,8 +298,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) dbConfig := create.DataBaseConfig switch database.Type { case constant.AppPostgresql, constant.AppPostgres: - iPostgresqlRepo := repo.NewIPostgresqlRepo() - oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(create.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal)) + oldPostgresqlDb, _ := postgresqlRepo.Get(commonRepo.WithByName(create.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) if oldPostgresqlDb.ID > 0 { return buserr.New(constant.ErrDbUserNotValid) } @@ -318,8 +317,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) website.DbID = pgDB.ID website.DbType = database.Type case constant.AppMysql, constant.AppMariaDB: - iMysqlRepo := repo.NewIMysqlRepo() - oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal)) + oldMysqlDb, _ := mysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) if oldMysqlDb.ID > 0 { return buserr.New(constant.ErrDbUserNotValid) } @@ -520,7 +518,7 @@ func (w WebsiteService) OpWebsite(req request.WebsiteOp) error { func (w WebsiteService) GetWebsiteOptions(req request.WebsiteOptionReq) ([]response.WebsiteOption, error) { var options []repo.DBOption if len(req.Types) > 0 { - options = append(options, websiteRepo.WithTypes(req.Types)) + options = append(options, commonRepo.WithTypes(req.Types)) } webs, _ := websiteRepo.List(options...) var datas []response.WebsiteOption @@ -1170,7 +1168,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r checkIds = append(req.InstallIds, appInstall.ID) } if len(checkIds) > 0 { - installList, _ := appInstallRepo.ListBy(commonRepo.WithIdsIn(checkIds)) + installList, _ := appInstallRepo.ListBy(commonRepo.WithByIDs(checkIds)) for _, install := range installList { if err = syncAppInstallStatus(&install, false); err != nil { return nil, err @@ -2200,6 +2198,9 @@ func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []respo pathAuth.Path = location.Match passPath := path.Join(passDir, fmt.Sprintf("%s.pass", name)) authContent, err = fileOp.GetContent(passPath) + if err != nil { + return nil, err + } authArray := strings.Split(string(authContent), "\n") for _, line := range authArray { if line == "" { diff --git a/agent/constant/errs.go b/agent/constant/errs.go index 3dc3fae3d..f7c7a0281 100644 --- a/agent/constant/errs.go +++ b/agent/constant/errs.go @@ -18,7 +18,6 @@ var ( ErrRecordExist = errors.New("ErrRecordExist") ErrRecordNotFound = errors.New("ErrRecordNotFound") ErrStructTransform = errors.New("ErrStructTransform") - ErrInitialPassword = errors.New("ErrInitialPassword") ErrNotSupportType = errors.New("ErrNotSupportType") ErrInvalidParams = errors.New("ErrInvalidParams") ) @@ -132,11 +131,6 @@ var ( ErrFirewall = "ErrFirewall" ) -// cronjob -var ( - ErrBashExecute = "ErrBashExecute" -) - var ( ErrNotExistUser = "ErrNotExistUser" ) diff --git a/agent/i18n/lang/en.yaml b/agent/i18n/lang/en.yaml index 6a9166083..cdaebda8b 100644 --- a/agent/i18n/lang/en.yaml +++ b/agent/i18n/lang/en.yaml @@ -1,11 +1,8 @@ ErrInvalidParams: "Request parameter error: {{ .detail }}" -ErrInitialPassword: "Initial password error" ErrInternalServer: "Service internal error: {{ .detail }}" ErrRecordExist: "Record already exists" ErrRecordNotFound: "Records not found" ErrStructTransform: "Type conversion failure: {{ .detail }}" -ErrNotLogin: "User is not Login: {{ .detail }}" -ErrPasswordExpired: "The current password has expired: {{ .detail }}" ErrNotSupportType: "The system does not support the current type: {{ .detail }}" #common @@ -18,7 +15,6 @@ TYPE_APP: "Application" TYPE_RUNTIME: "Runtime environment" TYPE_DOMAIN: "Domain name" ErrTypePort: 'Port {{ .name }} format error' -ErrTypePortRange: 'Port range needs to be between 1-65535' Success: "Success" Failed: "Failed" SystemRestart: "System restart causes task interruption" @@ -167,7 +163,6 @@ ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}" ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!" #cronjob -ErrBashExecute: "Script execution error, please check the specific information in the task output text area." ErrCutWebsiteLog: "{{ .name }} website log cutting failed, error {{ .err }}" CutWebsiteLogSuccess: "{{ .name }} website log cut successfully, backup path {{ .path }}" diff --git a/agent/i18n/lang/zh-Hant.yaml b/agent/i18n/lang/zh-Hant.yaml index d2a4b63f7..dcbdff22c 100644 --- a/agent/i18n/lang/zh-Hant.yaml +++ b/agent/i18n/lang/zh-Hant.yaml @@ -1,11 +1,8 @@ ErrInvalidParams: "請求參數錯誤: {{ .detail }}" -ErrInitialPassword: "原密碼錯誤" ErrInternalServer: "伺服器內部錯誤: {{ .detail }}" ErrRecordExist: "記錄已存在" ErrRecordNotFound: "記錄未找到" ErrStructTransform: "類型轉換失敗: {{ .detail }}" -ErrNotLogin: "用戶未登入: {{ .detail }}" -ErrPasswordExpired: "當前密碼已過期: {{ .detail }}" ErrNotSupportType: "系統暫不支持當前類型: {{ .detail }}" #common @@ -18,7 +15,6 @@ TYPE_APP: "應用" TYPE_RUNTIME: "運作環境" TYPE_DOMAIN: "網域名稱" ErrTypePort: '埠 {{ .name }} 格式錯誤' -ErrTypePortRange: '連接埠範圍需要在 1-65535 之間' Success: "成功" Failed: "失敗" SystemRestart: "系統重啟導致任務中斷" @@ -168,7 +164,6 @@ ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}" ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!" #cronjob -ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。" ErrCutWebsiteLog: "{{ .name }} 網站日誌切割失敗,錯誤 {{ .err }}" CutWebsiteLogSuccess: "{{ .name }} 網站日誌切割成功,備份路徑 {{ .path }}" diff --git a/agent/i18n/lang/zh.yaml b/agent/i18n/lang/zh.yaml index cf9258006..be35323ef 100644 --- a/agent/i18n/lang/zh.yaml +++ b/agent/i18n/lang/zh.yaml @@ -1,11 +1,8 @@ ErrInvalidParams: "请求参数错误: {{ .detail }}" -ErrInitialPassword: "原密码错误" ErrInternalServer: "服务内部错误: {{ .detail }}" ErrRecordExist: "记录已存在" ErrRecordNotFound: "记录未能找到" ErrStructTransform: "类型转换失败: {{ .detail }}" -ErrNotLogin: "用户未登录: {{ .detail }}" -ErrPasswordExpired: "当前密码已过期: {{ .detail }}" ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}" #common @@ -18,7 +15,6 @@ TYPE_APP: "应用" TYPE_RUNTIME: "运行环境" TYPE_DOMAIN: "域名" ErrTypePort: '端口 {{ .name }} 格式错误' -ErrTypePortRange: '端口范围需要在 1-65535 之间' Success: "成功" Failed: "失败" SystemRestart: "系统重启导致任务中断" @@ -128,7 +124,7 @@ ExecShellSuccess: "脚本执行成功" ErrUserIsExist: "当前用户已存在,请重新输入" ErrDatabaseIsExist: "当前数据库已存在,请重新输入" ErrExecTimeOut: "SQL 执行超时,请检查数据库" -ErrRemoteExist: "远程数据库已存在该名称,请修改后重试" +ErrRemoteExist: "远程数据库已存在该名称,请修改后重试"vv ErrLocalExist: "本地数据库已存在该名称,请修改后重试" #redis @@ -170,7 +166,6 @@ ErrUserFindErr: "用户 {{ .name }} 查找失败 {{ .err }}" ErrFirewall: "当前未检测到系统 firewalld 或 ufw 服务,请检查后重试!" #cronjob -ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。" ErrCutWebsiteLog: "{{ .name }} 网站日志切割失败,错误 {{ .err }}" CutWebsiteLogSuccess: "{{ .name }} 网站日志切割成功,备份路径 {{ .path }}" diff --git a/core/app/repo/command.go b/core/app/repo/command.go index a17a257c9..6212ed050 100644 --- a/core/app/repo/command.go +++ b/core/app/repo/command.go @@ -3,21 +3,18 @@ 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 { - GetList(opts ...DBOption) ([]model.Command, error) + List(opts ...DBOption) ([]model.Command, error) Page(limit, offset int, opts ...DBOption) (int64, []model.Command, error) - WithByInfo(info string) DBOption 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) - WithLikeName(name string) DBOption } func NewICommandRepo() ICommandRepo { @@ -46,7 +43,7 @@ func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Com return count, users, err } -func (u *CommandRepo) GetList(opts ...DBOption) ([]model.Command, error) { +func (u *CommandRepo) List(opts ...DBOption) ([]model.Command, error) { var commands []model.Command db := global.DB.Model(&model.Command{}) for _, opt := range opts { @@ -56,16 +53,6 @@ func (u *CommandRepo) GetList(opts ...DBOption) ([]model.Command, error) { return commands, err } -func (c *CommandRepo) WithByInfo(info string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(info) == 0 { - return g - } - infoStr := "%" + info + "%" - return g.Where("name LIKE ? OR addr LIKE ?", infoStr, infoStr) - } -} - func (u *CommandRepo) Create(command *model.Command) error { return global.DB.Create(command).Error } @@ -84,12 +71,3 @@ func (u *CommandRepo) Delete(opts ...DBOption) error { } return db.Delete(&model.Command{}).Error } - -func (a CommandRepo) WithLikeName(name string) DBOption { - return func(g *gorm.DB) *gorm.DB { - if len(name) == 0 { - return g - } - return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%") - } -} diff --git a/core/app/repo/common.go b/core/app/repo/common.go index 013db44ef..f9a779921 100644 --- a/core/app/repo/common.go +++ b/core/app/repo/common.go @@ -11,8 +11,9 @@ type DBOption func(*gorm.DB) *gorm.DB type ICommonRepo interface { WithByID(id uint) DBOption - WithByName(name string) DBOption WithByIDs(ids []uint) DBOption + WithByName(name string) DBOption + WithLikeName(name string) DBOption WithByType(ty string) DBOption WithOrderBy(orderStr string) DBOption @@ -30,6 +31,11 @@ func (c *CommonRepo) WithByID(id uint) DBOption { return g.Where("id = ?", id) } } +func (c *CommonRepo) WithByIDs(ids []uint) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("id in (?)", ids) + } +} func (c *CommonRepo) WithByName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(name) == 0 { @@ -38,9 +44,12 @@ func (c *CommonRepo) WithByName(name string) DBOption { return g.Where("`name` = ?", name) } } -func (c *CommonRepo) WithByIDs(ids []uint) DBOption { +func (c *CommonRepo) WithLikeName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { - return g.Where("id in (?)", ids) + if len(name) == 0 { + return g + } + return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%") } } func (c *CommonRepo) WithByType(ty string) DBOption { diff --git a/core/app/repo/host.go b/core/app/repo/host.go index c0edb0faa..a93d57f50 100644 --- a/core/app/repo/host.go +++ b/core/app/repo/host.go @@ -12,14 +12,15 @@ 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) - WithByInfo(info string) DBOption - WithByPort(port uint) DBOption - WithByUser(user string) DBOption - WithByAddr(addr string) DBOption Create(host *model.Host) error Update(id uint, vars map[string]interface{}) error UpdateGroup(group, newGroup uint) error Delete(opts ...DBOption) error + + WithByInfo(info string) DBOption + WithByPort(port uint) DBOption + WithByUser(user string) DBOption + WithByAddr(addr string) DBOption } func NewIHostRepo() IHostRepo { diff --git a/core/app/repo/logs.go b/core/app/repo/logs.go index 6b094b9f7..87660aa5a 100644 --- a/core/app/repo/logs.go +++ b/core/app/repo/logs.go @@ -13,13 +13,14 @@ type ILogRepo interface { CreateLoginLog(user *model.LoginLog) error PageLoginLog(limit, offset int, opts ...DBOption) (int64, []model.LoginLog, error) + CleanOperation() error + CreateOperationLog(user *model.OperationLog) error + PageOperationLog(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error) + WithByIP(ip string) DBOption WithByStatus(status string) DBOption WithByGroup(group string) DBOption WithByLikeOperation(operation string) DBOption - CleanOperation() error - CreateOperationLog(user *model.OperationLog) error - PageOperationLog(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error) } func NewILogRepo() ILogRepo { diff --git a/core/app/repo/setting.go b/core/app/repo/setting.go index 4e8358b10..0759ccff4 100644 --- a/core/app/repo/setting.go +++ b/core/app/repo/setting.go @@ -9,7 +9,7 @@ import ( type SettingRepo struct{} type ISettingRepo interface { - GetList(opts ...DBOption) ([]model.Setting, error) + List(opts ...DBOption) ([]model.Setting, error) Get(opts ...DBOption) (model.Setting, error) Create(key, value string) error Update(key, value string) error @@ -20,7 +20,7 @@ func NewISettingRepo() ISettingRepo { return &SettingRepo{} } -func (u *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) { +func (u *SettingRepo) List(opts ...DBOption) ([]model.Setting, error) { var settings []model.Setting db := global.DB.Model(&model.Setting{}) for _, opt := range opts { diff --git a/core/app/service/command.go b/core/app/service/command.go index 0fe1d4939..6434143d8 100644 --- a/core/app/service/command.go +++ b/core/app/service/command.go @@ -24,7 +24,7 @@ func NewICommandService() ICommandService { } func (u *CommandService) List(req dto.OperateByType) ([]dto.CommandInfo, error) { - commands, err := commandRepo.GetList(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type)) + commands, err := commandRepo.List(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type)) if err != nil { return nil, constant.ErrRecordNotFound } @@ -40,7 +40,7 @@ func (u *CommandService) List(req dto.OperateByType) ([]dto.CommandInfo, error) } func (u *CommandService) SearchForTree(req dto.OperateByType) ([]dto.CommandTree, error) { - cmdList, err := commandRepo.GetList(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type)) + cmdList, err := commandRepo.List(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type)) if err != nil { return nil, err } @@ -71,7 +71,7 @@ func (u *CommandService) SearchWithPage(req dto.SearchCommandWithPage) (int64, i commonRepo.WithByType(req.Type), } if len(req.Info) != 0 { - options = append(options, commandRepo.WithLikeName(req.Info)) + options = append(options, commonRepo.WithLikeName(req.Info)) } if req.GroupID != 0 { options = append(options, groupRepo.WithByGroupID(req.GroupID)) diff --git a/core/app/service/host.go b/core/app/service/host.go index 30959239c..a0bf50cb8 100644 --- a/core/app/service/host.go +++ b/core/app/service/host.go @@ -153,7 +153,7 @@ func (u *HostService) GetHostInfo(id uint) (*model.Host, error) { func (u *HostService) SearchWithPage(req dto.SearchHostWithPage) (int64, interface{}, error) { var options []repo.DBOption if len(req.Info) != 0 { - options = append(options, commandRepo.WithLikeName(req.Info)) + options = append(options, commonRepo.WithLikeName(req.Info)) } if req.GroupID != 0 { options = append(options, groupRepo.WithByGroupID(req.GroupID)) diff --git a/core/app/service/setting.go b/core/app/service/setting.go index 7f9636646..0523a0524 100644 --- a/core/app/service/setting.go +++ b/core/app/service/setting.go @@ -43,7 +43,7 @@ func NewISettingService() ISettingService { } func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) { - setting, err := settingRepo.GetList() + setting, err := settingRepo.List() if err != nil { return nil, constant.ErrRecordNotFound } diff --git a/frontend/src/components/group/index.vue b/frontend/src/components/group/index.vue index 7a1138b77..6931efad5 100644 --- a/frontend/src/components/group/index.vue +++ b/frontend/src/components/group/index.vue @@ -38,23 +38,6 @@ - - - -