diff --git a/agent/app/repo/common.go b/agent/app/repo/common.go index 1dc9444a67e8..ce93654308dd 100644 --- a/agent/app/repo/common.go +++ b/agent/app/repo/common.go @@ -12,54 +12,25 @@ import ( 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 - - WithByDate(startTime, endTime time.Time) DBOption - WithByCreatedAt(startTime, endTime time.Time) DBOption -} - -type CommonRepo struct{} - -func NewCommonRepo() ICommonRepo { - return &CommonRepo{} -} - -func (c *CommonRepo) WithByID(id uint) DBOption { +func WithByID(id uint) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("id = ?", id) } } -func (c *CommonRepo) WithByIDs(ids []uint) DBOption { + +func WithByIDs(ids []uint) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("id in (?)", ids) } } -func (c *CommonRepo) WithByName(name string) DBOption { +func 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 { + +func WithByLikeName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(name) == 0 { return g @@ -67,7 +38,8 @@ func (c *CommonRepo) WithByLikeName(name string) DBOption { return g.Where("name like ?", "%"+name+"%") } } -func (c *CommonRepo) WithByDetailName(detailName string) DBOption { + +func WithByDetailName(detailName string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(detailName) == 0 { return g @@ -76,17 +48,19 @@ func (c *CommonRepo) WithByDetailName(detailName string) DBOption { } } -func (c *CommonRepo) WithByType(tp string) DBOption { +func WithByType(tp string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("type = ?", tp) } } -func (c *CommonRepo) WithTypes(types []string) DBOption { + +func WithTypes(types []string) DBOption { return func(db *gorm.DB) *gorm.DB { return db.Where("type in (?)", types) } } -func (c *CommonRepo) WithByStatus(status string) DBOption { + +func WithByStatus(status string) DBOption { return func(g *gorm.DB) *gorm.DB { if len(status) == 0 { return g @@ -94,25 +68,25 @@ func (c *CommonRepo) WithByStatus(status string) DBOption { return g.Where("status = ?", status) } } -func (c *CommonRepo) WithByFrom(from string) DBOption { +func 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 { +func WithByDate(startTime, endTime time.Time) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("start_time > ? AND start_time < ?", startTime, endTime) } } -func (c *CommonRepo) WithByCreatedAt(startTime, endTime time.Time) DBOption { +func WithByCreatedAt(startTime, endTime time.Time) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("created_at > ? AND created_at < ?", startTime, endTime) } } -func (c *CommonRepo) WithOrderBy(orderStr string) DBOption { +func WithOrderBy(orderStr string) DBOption { if orderStr == "createdAt" { orderStr = "created_at" } @@ -120,7 +94,7 @@ func (c *CommonRepo) WithOrderBy(orderStr string) DBOption { return g.Order(orderStr) } } -func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption { +func WithOrderRuleBy(orderBy, order string) DBOption { if orderBy == "createdAt" { orderBy = "created_at" } diff --git a/agent/app/repo/entry.go b/agent/app/repo/entry.go deleted file mode 100644 index 19f73a359b1d..000000000000 --- a/agent/app/repo/entry.go +++ /dev/null @@ -1,5 +0,0 @@ -package repo - -var ( - commonRepo = NewCommonRepo() -) diff --git a/agent/app/repo/task.go b/agent/app/repo/task.go index a866eb26ec75..a9bb01d19acf 100644 --- a/agent/app/repo/task.go +++ b/agent/app/repo/task.go @@ -2,7 +2,6 @@ package repo import ( "context" - "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" @@ -24,6 +23,7 @@ type ITaskRepo interface { WithByID(id string) DBOption WithResourceID(id uint) DBOption WithOperate(taskOperate string) DBOption + WithByStatus(status string) DBOption } func NewITaskRepo() ITaskRepo { @@ -67,6 +67,12 @@ func (t TaskRepo) WithResourceID(id uint) DBOption { } } +func (t TaskRepo) WithByStatus(status string) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("status = ?", status) + } +} + func (t TaskRepo) Save(ctx context.Context, task *model.Task) error { return getTaskTx(ctx).Save(&task).Error } @@ -94,11 +100,11 @@ func (t TaskRepo) Update(ctx context.Context, task *model.Task) error { } func (t TaskRepo) UpdateRunningTaskToFailed() error { - return getTaskDb(commonRepo.WithByStatus(constant.StatusExecuting)).Model(&model.Task{}).Updates(map[string]interface{}{"status": constant.StatusFailed, "error_msg": "1Panel restart causes failure"}).Error + return getTaskDb(t.WithByStatus(constant.StatusExecuting)).Model(&model.Task{}).Updates(map[string]interface{}{"status": constant.StatusFailed, "error_msg": "1Panel restart causes failure"}).Error } func (t TaskRepo) CountExecutingTask() (int64, error) { var count int64 - err := getTaskDb(commonRepo.WithByStatus(constant.StatusExecuting)).Model(&model.Task{}).Count(&count).Error + err := getTaskDb(t.WithByStatus(constant.StatusExecuting)).Model(&model.Task{}).Count(&count).Error return count, err } diff --git a/agent/app/service/app.go b/agent/app/service/app.go index 64d3fa0fe1c3..7fa1a1bcaccd 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -95,7 +95,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) { for _, t := range appTags { appIds = append(appIds, t.AppId) } - opts = append(opts, commonRepo.WithByIDs(appIds)) + opts = append(opts, repo.WithByIDs(appIds)) } var res response.AppRes @@ -203,7 +203,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response. appDetailDTO.Enable = true if appType == "runtime" { - app, err := appRepo.GetFirst(commonRepo.WithByID(appID)) + app, err := appRepo.GetFirst(repo.WithByID(appID)) if err != nil { return appDetailDTO, err } @@ -274,7 +274,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response. appDetailDTO.HostMode = isHostModel(appDetailDTO.DockerCompose) - app, err := appRepo.GetFirst(commonRepo.WithByID(detail.AppId)) + app, err := appRepo.GetFirst(repo.WithByID(detail.AppId)) if err != nil { return appDetailDTO, err } @@ -288,7 +288,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response. } func (a AppService) GetAppDetailByID(id uint) (*response.AppDetailDTO, error) { res := &response.AppDetailDTO{} - appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(id)) + appDetail, err := appDetailRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -309,7 +309,7 @@ func (a AppService) GetIgnoredApp() ([]response.IgnoredApp, error) { return res, nil } for _, detail := range details { - app, err := appRepo.GetFirst(commonRepo.WithByID(detail.AppId)) + app, err := appRepo.GetFirst(repo.WithByID(detail.AppId)) if err != nil { return nil, err } @@ -328,7 +328,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App err = buserr.WithDetail(constant.Err1PanelNetworkFailed, err.Error(), nil) return } - if list, _ := appInstallRepo.ListBy(commonRepo.WithByName(req.Name)); len(list) > 0 { + if list, _ := appInstallRepo.ListBy(repo.WithByName(req.Name)); len(list) > 0 { err = buserr.New(constant.ErrAppNameExist) return } @@ -338,16 +338,16 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App appDetail model.AppDetail app model.App ) - appDetail, err = appDetailRepo.GetFirst(commonRepo.WithByID(req.AppDetailId)) + appDetail, err = appDetailRepo.GetFirst(repo.WithByID(req.AppDetailId)) if err != nil { return } - app, err = appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId)) + app, err = appRepo.GetFirst(repo.WithByID(appDetail.AppId)) if err != nil { return } if DatabaseKeys[app.Key] > 0 { - if existDatabases, _ := databaseRepo.GetList(commonRepo.WithByName(req.Name)); len(existDatabases) > 0 { + if existDatabases, _ := databaseRepo.GetList(repo.WithByName(req.Name)); len(existDatabases) > 0 { err = buserr.New(constant.ErrRemoteExist) return } @@ -462,7 +462,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App appInstall.DockerCompose = string(composeByte) if hostName, ok := req.Params["PANEL_DB_HOST"]; ok { - database, _ := databaseRepo.Get(commonRepo.WithByName(hostName.(string))) + database, _ := databaseRepo.Get(repo.WithByName(hostName.(string))) if !reflect.DeepEqual(database, model.Database{}) { req.Params["PANEL_DB_HOST"] = database.Address req.Params["PANEL_DB_PORT"] = database.Port diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index 8a13b951325e..f60ab93ff3c8 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -88,7 +88,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo ) if req.Name != "" { - opts = append(opts, commonRepo.WithByLikeName(req.Name)) + opts = append(opts, repo.WithByLikeName(req.Name)) } if len(req.Tags) != 0 { @@ -146,7 +146,7 @@ func (a *AppInstallService) CheckExist(req request.AppInstalledInfo) (*response. if len(req.Name) == 0 { appInstall, _ = appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID)) } else { - appInstall, _ = appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID), commonRepo.WithByName(req.Name)) + appInstall, _ = appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID), repo.WithByName(req.Name)) } if reflect.DeepEqual(appInstall, model.AppInstall{}) { @@ -240,7 +240,7 @@ func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([] } func (a *AppInstallService) Operate(req request.AppInstalledOperate) error { - install, err := appInstallRepo.GetFirstByCtx(context.Background(), commonRepo.WithByID(req.InstallId)) + install, err := appInstallRepo.GetFirstByCtx(context.Background(), repo.WithByID(req.InstallId)) if err != nil { return err } @@ -302,7 +302,7 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error { } func (a *AppInstallService) UpdateAppConfig(req request.AppConfigUpdate) error { - installed, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallID)) + installed, err := appInstallRepo.GetFirst(repo.WithByID(req.InstallID)) if err != nil { return err } @@ -314,7 +314,7 @@ func (a *AppInstallService) UpdateAppConfig(req request.AppConfigUpdate) error { } func (a *AppInstallService) Update(req request.AppInstalledUpdate) error { - installed, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId)) + installed, err := appInstallRepo.GetFirst(repo.WithByID(req.InstallId)) if err != nil { return err } @@ -441,7 +441,7 @@ func (a *AppInstallService) Update(req request.AppInstalledUpdate) error { } func (a *AppInstallService) IgnoreUpgrade(req request.AppInstalledIgnoreUpgrade) error { - appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(req.DetailID)) + appDetail, err := appDetailRepo.GetFirst(repo.WithByID(req.DetailID)) if err != nil { return err } @@ -478,7 +478,7 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro if key == constant.AppPostgres { key = constant.AppPostgresql } - dbs, _ := databaseRepo.GetList(commonRepo.WithByType(key)) + dbs, _ := databaseRepo.GetList(repo.WithByType(key)) if len(dbs) == 0 { return res, nil } @@ -488,7 +488,7 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro Value: db.Name, } if db.AppInstallID > 0 { - install, err := appInstallRepo.GetFirst(commonRepo.WithByID(db.AppInstallID)) + install, err := appInstallRepo.GetFirst(repo.WithByID(db.AppInstallID)) if err != nil { return nil, err } @@ -528,12 +528,12 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro } func (a *AppInstallService) GetUpdateVersions(req request.AppUpdateVersion) ([]dto.AppVersion, error) { - install, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.AppInstallID)) + install, err := appInstallRepo.GetFirst(repo.WithByID(req.AppInstallID)) var versions []dto.AppVersion if err != nil { return versions, err } - app, err := appRepo.GetFirst(commonRepo.WithByID(install.AppId)) + app, err := appRepo.GetFirst(repo.WithByID(install.AppId)) if err != nil { return versions, err } @@ -602,7 +602,7 @@ func (a *AppInstallService) ChangeAppPort(req request.PortUpdate) error { appRess, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID)) for _, appRes := range appRess { - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(appRes.AppInstallId)) + appInstall, err := appInstallRepo.GetFirst(repo.WithByID(appRes.AppInstallId)) if err != nil { return err } @@ -616,7 +616,7 @@ func (a *AppInstallService) ChangeAppPort(req request.PortUpdate) error { func (a *AppInstallService) DeleteCheck(installID uint) ([]dto.AppResource, error) { var res []dto.AppResource - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installID)) + appInstall, err := appInstallRepo.GetFirst(repo.WithByID(installID)) if err != nil { return nil, err } @@ -627,9 +627,9 @@ func (a *AppInstallService) DeleteCheck(installID uint) ([]dto.AppResource, erro Name: website.PrimaryDomain, }) } - resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID), commonRepo.WithByFrom(constant.AppResourceLocal)) + resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID), repo.WithByFrom(constant.AppResourceLocal)) for _, resource := range resources { - linkInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(resource.AppInstallId)) + linkInstall, _ := appInstallRepo.GetFirst(repo.WithByID(resource.AppInstallId)) res = append(res, dto.AppResource{ Type: "app", Name: linkInstall.Name, @@ -676,11 +676,11 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) { envs = make(map[string]interface{}) res response.AppConfig ) - install, err := appInstallRepo.GetFirst(commonRepo.WithByID(id)) + install, err := appInstallRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } - detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(install.AppDetailId)) + detail, err := appDetailRepo.GetFirst(repo.WithByID(install.AppDetailId)) if err != nil { return nil, err } @@ -857,7 +857,7 @@ func updateInstallInfoInDB(appKey, appName, param string, value interface{}) err _ = appInstallRepo.BatchUpdateBy(map[string]interface{}{ "param": strings.ReplaceAll(appInstall.Param, oldVal, newVal), "env": strings.ReplaceAll(appInstall.Env, oldVal, newVal), - }, commonRepo.WithByID(appInstall.ID)) + }, repo.WithByID(appInstall.ID)) } if param == "user-password" { oldVal = fmt.Sprintf("\"PANEL_DB_USER_PASSWORD\":\"%v\"", appInstall.UserPassword) @@ -865,7 +865,7 @@ func updateInstallInfoInDB(appKey, appName, param string, value interface{}) err _ = appInstallRepo.BatchUpdateBy(map[string]interface{}{ "param": strings.ReplaceAll(appInstall.Param, oldVal, newVal), "env": strings.ReplaceAll(appInstall.Env, oldVal, newVal), - }, commonRepo.WithByID(appInstall.ID)) + }, repo.WithByID(appInstall.ID)) } if param == "port" { oldVal = fmt.Sprintf("\"PANEL_APP_PORT_HTTP\":%v", appInstall.Port) @@ -874,7 +874,7 @@ func updateInstallInfoInDB(appKey, appName, param string, value interface{}) err "param": strings.ReplaceAll(appInstall.Param, oldVal, newVal), "env": strings.ReplaceAll(appInstall.Env, oldVal, newVal), "http_port": value, - }, commonRepo.WithByID(appInstall.ID)) + }, repo.WithByID(appInstall.ID)) } ComposeFile := fmt.Sprintf("%s/%s/%s/docker-compose.yml", constant.AppInstallDir, appKey, appInstall.Name) diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index f413d8dde326..efed7c8d4bb2 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/utils/nginx" "github.com/1Panel-dev/1Panel/agent/utils/nginx/parser" "github.com/1Panel-dev/1Panel/agent/utils/xpack" @@ -155,7 +156,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI Address: appInstall.ServiceName, Port: DatabaseKeys[app.Key], } - detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(appInstall.AppDetailId)) + detail, err := appDetailRepo.GetFirst(repo.WithByID(appInstall.AppDetailId)) if err != nil { return err } @@ -250,7 +251,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI if hostName == nil || hostName.(string) == "" { return nil } - database, _ := databaseRepo.Get(commonRepo.WithByName(hostName.(string))) + database, _ := databaseRepo.Get(repo.WithByName(hostName.(string))) if database.ID == 0 { return nil } @@ -258,7 +259,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: - oldPostgresqlDb, _ := postgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) + oldPostgresqlDb, _ := postgresqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.ResourceLocal)) resourceId = oldPostgresqlDb.ID if oldPostgresqlDb.ID > 0 { if oldPostgresqlDb.Username != dbConfig.DbUser || oldPostgresqlDb.Password != dbConfig.Password { @@ -280,7 +281,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI resourceId = pgdb.ID } case constant.AppMysql, constant.AppMariaDB: - oldMysqlDb, _ := mysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) + oldMysqlDb, _ := mysqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.ResourceLocal)) resourceId = oldMysqlDb.ID if oldMysqlDb.ID > 0 { if oldMysqlDb.Username != dbConfig.DbUser || oldMysqlDb.Password != dbConfig.Password { @@ -411,7 +412,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), commonRepo.WithByDetailName(install.Name)) + _ = backupRepo.DeleteRecord(ctx, repo.WithByType("app"), repo.WithByName(install.App.Key), repo.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) @@ -448,7 +449,7 @@ func deleteLink(del dto.DelAppLink) error { switch re.Key { case constant.AppMysql, constant.AppMariaDB: mysqlService := NewIMysqlService() - database, _ := mysqlRepo.Get(commonRepo.WithByID(re.ResourceId)) + database, _ := mysqlRepo.Get(repo.WithByID(re.ResourceId)) if reflect.DeepEqual(database, model.DatabaseMysql{}) { continue } @@ -463,7 +464,7 @@ func deleteLink(del dto.DelAppLink) error { } case constant.AppPostgresql: pgsqlService := NewIPostgresqlService() - database, _ := postgresqlRepo.Get(commonRepo.WithByID(re.ResourceId)) + database, _ := postgresqlRepo.Get(repo.WithByID(re.ResourceId)) if reflect.DeepEqual(database, model.DatabasePostgresql{}) { continue } @@ -535,11 +536,11 @@ func getUpgradeCompose(install model.AppInstall, detail model.AppDetail) (string } func upgradeInstall(req request.AppInstallUpgrade) error { - install, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallID)) + install, err := appInstallRepo.GetFirst(repo.WithByID(req.InstallID)) if err != nil { return err } - detail, err := appDetailRepo.GetFirst(commonRepo.WithByID(req.DetailID)) + detail, err := appDetailRepo.GetFirst(repo.WithByID(req.DetailID)) if err != nil { return err } @@ -711,16 +712,16 @@ func upgradeInstall(req request.AppInstallUpgrade) error { } t.Log(i18n.GetMsgByKey("DeleteRuntimePHP")) _ = fileOp.DeleteDir(path.Join(constant.RuntimeDir, "php")) - websites, _ := websiteRepo.List(commonRepo.WithByType("runtime")) + websites, _ := websiteRepo.List(repo.WithByType("runtime")) for _, website := range websites { - runtime, _ := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, _ := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if runtime != nil && runtime.Type == "php" { website.Type = constant.Static website.RuntimeID = 0 _ = websiteRepo.SaveWithoutCtx(&website) } } - _ = runtimeRepo.DeleteBy(commonRepo.WithByType("php")) + _ = runtimeRepo.DeleteBy(repo.WithByType("php")) t.Log(i18n.GetMsgByKey("MoveSiteDirSuccess")) } @@ -766,7 +767,7 @@ func upgradeInstall(req request.AppInstallUpgrade) error { go func() { err = upgradeTask.Execute() if err != nil { - existInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallID)) + existInstall, _ := appInstallRepo.GetFirst(repo.WithByID(req.InstallID)) if existInstall.ID > 0 && existInstall.Status != constant.Running { existInstall.Status = constant.UpgradeErr existInstall.Message = err.Error() @@ -1082,7 +1083,7 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error task.LogSuccess(logStr) return } - exist, _ := appInstallRepo.GetFirst(commonRepo.WithByID(appInstall.ID)) + exist, _ := appInstallRepo.GetFirst(repo.WithByID(appInstall.ID)) if exist.ID > 0 { containerNames, err := getContainerNames(*appInstall) if err == nil { @@ -1439,7 +1440,7 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) if updated { installDTO.DockerCompose = installed.DockerCompose } - app, err := appRepo.GetFirst(commonRepo.WithByID(installed.AppId)) + app, err := appRepo.GetFirst(repo.WithByID(installed.AppId)) if err != nil { return nil, err } diff --git a/agent/app/service/backup.go b/agent/app/service/backup.go index c8a46cb5d489..6ee37b10ad09 100644 --- a/agent/app/service/backup.go +++ b/agent/app/service/backup.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "sort" @@ -68,7 +69,7 @@ func (u *BackupService) Sync(req dto.SyncFromMaster) error { } accountItem.AccessKey, _ = encrypt.StringEncryptWithBase64(accountItem.AccessKey) accountItem.Credential, _ = encrypt.StringEncryptWithBase64(accountItem.Credential) - account, _ := backupRepo.Get(commonRepo.WithByName(req.Name)) + account, _ := backupRepo.Get(repo.WithByName(req.Name)) switch req.Operation { case "create": if account.ID != 0 { @@ -80,7 +81,7 @@ func (u *BackupService) Sync(req dto.SyncFromMaster) error { if account.ID == 0 { return constant.ErrRecordNotFound } - return backupRepo.Delete(commonRepo.WithByID(account.ID)) + return backupRepo.Delete(repo.WithByID(account.ID)) case "update": if account.ID == 0 { return constant.ErrRecordNotFound @@ -93,7 +94,7 @@ func (u *BackupService) Sync(req dto.SyncFromMaster) error { } func (u *BackupService) LoadBackupOptions() ([]dto.BackupOption, error) { - accounts, err := backupRepo.List(commonRepo.WithOrderBy("created_at desc")) + accounts, err := backupRepo.List(repo.WithOrderBy("created_at desc")) if err != nil { return nil, err } @@ -111,10 +112,10 @@ func (u *BackupService) LoadBackupOptions() ([]dto.BackupOption, error) { func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, []dto.BackupRecords, error) { total, records, err := backupRepo.PageRecord( search.Page, search.PageSize, - commonRepo.WithOrderBy("created_at desc"), - commonRepo.WithByName(search.Name), - commonRepo.WithByType(search.Type), - commonRepo.WithByDetailName(search.DetailName), + repo.WithOrderBy("created_at desc"), + repo.WithByName(search.Name), + repo.WithByType(search.Type), + repo.WithByDetailName(search.DetailName), ) if err != nil { return 0, nil, err @@ -133,7 +134,7 @@ func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, [ func (u *BackupService) SearchRecordsByCronjobWithPage(search dto.RecordSearchByCronjob) (int64, []dto.BackupRecords, error) { total, records, err := backupRepo.PageRecord( search.Page, search.PageSize, - commonRepo.WithOrderBy("created_at desc"), + repo.WithOrderBy("created_at desc"), backupRepo.WithByCronID(search.CronjobID), ) if err != nil { @@ -202,10 +203,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), commonRepo.WithByDetailName(detailName)) + return backupRepo.DeleteRecord(context.Background(), repo.WithByType(backupType), repo.WithByName(name), repo.WithByDetailName(detailName)) } - records, err := backupRepo.ListRecord(commonRepo.WithByType(backupType), commonRepo.WithByName(name), commonRepo.WithByDetailName(detailName)) + records, err := backupRepo.ListRecord(repo.WithByType(backupType), repo.WithByName(name), repo.WithByDetailName(detailName)) if err != nil { return err } @@ -219,13 +220,13 @@ func (u *BackupService) DeleteRecordByName(backupType, name, detailName string, if _, err = client.Delete(path.Join(record.FileDir, record.FileName)); err != nil { global.LOG.Errorf("remove file %s failed, err: %v", path.Join(record.FileDir, record.FileName), err) } - _ = backupRepo.DeleteRecord(context.Background(), commonRepo.WithByID(record.ID)) + _ = backupRepo.DeleteRecord(context.Background(), repo.WithByID(record.ID)) } return nil } func (u *BackupService) BatchDeleteRecord(ids []uint) error { - records, err := backupRepo.ListRecord(commonRepo.WithByIDs(ids)) + records, err := backupRepo.ListRecord(repo.WithByIDs(ids)) if err != nil { return err } @@ -239,14 +240,14 @@ 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.WithByIDs(ids)) + return backupRepo.DeleteRecord(context.Background(), repo.WithByIDs(ids)) } func (u *BackupService) ListAppRecords(name, detailName, fileName string) ([]model.BackupRecord, error) { records, err := backupRepo.ListRecord( - commonRepo.WithOrderBy("created_at asc"), - commonRepo.WithByName(name), - commonRepo.WithByType("app"), + repo.WithOrderBy("created_at asc"), + repo.WithByName(name), + repo.WithByType("app"), backupRepo.WithFileNameStartWith(fileName), backupRepo.WithByDetailName(detailName), ) @@ -336,7 +337,7 @@ func NewBackupClientWithID(id uint) (*model.BackupAccount, cloud_storage.CloudSt account.AccessKey, _ = encrypt.StringDecryptWithKey(account.AccessKey, setting.Value) account.Credential, _ = encrypt.StringDecryptWithKey(account.Credential, setting.Value) } else { - account, _ = backupRepo.Get(commonRepo.WithByID(id)) + account, _ = backupRepo.Get(repo.WithByID(id)) } backClient, err := newClient(&account) if err != nil { @@ -376,7 +377,7 @@ func NewBackupClientMap(ids []string) (map[string]backupClientHelper, error) { item, _ := strconv.Atoi(ids[i]) idItems = append(idItems, uint(item)) } - accounts, _ = backupRepo.List(commonRepo.WithByIDs(idItems)) + accounts, _ = backupRepo.List(repo.WithByIDs(idItems)) } clientMap := make(map[string]backupClientHelper) for _, item := range accounts { diff --git a/agent/app/service/backup_app.go b/agent/app/service/backup_app.go index 38515aac73fc..b462ec4d8cba 100644 --- a/agent/app/service/backup_app.go +++ b/agent/app/service/backup_app.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "io/fs" "os" "path" @@ -30,7 +31,7 @@ func (u *BackupService) AppBackup(req dto.CommonBackup) (*model.BackupRecord, er if err != nil { return nil, err } - install, err := appInstallRepo.GetFirst(commonRepo.WithByName(req.DetailName), appInstallRepo.WithAppId(app.ID)) + install, err := appInstallRepo.GetFirst(repo.WithByName(req.DetailName), appInstallRepo.WithAppId(app.ID)) if err != nil { return nil, err } @@ -79,7 +80,7 @@ func (u *BackupService) AppRecover(req dto.CommonRecover) error { if err != nil { return err } - install, err := appInstallRepo.GetFirst(commonRepo.WithByName(req.DetailName), appInstallRepo.WithAppId(app.ID)) + install, err := appInstallRepo.GetFirst(repo.WithByName(req.DetailName), appInstallRepo.WithAppId(app.ID)) if err != nil { return err } @@ -102,7 +103,7 @@ func (u *BackupService) AppRecover(req dto.CommonRecover) error { func backupDatabaseWithTask(parentTask *task.Task, resourceKey, tmpDir, name string, databaseID uint) error { switch resourceKey { case constant.AppMysql, constant.AppMariaDB: - db, err := mysqlRepo.Get(commonRepo.WithByID(databaseID)) + db, err := mysqlRepo.Get(repo.WithByID(databaseID)) if err != nil { return err } @@ -113,7 +114,7 @@ func backupDatabaseWithTask(parentTask *task.Task, resourceKey, tmpDir, name str } parentTask.LogSuccess(task.GetTaskName(db.Name, task.TaskBackup, task.TaskScopeDatabase)) case constant.AppPostgresql: - db, err := postgresqlRepo.Get(commonRepo.WithByID(databaseID)) + db, err := postgresqlRepo.Get(repo.WithByID(databaseID)) if err != nil { return err } @@ -237,23 +238,23 @@ func handleAppRecover(install *model.AppInstall, parentTask *task.Task, recoverF var database model.Database switch resource.From { case constant.AppResourceRemote: - database, err = databaseRepo.Get(commonRepo.WithByID(resource.LinkId)) + database, err = databaseRepo.Get(repo.WithByID(resource.LinkId)) if err != nil { return err } case constant.AppResourceLocal: - resourceApp, err := appInstallRepo.GetFirst(commonRepo.WithByID(resource.LinkId)) + resourceApp, err := appInstallRepo.GetFirst(repo.WithByID(resource.LinkId)) if err != nil { return err } - database, err = databaseRepo.Get(databaseRepo.WithAppInstallID(resourceApp.ID), commonRepo.WithByType(resource.Key), commonRepo.WithByFrom(constant.AppResourceLocal), commonRepo.WithByName(resourceApp.Name)) + database, err = databaseRepo.Get(databaseRepo.WithAppInstallID(resourceApp.ID), repo.WithByType(resource.Key), repo.WithByFrom(constant.AppResourceLocal), repo.WithByName(resourceApp.Name)) if err != nil { return err } } switch database.Type { case constant.AppPostgresql: - db, err := postgresqlRepo.Get(commonRepo.WithByID(resource.ResourceId)) + db, err := postgresqlRepo.Get(repo.WithByID(resource.ResourceId)) if err != nil { return err } @@ -269,7 +270,7 @@ func handleAppRecover(install *model.AppInstall, parentTask *task.Task, recoverF } t.LogSuccess(taskName) case constant.AppMysql, constant.AppMariaDB: - db, err := mysqlRepo.Get(commonRepo.WithByID(resource.ResourceId)) + db, err := mysqlRepo.Get(repo.WithByID(resource.ResourceId)) if err != nil { return err } @@ -285,7 +286,7 @@ func handleAppRecover(install *model.AppInstall, parentTask *task.Task, recoverF if err != nil { return err } - _ = appInstallResourceRepo.BatchUpdateBy(map[string]interface{}{"resource_id": newDB.ID}, commonRepo.WithByID(resource.ID)) + _ = appInstallResourceRepo.BatchUpdateBy(map[string]interface{}{"resource_id": newDB.ID}, repo.WithByID(resource.ID)) taskName := task.GetTaskName(db.Name, task.TaskRecover, task.TaskScopeDatabase) t.LogStart(taskName) if err := handleMysqlRecover(dto.CommonRecover{ diff --git a/agent/app/service/backup_mysql.go b/agent/app/service/backup_mysql.go index c16d4bc6f2d2..750cf20fd758 100644 --- a/agent/app/service/backup_mysql.go +++ b/agent/app/service/backup_mysql.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "path/filepath" @@ -107,7 +108,7 @@ func handleMysqlBackup(db DatabaseHelper, parentTask *task.Task, targetDir, file itemTask *task.Task ) itemTask = parentTask - dbInfo, err := mysqlRepo.Get(commonRepo.WithByName(db.Name), mysqlRepo.WithByMysqlName(db.Database)) + dbInfo, err := mysqlRepo.Get(repo.WithByName(db.Name), mysqlRepo.WithByMysqlName(db.Database)) if err != nil { return err } @@ -151,7 +152,7 @@ func handleMysqlRecover(req dto.CommonRecover, parentTask *task.Task, isRollback itemTask *task.Task ) itemTask = parentTask - dbInfo, err := mysqlRepo.Get(commonRepo.WithByName(req.DetailName), mysqlRepo.WithByMysqlName(req.Name)) + dbInfo, err := mysqlRepo.Get(repo.WithByName(req.DetailName), mysqlRepo.WithByMysqlName(req.Name)) if err != nil { return err } @@ -169,7 +170,7 @@ func handleMysqlRecover(req dto.CommonRecover, parentTask *task.Task, isRollback if !fileOp.Stat(req.File) { return buserr.WithName("ErrFileNotFound", req.File) } - dbInfo, err := mysqlRepo.Get(commonRepo.WithByName(req.DetailName), mysqlRepo.WithByMysqlName(req.Name)) + dbInfo, err := mysqlRepo.Get(repo.WithByName(req.DetailName), mysqlRepo.WithByMysqlName(req.Name)) if err != nil { return err } diff --git a/agent/app/service/backup_postgresql.go b/agent/app/service/backup_postgresql.go index e5292e0aaee1..b8e41f08e5a0 100644 --- a/agent/app/service/backup_postgresql.go +++ b/agent/app/service/backup_postgresql.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "path/filepath" @@ -142,7 +143,7 @@ func handlePostgresqlRecover(req dto.CommonRecover, parentTask *task.Task, isRol err error itemTask *task.Task ) - dbInfo, err := postgresqlRepo.Get(commonRepo.WithByName(req.DetailName), postgresqlRepo.WithByPostgresqlName(req.Name)) + dbInfo, err := postgresqlRepo.Get(repo.WithByName(req.DetailName), postgresqlRepo.WithByPostgresqlName(req.Name)) if err != nil { return err } diff --git a/agent/app/service/backup_website.go b/agent/app/service/backup_website.go index 0e6a00e9e647..53feb8dbbb01 100644 --- a/agent/app/service/backup_website.go +++ b/agent/app/service/backup_website.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "io/fs" "os" "path" @@ -141,7 +142,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback switch website.Type { case constant.Deployment: - app, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) + app, err := appInstallRepo.GetFirst(repo.WithByID(website.AppInstallID)) if err != nil { return err } @@ -157,7 +158,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback return err } case constant.Runtime: - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return err } @@ -229,7 +230,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName, excludes, switch website.Type { case constant.Deployment: - app, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) + app, err := appInstallRepo.GetFirst(repo.WithByID(website.AppInstallID)) if err != nil { return err } @@ -239,7 +240,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName, excludes, } t.LogSuccess(task.GetTaskName(app.Name, task.TaskBackup, task.TaskScopeApp)) case constant.Runtime: - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return err } @@ -280,18 +281,18 @@ func checkValidOfWebsite(oldWebsite, website *model.Website) error { return buserr.WithDetail(constant.ErrBackupMatch, fmt.Sprintf("oldName: %s, oldType: %v", oldWebsite.Alias, oldWebsite.Type), nil) } if oldWebsite.AppInstallID != 0 { - _, err := appInstallRepo.GetFirst(commonRepo.WithByID(oldWebsite.AppInstallID)) + _, err := appInstallRepo.GetFirst(repo.WithByID(oldWebsite.AppInstallID)) if err != nil { return buserr.WithDetail(constant.ErrBackupMatch, "app", nil) } } if oldWebsite.RuntimeID != 0 { - if _, err := runtimeRepo.GetFirst(commonRepo.WithByID(oldWebsite.RuntimeID)); err != nil { + if _, err := runtimeRepo.GetFirst(repo.WithByID(oldWebsite.RuntimeID)); err != nil { return buserr.WithDetail(constant.ErrBackupMatch, "runtime", nil) } } if oldWebsite.WebsiteSSLID != 0 { - if _, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(oldWebsite.WebsiteSSLID)); err != nil { + if _, err := websiteSSLRepo.GetFirst(repo.WithByID(oldWebsite.WebsiteSSLID)); err != nil { return buserr.WithDetail(constant.ErrBackupMatch, "ssl", nil) } } @@ -301,7 +302,7 @@ func checkValidOfWebsite(oldWebsite, website *model.Website) error { func recoverWebsiteDatabase(t *task.Task, dbID uint, dbType, tmpPath, websiteKey string) error { switch dbType { case constant.AppPostgresql: - db, err := postgresqlRepo.Get(commonRepo.WithByID(dbID)) + db, err := postgresqlRepo.Get(repo.WithByID(dbID)) if err != nil { return err } @@ -317,7 +318,7 @@ func recoverWebsiteDatabase(t *task.Task, dbID uint, dbType, tmpPath, websiteKey } t.LogSuccess(taskName) case constant.AppMysql, constant.AppMariaDB: - db, err := mysqlRepo.Get(commonRepo.WithByID(dbID)) + db, err := mysqlRepo.Get(repo.WithByID(dbID)) if err != nil { return err } diff --git a/agent/app/service/clam.go b/agent/app/service/clam.go index ae915ee3739c..815124d5e534 100644 --- a/agent/app/service/clam.go +++ b/agent/app/service/clam.go @@ -3,6 +3,7 @@ package service import ( "bufio" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "os/exec" "path" @@ -128,7 +129,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.WithByLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) + total, commands, err := clamRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info), repo.WithOrderRuleBy(req.OrderBy, req.Order)) if err != nil { return 0, nil, err } @@ -159,7 +160,7 @@ func (c *ClamService) SearchWithPage(req dto.SearchClamWithPage) (int64, interfa } func (c *ClamService) Create(req dto.ClamCreate) error { - clam, _ := clamRepo.Get(commonRepo.WithByName(req.Name)) + clam, _ := clamRepo.Get(repo.WithByName(req.Name)) if clam.ID != 0 { return constant.ErrRecordExist } @@ -184,7 +185,7 @@ func (c *ClamService) Create(req dto.ClamCreate) error { } func (c *ClamService) Update(req dto.ClamUpdate) error { - clam, _ := clamRepo.Get(commonRepo.WithByName(req.Name)) + clam, _ := clamRepo.Get(repo.WithByName(req.Name)) if clam.ID == 0 { return constant.ErrRecordNotFound } @@ -229,7 +230,7 @@ func (c *ClamService) Update(req dto.ClamUpdate) error { } func (c *ClamService) UpdateStatus(id uint, status string) error { - clam, _ := clamRepo.Get(commonRepo.WithByID(id)) + clam, _ := clamRepo.Get(repo.WithByID(id)) if clam.ID == 0 { return constant.ErrRecordNotFound } @@ -252,7 +253,7 @@ func (c *ClamService) UpdateStatus(id uint, status string) error { func (c *ClamService) Delete(req dto.ClamDelete) error { for _, id := range req.Ids { - clam, _ := clamRepo.Get(commonRepo.WithByID(id)) + clam, _ := clamRepo.Get(repo.WithByID(id)) if clam.ID == 0 { continue } @@ -262,7 +263,7 @@ func (c *ClamService) Delete(req dto.ClamDelete) error { if req.RemoveInfected { _ = os.RemoveAll(path.Join(clam.InfectedDir, "1panel-infected", clam.Name)) } - if err := clamRepo.Delete(commonRepo.WithByID(id)); err != nil { + if err := clamRepo.Delete(repo.WithByID(id)); err != nil { return err } } @@ -273,7 +274,7 @@ func (c *ClamService) HandleOnce(req dto.OperateByID) error { if cleaned := StopAllCronJob(true); cleaned { return buserr.New("ErrClamdscanNotFound") } - clam, _ := clamRepo.Get(commonRepo.WithByID(req.ID)) + clam, _ := clamRepo.Get(repo.WithByID(req.ID)) if clam.ID == 0 { return constant.ErrRecordNotFound } @@ -313,7 +314,7 @@ func (c *ClamService) HandleOnce(req dto.OperateByID) error { } func (c *ClamService) LoadRecords(req dto.ClamLogSearch) (int64, interface{}, error) { - clam, _ := clamRepo.Get(commonRepo.WithByID(req.ClamID)) + clam, _ := clamRepo.Get(repo.WithByID(req.ClamID)) if clam.ID == 0 { return 0, nil, constant.ErrRecordNotFound } @@ -376,7 +377,7 @@ func (c *ClamService) LoadRecordLog(req dto.ClamLogReq) (string, error) { } func (c *ClamService) CleanRecord(req dto.OperateByID) error { - clam, _ := clamRepo.Get(commonRepo.WithByID(req.ID)) + clam, _ := clamRepo.Get(repo.WithByID(req.ID)) if clam.ID == 0 { return constant.ErrRecordNotFound } @@ -490,7 +491,7 @@ func StopAllCronJob(withCheck bool) bool { return false } } - clams, _ := clamRepo.List(commonRepo.WithByStatus(constant.StatusEnable)) + clams, _ := clamRepo.List(repo.WithByStatus(constant.StatusEnable)) for i := 0; i < len(clams); i++ { global.Cron.Remove(cron.EntryID(clams[i].EntryID)) _ = clamRepo.Update(clams[i].ID, map[string]interface{}{"status": constant.StatusDisable, "entry_id": 0}) diff --git a/agent/app/service/compose_template.go b/agent/app/service/compose_template.go index 2cbf4e69a74d..f5c143d45f0f 100644 --- a/agent/app/service/compose_template.go +++ b/agent/app/service/compose_template.go @@ -2,6 +2,7 @@ package service import ( "github.com/1Panel-dev/1Panel/agent/app/dto" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/constant" "github.com/jinzhu/copier" "github.com/pkg/errors" @@ -38,7 +39,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.WithByLikeName(req.Info)) + total, composes, err := composeRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info)) var dtoComposeTemplates []dto.ComposeTemplateInfo for _, compose := range composes { var item dto.ComposeTemplateInfo @@ -51,7 +52,7 @@ func (u *ComposeTemplateService) SearchWithPage(req dto.SearchWithPage) (int64, } func (u *ComposeTemplateService) Create(composeDto dto.ComposeTemplateCreate) error { - compose, _ := composeRepo.Get(commonRepo.WithByName(composeDto.Name)) + compose, _ := composeRepo.Get(repo.WithByName(composeDto.Name)) if compose.ID != 0 { return constant.ErrRecordExist } @@ -66,13 +67,13 @@ func (u *ComposeTemplateService) Create(composeDto dto.ComposeTemplateCreate) er func (u *ComposeTemplateService) Delete(ids []uint) error { if len(ids) == 1 { - compose, _ := composeRepo.Get(commonRepo.WithByID(ids[0])) + compose, _ := composeRepo.Get(repo.WithByID(ids[0])) if compose.ID == 0 { return constant.ErrRecordNotFound } - return composeRepo.Delete(commonRepo.WithByID(ids[0])) + return composeRepo.Delete(repo.WithByID(ids[0])) } - return composeRepo.Delete(commonRepo.WithByIDs(ids)) + return composeRepo.Delete(repo.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 0df94e4ad5b8..28d57762e1a3 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/gin-gonic/gin" "io" "net/http" @@ -1009,7 +1010,7 @@ func (u *ContainerService) LoadContainerLogs(req dto.OperationWithNameAndType) s } } if len(containers) == 0 { - composeItem, _ := composeRepo.GetRecord(commonRepo.WithByName(req.Name)) + composeItem, _ := composeRepo.GetRecord(repo.WithByName(req.Name)) filePath = composeItem.Path } } diff --git a/agent/app/service/container_compose.go b/agent/app/service/container_compose.go index df08b625a385..3eafecfa0552 100644 --- a/agent/app/service/container_compose.go +++ b/agent/app/service/container_compose.go @@ -4,6 +4,7 @@ import ( "bufio" "errors" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "os/exec" "path" @@ -162,7 +163,7 @@ func (u *ContainerService) TestCompose(req dto.ComposeCreate) (bool, error) { if cmd.CheckIllegal(req.Path) { return false, buserr.New(constant.ErrCmdIllegal) } - composeItem, _ := composeRepo.GetRecord(commonRepo.WithByName(req.Name)) + composeItem, _ := composeRepo.GetRecord(repo.WithByName(req.Name)) if composeItem.ID != 0 { return false, constant.ErrRecordExist } @@ -217,7 +218,7 @@ func (u *ContainerService) CreateCompose(req dto.ComposeCreate) error { func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error { if len(req.Path) == 0 && req.Operation == "delete" { - _ = composeRepo.DeleteRecord(commonRepo.WithByName(req.Name)) + _ = composeRepo.DeleteRecord(repo.WithByName(req.Name)) return nil } if cmd.CheckIllegal(req.Path, req.Operation) { @@ -231,10 +232,10 @@ func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error { return errors.New(string(stdout)) } if req.WithFile { - _ = composeRepo.DeleteRecord(commonRepo.WithByName(req.Name)) + _ = composeRepo.DeleteRecord(repo.WithByName(req.Name)) _ = os.RemoveAll(path.Dir(req.Path)) } else { - composeItem, _ := composeRepo.GetRecord(commonRepo.WithByName(req.Name)) + composeItem, _ := composeRepo.GetRecord(repo.WithByName(req.Name)) if composeItem.Path == "" { upMap := make(map[string]interface{}) upMap["path"] = req.Path diff --git a/agent/app/service/cronjob.go b/agent/app/service/cronjob.go index b0893c747afe..408688daee7b 100644 --- a/agent/app/service/cronjob.go +++ b/agent/app/service/cronjob.go @@ -3,6 +3,7 @@ package service import ( "bufio" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strconv" @@ -41,7 +42,7 @@ func NewICronjobService() ICronjobService { } func (u *CronjobService) SearchWithPage(search dto.PageCronjob) (int64, interface{}, error) { - total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, commonRepo.WithByLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order)) + total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, repo.WithByLikeName(search.Info), repo.WithOrderRuleBy(search.OrderBy, search.Order)) var dtoCronjobs []dto.CronjobInfo for _, cronjob := range cronjobs { var item dto.CronjobInfo @@ -64,9 +65,9 @@ func (u *CronjobService) SearchRecords(search dto.SearchRecord) (int64, interfac total, records, err := cronjobRepo.PageRecords( search.Page, search.PageSize, - commonRepo.WithByStatus(search.Status), + repo.WithByStatus(search.Status), cronjobRepo.WithByJobID(search.CronjobID), - commonRepo.WithByDate(search.StartTime, search.EndTime)) + repo.WithByDate(search.StartTime, search.EndTime)) var dtoCronjobs []dto.Record for _, record := range records { var item dto.Record @@ -97,7 +98,7 @@ func (u *CronjobService) LoadNextHandle(specStr string) ([]string, error) { } func (u *CronjobService) LoadRecordLog(req dto.OperateByID) string { - record, err := cronjobRepo.GetRecord(commonRepo.WithByID(req.ID)) + record, err := cronjobRepo.GetRecord(repo.WithByID(req.ID)) if err != nil { return "" } @@ -112,7 +113,7 @@ func (u *CronjobService) LoadRecordLog(req dto.OperateByID) string { } func (u *CronjobService) CleanRecord(req dto.CronjobClean) error { - cronjob, err := cronjobRepo.Get(commonRepo.WithByID(req.CronjobID)) + cronjob, err := cronjobRepo.Get(repo.WithByID(req.CronjobID)) if err != nil { return err } @@ -149,7 +150,7 @@ func (u *CronjobService) CleanRecord(req dto.CronjobClean) error { } func (u *CronjobService) Download(req dto.CronjobDownload) (string, error) { - record, _ := cronjobRepo.GetRecord(commonRepo.WithByID(req.RecordID)) + record, _ := cronjobRepo.GetRecord(repo.WithByID(req.RecordID)) if record.ID == 0 { return "", constant.ErrRecordNotFound } @@ -175,7 +176,7 @@ func (u *CronjobService) Download(req dto.CronjobDownload) (string, error) { } func (u *CronjobService) HandleOnce(id uint) error { - cronjob, _ := cronjobRepo.Get(commonRepo.WithByID(id)) + cronjob, _ := cronjobRepo.Get(repo.WithByID(id)) if cronjob.ID == 0 { return constant.ErrRecordNotFound } @@ -184,7 +185,7 @@ func (u *CronjobService) HandleOnce(id uint) error { } func (u *CronjobService) Create(req dto.CronjobCreate) error { - cronjob, _ := cronjobRepo.Get(commonRepo.WithByName(req.Name)) + cronjob, _ := cronjobRepo.Get(repo.WithByName(req.Name)) if cronjob.ID != 0 { return constant.ErrRecordExist } @@ -231,7 +232,7 @@ func (u *CronjobService) StartJob(cronjob *model.Cronjob, isUpdate bool) (string func (u *CronjobService) Delete(req dto.CronjobBatchDelete) error { for _, id := range req.IDs { - cronjob, _ := cronjobRepo.Get(commonRepo.WithByID(id)) + cronjob, _ := cronjobRepo.Get(repo.WithByID(id)) if cronjob.ID == 0 { return errors.New("find cronjob in db failed") } @@ -244,7 +245,7 @@ func (u *CronjobService) Delete(req dto.CronjobBatchDelete) error { if err := u.CleanRecord(dto.CronjobClean{CronjobID: id, CleanData: req.CleanData, IsDelete: true}); err != nil { return err } - if err := cronjobRepo.Delete(commonRepo.WithByID(id)); err != nil { + if err := cronjobRepo.Delete(repo.WithByID(id)); err != nil { return err } } @@ -257,7 +258,7 @@ func (u *CronjobService) Update(id uint, req dto.CronjobUpdate) error { if err := copier.Copy(&cronjob, &req); err != nil { return errors.WithMessage(constant.ErrStructTransform, err.Error()) } - cronModel, err := cronjobRepo.Get(commonRepo.WithByID(id)) + cronModel, err := cronjobRepo.Get(repo.WithByID(id)) if err != nil { return constant.ErrRecordNotFound } @@ -304,7 +305,7 @@ func (u *CronjobService) Update(id uint, req dto.CronjobUpdate) error { } func (u *CronjobService) UpdateStatus(id uint, status string) error { - cronjob, _ := cronjobRepo.Get(commonRepo.WithByID(id)) + cronjob, _ := cronjobRepo.Get(repo.WithByID(id)) if cronjob.ID == 0 { return errors.WithMessage(constant.ErrRecordNotFound, "record not found") } diff --git a/agent/app/service/cronjob_backup.go b/agent/app/service/cronjob_backup.go index bb3b6a0114ab..14e0255eaa96 100644 --- a/agent/app/service/cronjob_backup.go +++ b/agent/app/service/cronjob_backup.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strconv" @@ -23,7 +24,7 @@ func (u *CronjobService) handleApp(cronjob model.Cronjob, startTime time.Time, t apps, _ = appInstallRepo.ListBy() } else { itemID, _ := strconv.Atoi(cronjob.AppID) - app, err := appInstallRepo.GetFirst(commonRepo.WithByID(uint(itemID))) + app, err := appInstallRepo.GetFirst(repo.WithByID(uint(itemID))) if err != nil { return err } @@ -300,7 +301,7 @@ func loadDbsForJob(cronjob model.Cronjob) []DatabaseHelper { } itemID, _ := strconv.Atoi(cronjob.DBName) if cronjob.DBType == "mysql" || cronjob.DBType == "mariadb" { - mysqlItem, _ := mysqlRepo.Get(commonRepo.WithByID(uint(itemID))) + mysqlItem, _ := mysqlRepo.Get(repo.WithByID(uint(itemID))) dbs = append(dbs, DatabaseHelper{ ID: mysqlItem.ID, DBType: cronjob.DBType, @@ -308,7 +309,7 @@ func loadDbsForJob(cronjob model.Cronjob) []DatabaseHelper { Name: mysqlItem.Name, }) } else { - pgItem, _ := postgresqlRepo.Get(commonRepo.WithByID(uint(itemID))) + pgItem, _ := postgresqlRepo.Get(repo.WithByID(uint(itemID))) dbs = append(dbs, DatabaseHelper{ ID: pgItem.ID, DBType: cronjob.DBType, @@ -326,7 +327,7 @@ func loadWebsForJob(cronjob model.Cronjob) []model.Website { return weblist } itemID, _ := strconv.Atoi(cronjob.Website) - webItem, _ := websiteRepo.GetFirst(commonRepo.WithByID(uint(itemID))) + webItem, _ := websiteRepo.GetFirst(repo.WithByID(uint(itemID))) if webItem.ID != 0 { weblist = append(weblist, webItem) } diff --git a/agent/app/service/cronjob_helper.go b/agent/app/service/cronjob_helper.go index 3a24e1fcbb03..6406a9a2dc8c 100644 --- a/agent/app/service/cronjob_helper.go +++ b/agent/app/service/cronjob_helper.go @@ -263,13 +263,13 @@ func (u *CronjobService) uploadCronjobBackFile(cronjob model.Cronjob, accountMap func (u *CronjobService) removeExpiredBackup(cronjob model.Cronjob, accountMap map[string]backupClientHelper, record model.BackupRecord) { var opts []repo.DBOption - opts = append(opts, commonRepo.WithByFrom("cronjob")) + opts = append(opts, repo.WithByFrom("cronjob")) opts = append(opts, backupRepo.WithByCronID(cronjob.ID)) - opts = append(opts, commonRepo.WithOrderBy("created_at desc")) + opts = append(opts, repo.WithOrderBy("created_at desc")) if record.ID != 0 { - opts = append(opts, commonRepo.WithByType(record.Type)) - opts = append(opts, commonRepo.WithByName(record.Name)) - opts = append(opts, commonRepo.WithByDetailName(record.DetailName)) + opts = append(opts, repo.WithByType(record.Type)) + opts = append(opts, repo.WithByName(record.Name)) + opts = append(opts, repo.WithByDetailName(record.DetailName)) } records, _ := backupRepo.ListRecord(opts...) if len(records) <= int(cronjob.RetainCopies) { @@ -283,7 +283,7 @@ func (u *CronjobService) removeExpiredBackup(cronjob model.Cronjob, accountMap m _, _ = accountMap[account].client.Delete(pathUtils.Join(accountMap[account].backupPath, "system_snapshot", records[i].FileName)) } } - _ = snapshotRepo.Delete(commonRepo.WithByName(strings.TrimSuffix(records[i].FileName, ".tar.gz"))) + _ = snapshotRepo.Delete(repo.WithByName(strings.TrimSuffix(records[i].FileName, ".tar.gz"))) } else { for _, account := range accounts { if len(account) != 0 { @@ -291,12 +291,12 @@ func (u *CronjobService) removeExpiredBackup(cronjob model.Cronjob, accountMap m } } } - _ = backupRepo.DeleteRecord(context.Background(), commonRepo.WithByID(records[i].ID)) + _ = backupRepo.DeleteRecord(context.Background(), repo.WithByID(records[i].ID)) } } func (u *CronjobService) removeExpiredLog(cronjob model.Cronjob) { - records, _ := cronjobRepo.ListRecord(cronjobRepo.WithByJobID(int(cronjob.ID)), commonRepo.WithOrderBy("created_at desc")) + records, _ := cronjobRepo.ListRecord(cronjobRepo.WithByJobID(int(cronjob.ID)), repo.WithOrderBy("created_at desc")) if len(records) <= int(cronjob.RetainCopies) { return } @@ -307,7 +307,7 @@ func (u *CronjobService) removeExpiredLog(cronjob model.Cronjob) { _ = os.Remove(file) } } - _ = cronjobRepo.DeleteRecord(commonRepo.WithByID(uint(records[i].ID))) + _ = cronjobRepo.DeleteRecord(repo.WithByID(records[i].ID)) _ = os.Remove(records[i].Records) } } diff --git a/agent/app/service/dashboard.go b/agent/app/service/dashboard.go index ecd5100628be..75585d68c60e 100644 --- a/agent/app/service/dashboard.go +++ b/agent/app/service/dashboard.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" network "net" "os" "sort" @@ -62,7 +63,7 @@ func (u *DashboardService) Sync(req dto.SyncFromMaster) error { if launcher.ID == 0 { return constant.ErrRecordNotFound } - return launcherRepo.Delete(commonRepo.WithByID(launcher.ID)) + return launcherRepo.Delete(repo.WithByID(launcher.ID)) case "update": if launcher.ID == 0 { return constant.ErrRecordNotFound diff --git a/agent/app/service/database.go b/agent/app/service/database.go index 7d380e542993..26598c2c79fe 100644 --- a/agent/app/service/database.go +++ b/agent/app/service/database.go @@ -3,6 +3,7 @@ package service import ( "context" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" @@ -42,8 +43,8 @@ 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.WithByLikeName(search.Info), - commonRepo.WithOrderRuleBy(search.OrderBy, search.Order), + repo.WithByLikeName(search.Info), + repo.WithOrderRuleBy(search.OrderBy, search.Order), databaseRepo.WithoutByFrom("local"), ) var datas []dto.DatabaseInfo @@ -59,7 +60,7 @@ func (u *DatabaseService) SearchWithPage(search dto.DatabaseSearch) (int64, inte func (u *DatabaseService) Get(name string) (dto.DatabaseInfo, error) { var data dto.DatabaseInfo - remote, err := databaseRepo.Get(commonRepo.WithByName(name)) + remote, err := databaseRepo.Get(repo.WithByName(name)) if err != nil { return data, err } @@ -156,7 +157,7 @@ func (u *DatabaseService) CheckDatabase(req dto.DatabaseCreate) bool { } func (u *DatabaseService) Create(req dto.DatabaseCreate) error { - db, _ := databaseRepo.Get(commonRepo.WithByName(req.Name)) + db, _ := databaseRepo.Get(repo.WithByName(req.Name)) if db.ID != 0 { if db.From == "local" { return buserr.New(constant.ErrLocalExist) @@ -215,9 +216,9 @@ func (u *DatabaseService) Create(req dto.DatabaseCreate) error { func (u *DatabaseService) DeleteCheck(id uint) ([]string, error) { var appInUsed []string - apps, _ := appInstallResourceRepo.GetBy(commonRepo.WithByFrom("remote"), appInstallResourceRepo.WithLinkId(id)) + apps, _ := appInstallResourceRepo.GetBy(repo.WithByFrom("remote"), appInstallResourceRepo.WithLinkId(id)) for _, app := range apps { - appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId)) + appInstall, _ := appInstallRepo.GetFirst(repo.WithByID(app.AppInstallId)) if appInstall.ID != 0 { appInUsed = append(appInUsed, appInstall.Name) } @@ -227,7 +228,7 @@ func (u *DatabaseService) DeleteCheck(id uint) ([]string, error) { } func (u *DatabaseService) Delete(req dto.DatabaseDelete) error { - db, _ := databaseRepo.Get(commonRepo.WithByID(req.ID)) + db, _ := databaseRepo.Get(repo.WithByID(req.ID)) if db.ID == 0 { return constant.ErrRecordNotFound } @@ -241,11 +242,11 @@ func (u *DatabaseService) Delete(req dto.DatabaseDelete) error { if _, err := os.Stat(backupDir); err == nil { _ = os.RemoveAll(backupDir) } - _ = backupRepo.DeleteRecord(context.Background(), commonRepo.WithByType(db.Type), commonRepo.WithByName(db.Name)) + _ = backupRepo.DeleteRecord(context.Background(), repo.WithByType(db.Type), repo.WithByName(db.Name)) global.LOG.Infof("delete database %s-%s backups successful", db.Type, db.Name) } - if err := databaseRepo.Delete(context.Background(), commonRepo.WithByID(req.ID)); err != nil && !req.ForceDelete { + if err := databaseRepo.Delete(context.Background(), repo.WithByID(req.ID)); err != nil && !req.ForceDelete { return err } if db.From != "local" { diff --git a/agent/app/service/database_mysql.go b/agent/app/service/database_mysql.go index fc86d4016c4b..16fff8cce001 100644 --- a/agent/app/service/database_mysql.go +++ b/agent/app/service/database_mysql.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "os/exec" "path" @@ -55,8 +56,8 @@ 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.WithByLikeName(search.Info), - commonRepo.WithOrderRuleBy(search.OrderBy, search.Order), + repo.WithByLikeName(search.Info), + repo.WithOrderRuleBy(search.OrderBy, search.Order), ) var dtoMysqls []dto.MysqlDBInfo for _, mysql := range mysqls { @@ -101,7 +102,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), commonRepo.WithByFrom(req.From)) + mysql, _ := mysqlRepo.Get(repo.WithByName(req.Name), mysqlRepo.WithByMysqlName(req.Database), repo.WithByFrom(req.From)) if mysql.ID != 0 { return nil, constant.ErrRecordExist } @@ -145,7 +146,7 @@ func (u *MysqlService) BindUser(req dto.BindUser) error { return buserr.New(constant.ErrCmdIllegal) } - dbItem, err := mysqlRepo.Get(mysqlRepo.WithByMysqlName(req.Database), commonRepo.WithByName(req.DB)) + dbItem, err := mysqlRepo.Get(mysqlRepo.WithByMysqlName(req.Database), repo.WithByName(req.DB)) if err != nil { return err } @@ -229,7 +230,7 @@ func (u *MysqlService) UpdateDescription(req dto.UpdateDescription) error { func (u *MysqlService) DeleteCheck(req dto.MysqlDBDeleteCheck) ([]string, error) { var appInUsed []string - db, err := mysqlRepo.Get(commonRepo.WithByID(req.ID)) + db, err := mysqlRepo.Get(repo.WithByID(req.ID)) if err != nil { return appInUsed, err } @@ -241,7 +242,7 @@ func (u *MysqlService) DeleteCheck(req dto.MysqlDBDeleteCheck) ([]string, error) } apps, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(app.ID), appInstallResourceRepo.WithResourceId(db.ID)) for _, app := range apps { - appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId)) + appInstall, _ := appInstallRepo.GetFirst(repo.WithByID(app.AppInstallId)) if appInstall.ID != 0 { appInUsed = append(appInUsed, appInstall.Name) } @@ -249,7 +250,7 @@ func (u *MysqlService) DeleteCheck(req dto.MysqlDBDeleteCheck) ([]string, error) } else { apps, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithResourceId(db.ID), appRepo.WithKey(req.Type)) for _, app := range apps { - appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId)) + appInstall, _ := appInstallRepo.GetFirst(repo.WithByID(app.AppInstallId)) if appInstall.ID != 0 { appInUsed = append(appInUsed, appInstall.Name) } @@ -260,7 +261,7 @@ func (u *MysqlService) DeleteCheck(req dto.MysqlDBDeleteCheck) ([]string, error) } func (u *MysqlService) Delete(ctx context.Context, req dto.MysqlDBDelete) error { - db, err := mysqlRepo.Get(commonRepo.WithByID(req.ID)) + db, err := mysqlRepo.Get(repo.WithByID(req.ID)) if err != nil && !req.ForceDelete { return err } @@ -288,11 +289,11 @@ 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), commonRepo.WithByDetailName(db.Name)) + _ = backupRepo.DeleteRecord(ctx, repo.WithByType(req.Type), repo.WithByName(req.Database), repo.WithByDetailName(db.Name)) global.LOG.Infof("delete database %s-%s backups successful", req.Database, db.Name) } - _ = mysqlRepo.Delete(ctx, commonRepo.WithByID(db.ID)) + _ = mysqlRepo.Delete(ctx, repo.WithByID(db.ID)) return nil } @@ -314,7 +315,7 @@ func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { passwordInfo.Version = version if req.ID != 0 { - mysqlData, err = mysqlRepo.Get(commonRepo.WithByID(req.ID)) + mysqlData, err = mysqlRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } @@ -340,11 +341,11 @@ func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { appRess, _ = appInstallResourceRepo.GetBy(appInstallResourceRepo.WithResourceId(mysqlData.ID)) } for _, appRes := range appRess { - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(appRes.AppInstallId)) + appInstall, err := appInstallRepo.GetFirst(repo.WithByID(appRes.AppInstallId)) if err != nil { return err } - appModel, err := appRepo.GetFirst(commonRepo.WithByID(appInstall.AppId)) + appModel, err := appRepo.GetFirst(repo.WithByID(appInstall.AppId)) if err != nil { return err } @@ -367,7 +368,7 @@ func (u *MysqlService) ChangePassword(req dto.ChangeDBInfo) error { return err } if req.From == "local" { - remote, err := databaseRepo.Get(commonRepo.WithByName(req.Database)) + remote, err := databaseRepo.Get(repo.WithByName(req.Database)) if err != nil { return err } @@ -398,7 +399,7 @@ func (u *MysqlService) ChangeAccess(req dto.ChangeDBInfo) error { accessInfo.Version = version if req.ID != 0 { - mysqlData, err = mysqlRepo.Get(commonRepo.WithByID(req.ID)) + mysqlData, err = mysqlRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } @@ -624,7 +625,7 @@ func LoadMysqlClientByFrom(database string) (mysql.MysqlClient, string, error) { ) dbInfo.Timeout = 300 - databaseItem, err := databaseRepo.Get(commonRepo.WithByName(database)) + databaseItem, err := databaseRepo.Get(repo.WithByName(database)) if err != nil { return nil, "", err } diff --git a/agent/app/service/database_postgresql.go b/agent/app/service/database_postgresql.go index 68697c709ac9..ab790d886f48 100644 --- a/agent/app/service/database_postgresql.go +++ b/agent/app/service/database_postgresql.go @@ -3,6 +3,7 @@ package service import ( "context" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strings" @@ -43,8 +44,8 @@ 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.WithByLikeName(search.Info), - commonRepo.WithOrderRuleBy(search.OrderBy, search.Order), + repo.WithByLikeName(search.Info), + repo.WithOrderRuleBy(search.OrderBy, search.Order), ) var dtoPostgresqls []dto.PostgresqlDBInfo for _, pg := range postgresqls { @@ -88,7 +89,7 @@ func (u *PostgresqlService) BindUser(req dto.PostgresqlBindUser) error { if cmd.CheckIllegal(req.Name, req.Username, req.Password) { return buserr.New(constant.ErrCmdIllegal) } - dbItem, err := postgresqlRepo.Get(postgresqlRepo.WithByPostgresqlName(req.Database), commonRepo.WithByName(req.Name)) + dbItem, err := postgresqlRepo.Get(postgresqlRepo.WithByPostgresqlName(req.Database), repo.WithByName(req.Name)) if err != nil { return err } @@ -125,7 +126,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), commonRepo.WithByFrom(req.From)) + pgsql, _ := postgresqlRepo.Get(repo.WithByName(req.Name), postgresqlRepo.WithByPostgresqlName(req.Database), repo.WithByFrom(req.From)) if pgsql.ID != 0 { return nil, constant.ErrRecordExist } @@ -171,7 +172,7 @@ func LoadPostgresqlClientByFrom(database string) (postgresql.PostgresqlClient, e ) dbInfo.Timeout = 300 - databaseItem, err := databaseRepo.Get(commonRepo.WithByName(database)) + databaseItem, err := databaseRepo.Get(repo.WithByName(database)) if err != nil { return nil, err } @@ -251,7 +252,7 @@ func (u *PostgresqlService) UpdateDescription(req dto.UpdateDescription) error { func (u *PostgresqlService) DeleteCheck(req dto.PostgresqlDBDeleteCheck) ([]string, error) { var appInUsed []string - db, err := postgresqlRepo.Get(commonRepo.WithByID(req.ID)) + db, err := postgresqlRepo.Get(repo.WithByID(req.ID)) if err != nil { return appInUsed, err } @@ -263,7 +264,7 @@ func (u *PostgresqlService) DeleteCheck(req dto.PostgresqlDBDeleteCheck) ([]stri } apps, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(app.ID), appInstallResourceRepo.WithResourceId(db.ID)) for _, app := range apps { - appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId)) + appInstall, _ := appInstallRepo.GetFirst(repo.WithByID(app.AppInstallId)) if appInstall.ID != 0 { appInUsed = append(appInUsed, appInstall.Name) } @@ -271,7 +272,7 @@ func (u *PostgresqlService) DeleteCheck(req dto.PostgresqlDBDeleteCheck) ([]stri } else { apps, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithResourceId(db.ID), appRepo.WithKey(req.Type)) for _, app := range apps { - appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId)) + appInstall, _ := appInstallRepo.GetFirst(repo.WithByID(app.AppInstallId)) if appInstall.ID != 0 { appInUsed = append(appInUsed, appInstall.Name) } @@ -282,7 +283,7 @@ func (u *PostgresqlService) DeleteCheck(req dto.PostgresqlDBDeleteCheck) ([]stri } func (u *PostgresqlService) Delete(ctx context.Context, req dto.PostgresqlDBDelete) error { - db, err := postgresqlRepo.Get(commonRepo.WithByID(req.ID)) + db, err := postgresqlRepo.Get(repo.WithByID(req.ID)) if err != nil && !req.ForceDelete { return err } @@ -309,11 +310,11 @@ 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), commonRepo.WithByDetailName(db.Name)) + _ = backupRepo.DeleteRecord(ctx, repo.WithByType(req.Type), repo.WithByName(req.Database), repo.WithByDetailName(db.Name)) global.LOG.Infof("delete database %s-%s backups successful", req.Database, db.Name) } - _ = postgresqlRepo.Delete(ctx, commonRepo.WithByID(db.ID)) + _ = postgresqlRepo.Delete(ctx, repo.WithByID(db.ID)) return nil } @@ -321,7 +322,7 @@ func (u *PostgresqlService) ChangePrivileges(req dto.PostgresqlPrivileges) error if cmd.CheckIllegal(req.Database, req.Username) { return buserr.New(constant.ErrCmdIllegal) } - dbItem, err := postgresqlRepo.Get(postgresqlRepo.WithByPostgresqlName(req.Database), commonRepo.WithByName(req.Name)) + dbItem, err := postgresqlRepo.Get(postgresqlRepo.WithByPostgresqlName(req.Database), repo.WithByName(req.Name)) if err != nil { return err } @@ -359,13 +360,13 @@ func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { passwordInfo.Timeout = 300 if req.ID != 0 { - postgresqlData, err = postgresqlRepo.Get(commonRepo.WithByID(req.ID)) + postgresqlData, err = postgresqlRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } passwordInfo.Username = postgresqlData.Username } else { - dbItem, err := databaseRepo.Get(commonRepo.WithByType(req.Type), commonRepo.WithByFrom(req.From)) + dbItem, err := databaseRepo.Get(repo.WithByType(req.Type), repo.WithByFrom(req.From)) if err != nil { return err } @@ -387,11 +388,11 @@ func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { appRess, _ = appInstallResourceRepo.GetBy(appInstallResourceRepo.WithResourceId(postgresqlData.ID)) } for _, appRes := range appRess { - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(appRes.AppInstallId)) + appInstall, err := appInstallRepo.GetFirst(repo.WithByID(appRes.AppInstallId)) if err != nil { return err } - appModel, err := appRepo.GetFirst(commonRepo.WithByID(appInstall.AppId)) + appModel, err := appRepo.GetFirst(repo.WithByID(appInstall.AppId)) if err != nil { return err } @@ -414,7 +415,7 @@ func (u *PostgresqlService) ChangePassword(req dto.ChangeDBInfo) error { return err } if req.From == "local" { - remote, err := databaseRepo.Get(commonRepo.WithByName(req.Database)) + remote, err := databaseRepo.Get(repo.WithByName(req.Database)) if err != nil { return err } diff --git a/agent/app/service/database_redis.go b/agent/app/service/database_redis.go index 0ff38c33c877..918dec5ec549 100644 --- a/agent/app/service/database_redis.go +++ b/agent/app/service/database_redis.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "os/exec" "strings" @@ -88,7 +89,7 @@ func (u *RedisService) ChangePassword(req dto.ChangeRedisPass) error { if err := updateInstallInfoInDB("redis", req.Database, "password", req.Value); err != nil { return err } - remote, err := databaseRepo.Get(commonRepo.WithByName(req.Database)) + remote, err := databaseRepo.Get(repo.WithByName(req.Database)) if err != nil { return err } diff --git a/agent/app/service/entry.go b/agent/app/service/entry.go index 9d5ec7f5ac36..8cb7d0a0e21d 100644 --- a/agent/app/service/entry.go +++ b/agent/app/service/entry.go @@ -3,8 +3,6 @@ package service import "github.com/1Panel-dev/1Panel/agent/app/repo" var ( - commonRepo = repo.NewCommonRepo() - appRepo = repo.NewIAppRepo() appTagRepo = repo.NewIAppTagRepo() appDetailRepo = repo.NewIAppDetailRepo() diff --git a/agent/app/service/favorite.go b/agent/app/service/favorite.go index 2a44ee31b87c..95c1faa0f56b 100644 --- a/agent/app/service/favorite.go +++ b/agent/app/service/favorite.go @@ -5,6 +5,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto/response" "github.com/1Panel-dev/1Panel/agent/app/model" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/utils/files" @@ -76,7 +77,7 @@ func (f *FavoriteService) Create(req request.FavoriteCreate) (*model.Favorite, e } func (f *FavoriteService) Delete(id uint) error { - if err := favoriteRepo.Delete(commonRepo.WithByID(id)); err != nil { + if err := favoriteRepo.Delete(repo.WithByID(id)); err != nil { return err } return nil diff --git a/agent/app/service/file.go b/agent/app/service/file.go index eb5f1822c7d3..0c749aa8d29a 100644 --- a/agent/app/service/file.go +++ b/agent/app/service/file.go @@ -415,19 +415,19 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi logFilePath := "" switch req.Type { case constant.TypeWebsite: - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } logFilePath = GetSitePath(website, req.Name) case constant.TypePhp: - php, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + php, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } logFilePath = php.GetLogPath() case constant.TypeSSL: - ssl, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(req.ID)) + ssl, err := websiteSSLRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } @@ -454,7 +454,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi if req.TaskID != "" { opts = append(opts, taskRepo.WithByID(req.TaskID)) } else { - opts = append(opts, commonRepo.WithByType(req.TaskType), taskRepo.WithOperate(req.TaskOperate), taskRepo.WithResourceID(req.ID)) + opts = append(opts, repo.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/ftp.go b/agent/app/service/ftp.go index 889c97ff4c0b..6d0cd6e34310 100644 --- a/agent/app/service/ftp.go +++ b/agent/app/service/ftp.go @@ -1,6 +1,7 @@ package service import ( + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "sort" @@ -74,7 +75,7 @@ func (u *FtpService) Operate(operation string) error { } func (f *FtpService) SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) { - total, lists, err := ftpRepo.Page(req.Page, req.PageSize, ftpRepo.WithLikeUser(req.Info), commonRepo.WithOrderBy("created_at desc")) + total, lists, err := ftpRepo.Page(req.Page, req.PageSize, ftpRepo.WithLikeUser(req.Info), repo.WithOrderBy("created_at desc")) if err != nil { return 0, nil, err } @@ -171,12 +172,12 @@ func (f *FtpService) Delete(req dto.BatchDeleteReq) error { return err } for _, id := range req.Ids { - ftpItem, err := ftpRepo.Get(commonRepo.WithByID(id)) + ftpItem, err := ftpRepo.Get(repo.WithByID(id)) if err != nil { return err } _ = client.UserDel(ftpItem.User) - _ = ftpRepo.Delete(commonRepo.WithByID(id)) + _ = ftpRepo.Delete(repo.WithByID(id)) } return nil } @@ -196,7 +197,7 @@ func (f *FtpService) Update(req dto.FtpUpdate) error { if err != nil { return err } - ftpItem, _ := ftpRepo.Get(commonRepo.WithByID(req.ID)) + ftpItem, _ := ftpRepo.Get(repo.WithByID(req.ID)) if ftpItem.ID == 0 { return constant.ErrRecordNotFound } diff --git a/agent/app/service/image.go b/agent/app/service/image.go index 2ae44f986f4d..05a4d4ae9f2c 100644 --- a/agent/app/service/image.go +++ b/agent/app/service/image.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "io" "os" "path" @@ -244,7 +245,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) error { options.RegistryAuth = authStr } } else { - repo, err := imageRepoRepo.Get(commonRepo.WithByID(req.RepoID)) + repo, err := imageRepoRepo.Get(repo.WithByID(req.RepoID)) taskItem.LogWithStatus(i18n.GetMsgByKey("ImageRepoAuthFromDB"), err) if err != nil { return err @@ -355,19 +356,19 @@ func (u *ImageService) ImagePush(req dto.ImagePush) error { go func() { options := image.PushOptions{All: true} - var repo model.ImageRepo + var imageRepo model.ImageRepo newName := "" taskItem.AddSubTask(i18n.GetMsgByKey("ImagePush"), func(t *task.Task) error { - repo, err = imageRepoRepo.Get(commonRepo.WithByID(req.RepoID)) - newName = fmt.Sprintf("%s/%s", repo.DownloadUrl, req.Name) + imageRepo, err = imageRepoRepo.Get(repo.WithByID(req.RepoID)) + newName = fmt.Sprintf("%s/%s", imageRepo.DownloadUrl, req.Name) taskItem.LogWithStatus(i18n.GetMsgByKey("ImageRepoAuthFromDB"), err) if err != nil { return err } options = image.PushOptions{All: true} authConfig := registry.AuthConfig{ - Username: repo.Username, - Password: repo.Password, + Username: imageRepo.Username, + Password: imageRepo.Password, } encodedJSON, _ := json.Marshal(authConfig) authStr := base64.URLEncoding.EncodeToString(encodedJSON) diff --git a/agent/app/service/image_repo.go b/agent/app/service/image_repo.go index 406650dc73ca..fbdcc6461d4a 100644 --- a/agent/app/service/image_repo.go +++ b/agent/app/service/image_repo.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "strings" "time" @@ -34,7 +35,7 @@ func NewIImageRepoService() IImageRepoService { } func (u *ImageRepoService) Page(req dto.SearchWithPage) (int64, interface{}, error) { - total, ops, err := imageRepoRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info), commonRepo.WithOrderBy("created_at desc")) + total, ops, err := imageRepoRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info), repo.WithOrderBy("created_at desc")) var dtoOps []dto.ImageRepoInfo for _, op := range ops { var item dto.ImageRepoInfo @@ -47,7 +48,7 @@ func (u *ImageRepoService) Page(req dto.SearchWithPage) (int64, interface{}, err } func (u *ImageRepoService) Login(req dto.OperateByID) error { - repo, err := imageRepoRepo.Get(commonRepo.WithByID(req.ID)) + repo, err := imageRepoRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } @@ -62,7 +63,7 @@ func (u *ImageRepoService) Login(req dto.OperateByID) error { } func (u *ImageRepoService) List() ([]dto.ImageRepoOption, error) { - ops, err := imageRepoRepo.List(commonRepo.WithOrderBy("created_at desc")) + ops, err := imageRepoRepo.List(repo.WithOrderBy("created_at desc")) var dtoOps []dto.ImageRepoOption for _, op := range ops { if op.Status == constant.StatusSuccess { @@ -80,7 +81,7 @@ func (u *ImageRepoService) Create(req dto.ImageRepoCreate) error { if cmd.CheckIllegal(req.Username, req.Password, req.DownloadUrl) { return buserr.New(constant.ErrCmdIllegal) } - imageRepo, _ := imageRepoRepo.Get(commonRepo.WithByName(req.Name)) + imageRepo, _ := imageRepoRepo.Get(repo.WithByName(req.Name)) if imageRepo.ID != 0 { return constant.ErrRecordExist } @@ -136,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.WithByIDs(req.Ids)); err != nil { + if err := imageRepoRepo.Delete(repo.WithByIDs(req.Ids)); err != nil { return err } return nil @@ -149,7 +150,7 @@ func (u *ImageRepoService) Update(req dto.ImageRepoUpdate) error { if cmd.CheckIllegal(req.Username, req.Password, req.DownloadUrl) { return buserr.New(constant.ErrCmdIllegal) } - repo, err := imageRepoRepo.Get(commonRepo.WithByID(req.ID)) + repo, err := imageRepoRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } diff --git a/agent/app/service/monitor.go b/agent/app/service/monitor.go index 9a804f5b2fc1..69fb2f40795c 100644 --- a/agent/app/service/monitor.go +++ b/agent/app/service/monitor.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "strconv" "time" @@ -52,7 +53,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa var data []dto.MonitorData if req.Param == "all" || req.Param == "cpu" || req.Param == "memory" || req.Param == "load" { - bases, err := monitorRepo.GetBase(commonRepo.WithByCreatedAt(req.StartTime, req.EndTime)) + bases, err := monitorRepo.GetBase(repo.WithByCreatedAt(req.StartTime, req.EndTime)) if err != nil { return nil, err } @@ -66,7 +67,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa data = append(data, itemData) } if req.Param == "all" || req.Param == "io" { - bases, err := monitorRepo.GetIO(commonRepo.WithByCreatedAt(req.StartTime, req.EndTime)) + bases, err := monitorRepo.GetIO(repo.WithByCreatedAt(req.StartTime, req.EndTime)) if err != nil { return nil, err } @@ -80,7 +81,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa data = append(data, itemData) } if req.Param == "all" || req.Param == "network" { - bases, err := monitorRepo.GetIO(commonRepo.WithByName(req.Info), commonRepo.WithByCreatedAt(req.StartTime, req.EndTime)) + bases, err := monitorRepo.GetIO(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime)) if err != nil { return nil, err } diff --git a/agent/app/service/php_extensions.go b/agent/app/service/php_extensions.go index a7686da5e8ba..eccc32dfe7ce 100644 --- a/agent/app/service/php_extensions.go +++ b/agent/app/service/php_extensions.go @@ -4,6 +4,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto/response" "github.com/1Panel-dev/1Panel/agent/app/model" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/constant" ) @@ -61,7 +62,7 @@ func (p PHPExtensionsService) List() ([]response.PHPExtensionsDTO, error) { } func (p PHPExtensionsService) Create(req request.PHPExtensionsCreate) error { - exist, _ := phpExtensionsRepo.GetFirst(commonRepo.WithByName(req.Name)) + exist, _ := phpExtensionsRepo.GetFirst(repo.WithByName(req.Name)) if exist.ID > 0 { return buserr.New(constant.ErrNameIsExist) } @@ -73,7 +74,7 @@ func (p PHPExtensionsService) Create(req request.PHPExtensionsCreate) error { } func (p PHPExtensionsService) Update(req request.PHPExtensionsUpdate) error { - exist, err := phpExtensionsRepo.GetFirst(commonRepo.WithByID(req.ID)) + exist, err := phpExtensionsRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -82,5 +83,5 @@ func (p PHPExtensionsService) Update(req request.PHPExtensionsUpdate) error { } func (p PHPExtensionsService) Delete(req request.PHPExtensionsDelete) error { - return phpExtensionsRepo.DeleteBy(commonRepo.WithByID(req.ID)) + return phpExtensionsRepo.DeleteBy(repo.WithByID(req.ID)) } diff --git a/agent/app/service/runtime.go b/agent/app/service/runtime.go index dbd945c7202f..11598edd40d3 100644 --- a/agent/app/service/runtime.go +++ b/agent/app/service/runtime.go @@ -75,10 +75,10 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e opts []repo.DBOption ) if create.Name != "" { - opts = append(opts, commonRepo.WithByName(create.Name)) + opts = append(opts, repo.WithByName(create.Name)) } if create.Type != "" { - opts = append(opts, commonRepo.WithByType(create.Type)) + opts = append(opts, repo.WithByType(create.Type)) } exist, _ := runtimeRepo.GetFirst(opts...) if exist != nil { @@ -134,11 +134,11 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e return nil, err } - appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(create.AppDetailID)) + appDetail, err := appDetailRepo.GetFirst(repo.WithByID(create.AppDetailID)) if err != nil { return nil, err } - app, err := appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId)) + app, err := appRepo.GetFirst(repo.WithByID(appDetail.AppId)) if err != nil { return nil, err } @@ -183,13 +183,13 @@ func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.Runt res []response.RuntimeDTO ) if req.Name != "" { - opts = append(opts, commonRepo.WithByLikeName(req.Name)) + opts = append(opts, repo.WithByLikeName(req.Name)) } if req.Status != "" { opts = append(opts, runtimeRepo.WithStatus(req.Status)) } if req.Type != "" { - opts = append(opts, commonRepo.WithByType(req.Type)) + opts = append(opts, repo.WithByType(req.Type)) } total, runtimes, err := runtimeRepo.Page(req.Page, req.PageSize, opts...) if err != nil { @@ -223,7 +223,7 @@ func (r *RuntimeService) DeleteCheck(runTimeId uint) ([]dto.AppResource, error) } func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(runtimeDelete.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(runtimeDelete.ID)) if err != nil { return err } @@ -232,7 +232,7 @@ func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error { return buserr.New(constant.ErrDelWithWebsite) } if runtime.Resource != constant.ResourceAppstore { - return runtimeRepo.DeleteBy(commonRepo.WithByID(runtimeDelete.ID)) + return runtimeRepo.DeleteBy(repo.WithByID(runtimeDelete.ID)) } projectDir := runtime.GetPath() if out, err := compose.Down(runtime.GetComposePath()); err != nil && !runtimeDelete.ForceDelete { @@ -260,11 +260,11 @@ func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error { if err := files.NewFileOp().DeleteDir(projectDir); err != nil && !runtimeDelete.ForceDelete { return err } - return runtimeRepo.DeleteBy(commonRepo.WithByID(runtimeDelete.ID)) + return runtimeRepo.DeleteBy(repo.WithByID(runtimeDelete.ID)) } func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(id)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -273,7 +273,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) { if runtime.Resource == constant.ResourceLocal { return &res, nil } - appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(runtime.AppDetailID)) + appDetail, err := appDetailRepo.GetFirst(repo.WithByID(runtime.AppDetailID)) if err != nil { return nil, err } @@ -426,7 +426,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) { } func (r *RuntimeService) Update(req request.RuntimeUpdate) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -456,11 +456,11 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error { } } - appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(runtime.AppDetailID)) + appDetail, err := appDetailRepo.GetFirst(repo.WithByID(runtime.AppDetailID)) if err != nil { return err } - app, err := appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId)) + app, err := appRepo.GetFirst(repo.WithByID(appDetail.AppId)) if err != nil { return err } @@ -561,7 +561,7 @@ func (r *RuntimeService) GetNodePackageRunScript(req request.NodePackageReq) ([] } func (r *RuntimeService) OperateRuntime(req request.RuntimeOperate) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -597,7 +597,7 @@ func (r *RuntimeService) OperateRuntime(req request.RuntimeOperate) error { } func (r *RuntimeService) GetNodeModules(req request.NodeModuleReq) ([]response.NodeModule, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } @@ -630,7 +630,7 @@ func (r *RuntimeService) GetNodeModules(req request.NodeModuleReq) ([]response.N } func (r *RuntimeService) OperateNodeModules(req request.NodeModuleOperateReq) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -693,7 +693,7 @@ func (r *RuntimeService) SyncRuntimeStatus() error { func (r *RuntimeService) GetPHPExtensions(runtimeID uint) (response.PHPExtensionRes, error) { var res response.PHPExtensionRes - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(runtimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(runtimeID)) if err != nil { return res, err } @@ -733,7 +733,7 @@ func (r *RuntimeService) GetPHPExtensions(runtimeID uint) (response.PHPExtension } func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -814,7 +814,7 @@ func (r *RuntimeService) InstallPHPExtension(req request.PHPExtensionInstallReq) } func (r *RuntimeService) UnInstallPHPExtension(req request.PHPExtensionInstallReq) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -828,7 +828,7 @@ func (r *RuntimeService) UnInstallPHPExtension(req request.PHPExtensionInstallRe } func (r *RuntimeService) GetPHPConfig(id uint) (*response.PHPConfig, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(id)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -878,7 +878,7 @@ func (r *RuntimeService) GetPHPConfig(id uint) (*response.PHPConfig, error) { } func (r *RuntimeService) UpdatePHPConfig(req request.PHPConfigUpdate) (err error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -943,7 +943,7 @@ func (r *RuntimeService) UpdatePHPConfig(req request.PHPConfigUpdate) (err error } func (r *RuntimeService) GetPHPConfigFile(req request.PHPFileReq) (*response.FileInfo, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } @@ -965,7 +965,7 @@ func (r *RuntimeService) GetPHPConfigFile(req request.PHPFileReq) (*response.Fil } func (r *RuntimeService) UpdatePHPConfigFile(req request.PHPFileUpdate) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -985,7 +985,7 @@ func (r *RuntimeService) UpdatePHPConfigFile(req request.PHPFileUpdate) error { } func (r *RuntimeService) UpdateFPMConfig(req request.FPMConfig) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -1023,7 +1023,7 @@ var PmKeys = map[string]struct { } func (r *RuntimeService) GetFPMConfig(id uint) (*request.FPMConfig, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(id)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -1046,7 +1046,7 @@ func (r *RuntimeService) GetFPMConfig(id uint) (*request.FPMConfig, error) { } func (r *RuntimeService) GetSupervisorProcess(id uint) ([]response.SupervisorProcessConfig, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(id)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -1055,7 +1055,7 @@ func (r *RuntimeService) GetSupervisorProcess(id uint) ([]response.SupervisorPro } func (r *RuntimeService) OperateSupervisorProcess(req request.PHPSupervisorProcessConfig) error { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -1064,7 +1064,7 @@ func (r *RuntimeService) OperateSupervisorProcess(req request.PHPSupervisorProce } func (r *RuntimeService) OperateSupervisorProcessFile(req request.PHPSupervisorProcessFileReq) (string, error) { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.ID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return "", err } diff --git a/agent/app/service/runtime_utils.go b/agent/app/service/runtime_utils.go index 4f6b93e7b15d..ba155fbd07d9 100644 --- a/agent/app/service/runtime_utils.go +++ b/agent/app/service/runtime_utils.go @@ -10,6 +10,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto/response" "github.com/1Panel-dev/1Panel/agent/app/model" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/cmd/server/nginx_conf" "github.com/1Panel-dev/1Panel/agent/constant" @@ -54,7 +55,7 @@ func handleRuntime(create request.RuntimeCreate, runtime *model.Runtime, fileOp runtime.Status = constant.RuntimeCreating runtime.CodeDir = create.CodeDir - nodeDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(runtime.AppDetailID)) + nodeDetail, err := appDetailRepo.GetFirst(repo.WithByID(runtime.AppDetailID)) if err != nil { return err } diff --git a/agent/app/service/snapshot.go b/agent/app/service/snapshot.go index 3e9c44fdc984..0f737ccb027e 100644 --- a/agent/app/service/snapshot.go +++ b/agent/app/service/snapshot.go @@ -3,6 +3,7 @@ package service import ( "context" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strconv" @@ -45,7 +46,7 @@ func NewISnapshotService() ISnapshotService { } func (u *SnapshotService) SearchWithPage(req dto.PageSnapshot) (int64, interface{}, error) { - total, records, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) + total, records, err := snapshotRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info), repo.WithOrderRuleBy(req.OrderBy, req.Order)) if err != nil { return 0, nil, err } @@ -61,7 +62,7 @@ func (u *SnapshotService) SearchWithPage(req dto.PageSnapshot) (int64, interface } func (u *SnapshotService) LoadSize(req dto.SearchWithPage) ([]dto.SnapshotFile, error) { - _, records, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info)) + _, records, err := snapshotRepo.Page(req.Page, req.PageSize, repo.WithByLikeName(req.Info)) if err != nil { return nil, err } @@ -112,7 +113,7 @@ func (u *SnapshotService) SnapshotImport(req dto.SnapshotImport) error { return fmt.Errorf("incorrect snapshot request body: %v", req.Names) } for _, snapName := range req.Names { - snap, _ := snapshotRepo.Get(commonRepo.WithByName(strings.ReplaceAll(snapName, ".tar.gz", ""))) + snap, _ := snapshotRepo.Get(repo.WithByName(strings.ReplaceAll(snapName, ".tar.gz", ""))) if snap.ID != 0 { return constant.ErrRecordExist } @@ -185,7 +186,7 @@ type SnapshotJson struct { } func (u *SnapshotService) Delete(req dto.SnapshotBatchDelete) error { - snaps, _ := snapshotRepo.GetList(commonRepo.WithByIDs(req.Ids)) + snaps, _ := snapshotRepo.GetList(repo.WithByIDs(req.Ids)) for _, snap := range snaps { if req.DeleteWithFile { accounts, err := NewBackupClientMap(strings.Split(snap.SourceAccountIDs, ",")) @@ -198,7 +199,7 @@ func (u *SnapshotService) Delete(req dto.SnapshotBatchDelete) error { } } - if err := snapshotRepo.Delete(commonRepo.WithByID(snap.ID)); err != nil { + if err := snapshotRepo.Delete(repo.WithByID(snap.ID)); err != nil { return err } } diff --git a/agent/app/service/snapshot_create.go b/agent/app/service/snapshot_create.go index c1d9f0f7cac5..5f07f352c1ac 100644 --- a/agent/app/service/snapshot_create.go +++ b/agent/app/service/snapshot_create.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strings" @@ -77,11 +78,11 @@ func (u *SnapshotService) SnapshotCreate(req dto.SnapshotCreate, isCron bool) er } func (u *SnapshotService) SnapshotReCreate(id uint) error { - snap, err := snapshotRepo.Get(commonRepo.WithByID(id)) + snap, err := snapshotRepo.Get(repo.WithByID(id)) if err != nil { return err } - taskModel, err := taskRepo.GetFirst(taskRepo.WithResourceID(snap.ID), commonRepo.WithByType(task.TaskScopeSnapshot)) + taskModel, err := taskRepo.GetFirst(taskRepo.WithResourceID(snap.ID), repo.WithByType(task.TaskScopeSnapshot)) if err != nil { return err } diff --git a/agent/app/service/snapshot_recover.go b/agent/app/service/snapshot_recover.go index 7351ddb7c300..42f4db3f92db 100644 --- a/agent/app/service/snapshot_recover.go +++ b/agent/app/service/snapshot_recover.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" "strings" @@ -28,7 +29,7 @@ type snapRecoverHelper struct { func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error { global.LOG.Info("start to recover panel by snapshot now") - snap, err := snapshotRepo.Get(commonRepo.WithByID(req.ID)) + snap, err := snapshotRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } diff --git a/agent/app/service/snapshot_rollback.go b/agent/app/service/snapshot_rollback.go index 1fab2615b240..f2ab1e35a4f8 100644 --- a/agent/app/service/snapshot_rollback.go +++ b/agent/app/service/snapshot_rollback.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "os" "path" @@ -15,7 +16,7 @@ import ( func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error { global.LOG.Info("start to rollback now") - snap, err := snapshotRepo.Get(commonRepo.WithByID(req.ID)) + snap, err := snapshotRepo.Get(repo.WithByID(req.ID)) if err != nil { return err } diff --git a/agent/app/service/task.go b/agent/app/service/task.go index 8bcb4b2162e4..973a8f2bf12c 100644 --- a/agent/app/service/task.go +++ b/agent/app/service/task.go @@ -19,13 +19,13 @@ func NewITaskService() ITaskLogService { func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error) { opts := []repo.DBOption{ - commonRepo.WithOrderBy("created_at desc"), + repo.WithOrderBy("created_at desc"), } if req.Status != "" { - opts = append(opts, commonRepo.WithByStatus(req.Status)) + opts = append(opts, repo.WithByStatus(req.Status)) } if req.Type != "" { - opts = append(opts, commonRepo.WithByType(req.Type)) + opts = append(opts, repo.WithByType(req.Type)) } total, tasks, err := taskRepo.Page( diff --git a/agent/app/service/website.go b/agent/app/service/website.go index f02448ff97c5..d2adf256a5d2 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -133,7 +133,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons websiteDTOs []response.WebsiteRes opts []repo.DBOption ) - opts = append(opts, commonRepo.WithOrderRuleBy(req.OrderBy, req.Order)) + opts = append(opts, repo.WithOrderRuleBy(req.OrderBy, req.Order)) if req.Name != "" { domains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithDomainLike(req.Name)) if len(domains) > 0 { @@ -141,7 +141,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons for _, domain := range domains { websiteIds = append(websiteIds, domain.WebsiteID) } - opts = append(opts, commonRepo.WithByIDs(websiteIds)) + opts = append(opts, repo.WithByIDs(websiteIds)) } else { opts = append(opts, websiteRepo.WithDomainLike(req.Name)) } @@ -162,14 +162,14 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons ) switch web.Type { case constant.Deployment: - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(web.AppInstallID)) + appInstall, err := appInstallRepo.GetFirst(repo.WithByID(web.AppInstallID)) if err != nil { return 0, nil, err } appName = appInstall.Name appInstallID = appInstall.ID case constant.Runtime: - runtime, _ := runtimeRepo.GetFirst(commonRepo.WithByID(web.RuntimeID)) + runtime, _ := runtimeRepo.GetFirst(repo.WithByID(web.RuntimeID)) if runtime != nil { runtimeName = runtime.Name runtimeType = runtime.Type @@ -209,7 +209,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons func (w WebsiteService) GetWebsites() ([]response.WebsiteDTO, error) { var websiteDTOs []response.WebsiteDTO - websites, _ := websiteRepo.List(commonRepo.WithOrderRuleBy("primary_domain", "ascending")) + websites, _ := websiteRepo.List(repo.WithOrderRuleBy("primary_domain", "ascending")) for _, web := range websites { res := response.WebsiteDTO{ Website: web, @@ -287,14 +287,14 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) if create.CreateDb { createDataBase := func(t *task.Task) error { - database, _ := databaseRepo.Get(commonRepo.WithByName(create.DbHost)) + database, _ := databaseRepo.Get(repo.WithByName(create.DbHost)) if database.ID == 0 { return nil } dbConfig := create.DataBaseConfig switch database.Type { case constant.AppPostgresql, constant.AppPostgres: - oldPostgresqlDb, _ := postgresqlRepo.Get(commonRepo.WithByName(create.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) + oldPostgresqlDb, _ := postgresqlRepo.Get(repo.WithByName(create.DbName), repo.WithByFrom(constant.ResourceLocal)) if oldPostgresqlDb.ID > 0 { return buserr.New(constant.ErrDbUserNotValid) } @@ -313,7 +313,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) website.DbID = pgDB.ID website.DbType = database.Type case constant.AppMysql, constant.AppMariaDB: - oldMysqlDb, _ := mysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal)) + oldMysqlDb, _ := mysqlRepo.Get(repo.WithByName(dbConfig.DbName), repo.WithByFrom(constant.ResourceLocal)) if oldMysqlDb.ID > 0 { return buserr.New(constant.ErrDbUserNotValid) } @@ -358,7 +358,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) website.Proxy = fmt.Sprintf("127.0.0.1:%d", appInstall.HttpPort) } else { var install model.AppInstall - install, err = appInstallRepo.GetFirst(commonRepo.WithByID(create.AppInstallID)) + install, err = appInstallRepo.GetFirst(repo.WithByID(create.AppInstallID)) if err != nil { return err } @@ -371,7 +371,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) createTask.AddSubTask(i18n.GetMsgByKey("ConfigApp"), configApp, nil) } case constant.Runtime: - runtime, err = runtimeRepo.GetFirst(commonRepo.WithByID(create.RuntimeID)) + runtime, err = runtimeRepo.GetFirst(repo.WithByID(create.RuntimeID)) if err != nil { return err } @@ -398,7 +398,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) website.Proxy = fmt.Sprintf("127.0.0.1:%d", runtime.Port) } case constant.Subsite: - parentWebsite, err := websiteRepo.GetFirst(commonRepo.WithByID(create.ParentWebsiteID)) + parentWebsite, err := websiteRepo.GetFirst(repo.WithByID(create.ParentWebsiteID)) if err != nil { return err } @@ -456,7 +456,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) if create.EnableSSL { enableSSL := func(t *task.Task) error { - websiteModel, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(create.WebsiteSSLID)) + websiteModel, err := websiteSSLRepo.GetFirst(repo.WithByID(create.WebsiteSSLID)) if err != nil { return err } @@ -487,7 +487,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) } func (w WebsiteService) OpWebsite(req request.WebsiteOp) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -500,7 +500,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, commonRepo.WithTypes(req.Types)) + options = append(options, repo.WithTypes(req.Types)) } webs, _ := websiteRepo.List(options...) var datas []response.WebsiteOption @@ -515,7 +515,7 @@ func (w WebsiteService) GetWebsiteOptions(req request.WebsiteOptionReq) ([]respo } func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -542,7 +542,7 @@ func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error { func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) { var res response.WebsiteDTO - website, err := websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err := websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return res, err } @@ -552,7 +552,7 @@ func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) { res.SitePath = GetSitePath(website, SiteDir) res.SiteDir = website.SiteDir if website.Type == constant.Runtime { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return res, err } @@ -563,7 +563,7 @@ func (w WebsiteService) GetWebsite(id uint) (response.WebsiteDTO, error) { } func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -586,7 +586,7 @@ func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error { } if checkIsLinkApp(website) && req.DeleteApp { - appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) + appInstall, _ := appInstallRepo.GetFirst(repo.WithByID(website.AppInstallID)) if appInstall.ID > 0 { deleteReq := request.AppInstallDelete{ Install: appInstall, @@ -607,7 +607,7 @@ func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error { _ = NewIBackupService().DeleteRecordByName("website", website.PrimaryDomain, website.Alias, req.DeleteBackup) }() - if err := websiteRepo.DeleteBy(ctx, commonRepo.WithByID(req.ID)); err != nil { + if err := websiteRepo.DeleteBy(ctx, repo.WithByID(req.ID)); err != nil { return err } if err := websiteDomainRepo.DeleteBy(ctx, websiteDomainRepo.WithWebsiteId(req.ID)); err != nil { @@ -623,12 +623,12 @@ func (w WebsiteService) DeleteWebsite(req request.WebsiteDelete) error { } func (w WebsiteService) UpdateWebsiteDomain(req request.WebsiteDomainUpdate) error { - domain, err := websiteDomainRepo.GetFirst(commonRepo.WithByID(req.ID)) + domain, err := websiteDomainRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } domain.SSL = req.SSL - website, err := websiteRepo.GetFirst(commonRepo.WithByID(domain.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(domain.WebsiteID)) if err != nil { return err } @@ -663,7 +663,7 @@ func (w WebsiteService) CreateWebsiteDomain(create request.WebsiteDomainCreate) if err != nil { return nil, err } - website, err := websiteRepo.GetFirst(commonRepo.WithByID(create.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(create.WebsiteID)) if err != nil { return nil, err } @@ -733,7 +733,7 @@ func (w WebsiteService) GetWebsiteDomain(websiteId uint) ([]model.WebsiteDomain, } func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error { - webSiteDomain, err := websiteDomainRepo.GetFirst(commonRepo.WithByID(domainId)) + webSiteDomain, err := websiteDomainRepo.GetFirst(repo.WithByID(domainId)) if err != nil { return err } @@ -741,7 +741,7 @@ func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error { if websiteDomains, _ := websiteDomainRepo.GetBy(websiteDomainRepo.WithWebsiteId(webSiteDomain.WebsiteID)); len(websiteDomains) == 1 { return fmt.Errorf("can not delete last domain") } - website, err := websiteRepo.GetFirst(commonRepo.WithByID(webSiteDomain.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(webSiteDomain.WebsiteID)) if err != nil { return err } @@ -822,7 +822,7 @@ func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error { } } - return websiteDomainRepo.DeleteBy(context.TODO(), commonRepo.WithByID(domainId)) + return websiteDomainRepo.DeleteBy(context.TODO(), repo.WithByID(domainId)) } func (w WebsiteService) GetNginxConfigByScope(req request.NginxScopeReq) (*response.WebsiteNginxConfig, error) { @@ -831,7 +831,7 @@ func (w WebsiteService) GetNginxConfigByScope(req request.NginxScopeReq) (*respo return nil, nil } - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return nil, err } @@ -851,7 +851,7 @@ func (w WebsiteService) UpdateNginxConfigByScope(req request.NginxConfigUpdate) if !ok || len(keys) == 0 { return nil } - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -874,7 +874,7 @@ func (w WebsiteService) UpdateNginxConfigByScope(req request.NginxConfigUpdate) } func (w WebsiteService) GetWebsiteNginxConfig(websiteID uint, configType string) (*response.FileInfo, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(websiteID)) if err != nil { return nil, err } @@ -894,7 +894,7 @@ func (w WebsiteService) GetWebsiteNginxConfig(websiteID uint, configType string) } func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId)) + website, err := websiteRepo.GetFirst(repo.WithByID(websiteId)) if err != nil { return response.WebsiteHTTPS{}, err } @@ -918,7 +918,7 @@ func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, res.Enable = false return res, nil } - websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebsiteSSLID)) + websiteSSL, err := websiteSSLRepo.GetFirst(repo.WithByID(website.WebsiteSSLID)) if err != nil { return response.WebsiteHTTPS{}, err } @@ -953,7 +953,7 @@ func (w WebsiteService) GetWebsiteHTTPS(websiteId uint) (response.WebsiteHTTPS, } func (w WebsiteService) OpWebsiteHTTPS(ctx context.Context, req request.WebsiteHTTPSOp) (*response.WebsiteHTTPS, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return nil, err } @@ -1025,7 +1025,7 @@ func (w WebsiteService) OpWebsiteHTTPS(ctx context.Context, req request.WebsiteH } if req.Type == constant.SSLExisted { - websiteModel, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(req.WebsiteSSLID)) + websiteModel, err := websiteSSLRepo.GetFirst(repo.WithByID(req.WebsiteSSLID)) if err != nil { return nil, err } @@ -1137,7 +1137,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r checkIds = append(req.InstallIds, appInstall.ID) } if len(checkIds) > 0 { - installList, _ := appInstallRepo.ListBy(commonRepo.WithByIDs(checkIds)) + installList, _ := appInstallRepo.ListBy(repo.WithByIDs(checkIds)) for _, install := range installList { if err = syncAppInstallStatus(&install, false); err != nil { return nil, err @@ -1160,7 +1160,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r } func (w WebsiteService) UpdateNginxConfigFile(req request.WebsiteNginxUpdate) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -1177,7 +1177,7 @@ func (w WebsiteService) UpdateNginxConfigFile(req request.WebsiteNginxUpdate) er } func (w WebsiteService) OpWebsiteLog(req request.WebsiteLogReq) (*response.WebsiteLog, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } @@ -1284,7 +1284,7 @@ func (w WebsiteService) ChangeDefaultServer(id uint) error { } } if id > 0 { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err := websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return err } @@ -1324,12 +1324,12 @@ func (w WebsiteService) ChangeDefaultServer(id uint) error { } func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } if website.Type == constant.Runtime { - oldRuntime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + oldRuntime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return err } @@ -1362,7 +1362,7 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error if req.RuntimeID > 0 { server.RemoveDirective("location", []string{"~", "[^/]\\.php(/|$)"}) - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(req.RuntimeID)) if err != nil { return err } @@ -1396,7 +1396,7 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error } func (w WebsiteService) UpdateRewriteConfig(req request.NginxRewriteUpdate) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -1432,7 +1432,7 @@ func (w WebsiteService) UpdateRewriteConfig(req request.NginxRewriteUpdate) erro } func (w WebsiteService) GetRewriteConfig(req request.NginxRewriteReq) (*response.NginxRewriteRes, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return nil, err } @@ -1502,7 +1502,7 @@ func (w WebsiteService) ListCustomRewrite() ([]string, error) { } func (w WebsiteService) UpdateSiteDir(req request.WebsiteUpdateDir) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -1519,7 +1519,7 @@ func (w WebsiteService) UpdateSiteDir(req request.WebsiteUpdateDir) error { } func (w WebsiteService) UpdateSitePermission(req request.WebsiteUpdateDirPermission) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return err } @@ -1546,7 +1546,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) oldContent []byte ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return } @@ -1648,7 +1648,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) } func (w WebsiteService) UpdateProxyCache(req request.NginxProxyCacheUpdate) (err error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return } @@ -1668,7 +1668,7 @@ func (w WebsiteService) GetProxyCache(id uint) (res response.NginxProxyCache, er var ( website model.Website ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err = websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return } @@ -1726,7 +1726,7 @@ func (w WebsiteService) GetProxies(id uint) (res []request.WebsiteProxyConfig, e website model.Website fileList response.FileInfo ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err = websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return } @@ -1797,7 +1797,7 @@ func (w WebsiteService) UpdateProxyFile(req request.NginxProxyUpdate) (err error nginxFull dto.NginxFull oldRewriteContent []byte ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -1824,7 +1824,7 @@ func (w WebsiteService) UpdateProxyFile(req request.NginxProxyUpdate) (err error } func (w WebsiteService) ClearProxyCache(req request.NginxCommonReq) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -1852,7 +1852,7 @@ func (w WebsiteService) GetAuthBasics(req request.NginxAuthReq) (res response.Ng authContent []byte nginxParams []response.NginxParam ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return } @@ -1897,7 +1897,7 @@ func (w WebsiteService) UpdateAuthBasic(req request.NginxAuthUpdate) (err error) authContent []byte authArray []string ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -2024,7 +2024,7 @@ func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []respo nginxInstall model.AppInstall authContent []byte ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return } @@ -2088,7 +2088,7 @@ func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []respo } func (w WebsiteService) UpdatePathAuthBasic(req request.NginxPathAuthUpdate) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -2157,7 +2157,7 @@ func (w WebsiteService) UpdatePathAuthBasic(req request.NginxPathAuthUpdate) err } func (w WebsiteService) UpdateAntiLeech(req request.NginxAntiLeechUpdate) (err error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return } @@ -2244,7 +2244,7 @@ func (w WebsiteService) UpdateAntiLeech(req request.NginxAntiLeechUpdate) (err e } func (w WebsiteService) GetAntiLeech(id uint) (*response.NginxAntiLeechRes, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err := websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -2327,7 +2327,7 @@ func (w WebsiteService) OperateRedirect(req request.NginxRedirectReq) (err error oldContent []byte ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -2475,7 +2475,7 @@ func (w WebsiteService) GetRedirect(id uint) (res []response.NginxRedirectConfig website model.Website fileList response.FileInfo ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err = websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return } @@ -2605,7 +2605,7 @@ func (w WebsiteService) UpdateRedirectFile(req request.NginxRedirectUpdate) (err nginxFull dto.NginxFull oldRewriteContent []byte ) - website, err = websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err = websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -2632,7 +2632,7 @@ func (w WebsiteService) UpdateRedirectFile(req request.NginxRedirectUpdate) (err } func (w WebsiteService) LoadWebsiteDirConfig(req request.WebsiteCommonReq) (*response.WebsiteDirConfig, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } @@ -2765,7 +2765,7 @@ func (w WebsiteService) UpdateDefaultHtml(req request.WebsiteHtmlUpdate) error { } func (w WebsiteService) GetLoadBalances(id uint) ([]dto.NginxUpstream, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(id)) + website, err := websiteRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -2860,7 +2860,7 @@ func (w WebsiteService) GetLoadBalances(id uint) ([]dto.NginxUpstream, error) { } func (w WebsiteService) CreateLoadBalance(req request.WebsiteLBCreate) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -2935,7 +2935,7 @@ func (w WebsiteService) CreateLoadBalance(req request.WebsiteLBCreate) error { } func (w WebsiteService) UpdateLoadBalance(req request.WebsiteLBUpdate) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -3007,7 +3007,7 @@ func (w WebsiteService) UpdateLoadBalance(req request.WebsiteLBUpdate) error { } func (w WebsiteService) DeleteLoadBalance(req request.WebsiteLBDelete) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -3028,7 +3028,7 @@ func (w WebsiteService) DeleteLoadBalance(req request.WebsiteLBDelete) error { } func (w WebsiteService) UpdateLoadBalanceFile(req request.WebsiteLBUpdateFile) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -3059,7 +3059,7 @@ func (w WebsiteService) ChangeGroup(group, newGroup uint) error { } func (w WebsiteService) SetRealIPConfig(req request.WebsiteRealIP) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } @@ -3102,7 +3102,7 @@ func (w WebsiteService) SetRealIPConfig(req request.WebsiteRealIP) error { } func (w WebsiteService) GetRealIPConfig(websiteID uint) (*response.WebsiteRealIP, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(websiteID)) if err != nil { return nil, err } @@ -3139,7 +3139,7 @@ func (w WebsiteService) GetRealIPConfig(websiteID uint) (*response.WebsiteRealIP } func (w WebsiteService) GetWebsiteResource(websiteID uint) ([]response.Resource, error) { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(websiteID)) if err != nil { return nil, err } @@ -3149,7 +3149,7 @@ func (w WebsiteService) GetWebsiteResource(websiteID uint) ([]response.Resource, databaseType string ) if website.Type == constant.Runtime { - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return nil, err } @@ -3161,7 +3161,7 @@ func (w WebsiteService) GetWebsiteResource(websiteID uint) ([]response.Resource, }) } if website.Type == constant.Deployment { - install, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) + install, err := appInstallRepo.GetFirst(repo.WithByID(website.AppInstallID)) if err != nil { return nil, err } @@ -3186,7 +3186,7 @@ func (w WebsiteService) GetWebsiteResource(websiteID uint) ([]response.Resource, if databaseID > 0 { switch databaseType { case constant.AppMysql, constant.AppMariaDB: - db, _ := mysqlRepo.Get(commonRepo.WithByID(databaseID)) + db, _ := mysqlRepo.Get(repo.WithByID(databaseID)) if db.ID > 0 { res = append(res, response.Resource{ Name: db.Name, @@ -3196,7 +3196,7 @@ func (w WebsiteService) GetWebsiteResource(websiteID uint) ([]response.Resource, }) } case constant.AppPostgresql, constant.AppPostgres: - db, _ := postgresqlRepo.Get(commonRepo.WithByID(databaseID)) + db, _ := postgresqlRepo.Get(repo.WithByID(databaseID)) if db.ID > 0 { res = append(res, response.Resource{ Name: db.Name, @@ -3215,7 +3215,7 @@ func (w WebsiteService) ListDatabases() ([]response.Database, error) { var res []response.Database mysqlDBs, _ := mysqlRepo.List() for _, db := range mysqlDBs { - database, _ := databaseRepo.Get(commonRepo.WithByName(db.MysqlName)) + database, _ := databaseRepo.Get(repo.WithByName(db.MysqlName)) if database.ID > 0 { res = append(res, response.Database{ ID: db.ID, @@ -3226,7 +3226,7 @@ func (w WebsiteService) ListDatabases() ([]response.Database, error) { } pgSqls, _ := postgresqlRepo.List() for _, db := range pgSqls { - database, _ := databaseRepo.Get(commonRepo.WithByName(db.PostgresqlName)) + database, _ := databaseRepo.Get(repo.WithByName(db.PostgresqlName)) if database.ID > 0 { res = append(res, response.Database{ ID: db.ID, @@ -3239,7 +3239,7 @@ func (w WebsiteService) ListDatabases() ([]response.Database, error) { } func (w WebsiteService) ChangeDatabase(req request.ChangeDatabase) error { - website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID)) + website, err := websiteRepo.GetFirst(repo.WithByID(req.WebsiteID)) if err != nil { return err } diff --git a/agent/app/service/website_acme_account.go b/agent/app/service/website_acme_account.go index 18789ddee286..06665bb6ea67 100644 --- a/agent/app/service/website_acme_account.go +++ b/agent/app/service/website_acme_account.go @@ -5,6 +5,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/dto/request" "github.com/1Panel-dev/1Panel/agent/app/dto/response" "github.com/1Panel-dev/1Panel/agent/app/model" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/buserr" "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/utils/ssl" @@ -24,7 +25,7 @@ func NewIWebsiteAcmeAccountService() IWebsiteAcmeAccountService { } func (w WebsiteAcmeAccountService) Page(search dto.PageInfo) (int64, []response.WebsiteAcmeAccountDTO, error) { - total, accounts, err := websiteAcmeRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc")) + total, accounts, err := websiteAcmeRepo.Page(search.Page, search.PageSize, repo.WithOrderBy("created_at desc")) var accountDTOs []response.WebsiteAcmeAccountDTO for _, account := range accounts { accountDTOs = append(accountDTOs, response.WebsiteAcmeAccountDTO{ @@ -74,5 +75,5 @@ func (w WebsiteAcmeAccountService) Delete(id uint) error { if ssls, _ := websiteSSLRepo.List(websiteSSLRepo.WithByAcmeAccountId(id)); len(ssls) > 0 { return buserr.New(constant.ErrAccountCannotDelete) } - return websiteAcmeRepo.DeleteBy(commonRepo.WithByID(id)) + return websiteAcmeRepo.DeleteBy(repo.WithByID(id)) } diff --git a/agent/app/service/website_ca.go b/agent/app/service/website_ca.go index 5a9bdd43bba8..bd17e9a932a3 100644 --- a/agent/app/service/website_ca.go +++ b/agent/app/service/website_ca.go @@ -10,6 +10,7 @@ import ( "crypto/x509/pkix" "encoding/pem" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/utils/common" "log" "math/big" @@ -49,7 +50,7 @@ func NewIWebsiteCAService() IWebsiteCAService { } func (w WebsiteCAService) Page(search request.WebsiteCASearch) (int64, []response.WebsiteCADTO, error) { - total, cas, err := websiteCARepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc")) + total, cas, err := websiteCARepo.Page(search.Page, search.PageSize, repo.WithOrderBy("created_at desc")) if err != nil { return 0, nil, err } @@ -63,7 +64,7 @@ func (w WebsiteCAService) Page(search request.WebsiteCASearch) (int64, []respons } func (w WebsiteCAService) Create(create request.WebsiteCACreate) (*request.WebsiteCACreate, error) { - if exist, _ := websiteCARepo.GetFirst(commonRepo.WithByName(create.Name)); exist.ID > 0 { + if exist, _ := websiteCARepo.GetFirst(repo.WithByName(create.Name)); exist.ID > 0 { return nil, buserr.New(constant.ErrNameIsExist) } @@ -126,7 +127,7 @@ func (w WebsiteCAService) Create(create request.WebsiteCACreate) (*request.Websi func (w WebsiteCAService) GetCA(id uint) (*response.WebsiteCADTO, error) { res := &response.WebsiteCADTO{} - ca, err := websiteCARepo.GetFirst(commonRepo.WithByID(id)) + ca, err := websiteCARepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -154,14 +155,14 @@ func (w WebsiteCAService) Delete(id uint) error { if len(ssls) > 0 { return buserr.New("ErrDeleteCAWithSSL") } - exist, err := websiteCARepo.GetFirst(commonRepo.WithByID(id)) + exist, err := websiteCARepo.GetFirst(repo.WithByID(id)) if err != nil { return err } if exist.Name == "1Panel" { return buserr.New("ErrDefaultCA") } - return websiteCARepo.DeleteBy(commonRepo.WithByID(id)) + return websiteCARepo.DeleteBy(repo.WithByID(id)) } func (w WebsiteCAService) ObtainSSL(req request.WebsiteCAObtain) (*model.WebsiteSSL, error) { @@ -173,11 +174,11 @@ func (w WebsiteCAService) ObtainSSL(req request.WebsiteCAObtain) (*model.Website ca model.WebsiteCA ) if req.Renew { - websiteSSL, err = websiteSSLRepo.GetFirst(commonRepo.WithByID(req.SSLID)) + websiteSSL, err = websiteSSLRepo.GetFirst(repo.WithByID(req.SSLID)) if err != nil { return nil, err } - ca, err = websiteCARepo.GetFirst(commonRepo.WithByID(websiteSSL.CaID)) + ca, err = websiteCARepo.GetFirst(repo.WithByID(websiteSSL.CaID)) if err != nil { return nil, err } @@ -193,7 +194,7 @@ func (w WebsiteCAService) ObtainSSL(req request.WebsiteCAObtain) (*model.Website } } } else { - ca, err = websiteCARepo.GetFirst(commonRepo.WithByID(req.ID)) + ca, err = websiteCARepo.GetFirst(repo.WithByID(req.ID)) if err != nil { return nil, err } @@ -419,7 +420,7 @@ func createPrivateKey(keyType string) (privateKey any, publicKey any, privateKey } func (w WebsiteCAService) DownloadFile(id uint) (*os.File, error) { - ca, err := websiteCARepo.GetFirst(commonRepo.WithByID(id)) + ca, err := websiteCARepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } diff --git a/agent/app/service/website_dns_account.go b/agent/app/service/website_dns_account.go index e9fdbc49b95a..b45ff9d0c707 100644 --- a/agent/app/service/website_dns_account.go +++ b/agent/app/service/website_dns_account.go @@ -2,6 +2,7 @@ package service import ( "encoding/json" + "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/app/dto/request" @@ -26,7 +27,7 @@ func NewIWebsiteDnsAccountService() IWebsiteDnsAccountService { } func (w WebsiteDnsAccountService) Page(search dto.PageInfo) (int64, []response.WebsiteDnsAccountDTO, error) { - total, accounts, err := websiteDnsRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc")) + total, accounts, err := websiteDnsRepo.Page(search.Page, search.PageSize, repo.WithOrderBy("created_at desc")) var accountDTOs []response.WebsiteDnsAccountDTO for _, account := range accounts { auth := make(map[string]string) @@ -40,7 +41,7 @@ func (w WebsiteDnsAccountService) Page(search dto.PageInfo) (int64, []response.W } func (w WebsiteDnsAccountService) Create(create request.WebsiteDnsAccountCreate) (request.WebsiteDnsAccountCreate, error) { - exist, _ := websiteDnsRepo.GetFirst(commonRepo.WithByName(create.Name)) + exist, _ := websiteDnsRepo.GetFirst(repo.WithByName(create.Name)) if exist != nil { return request.WebsiteDnsAccountCreate{}, buserr.New(constant.ErrNameIsExist) } @@ -66,7 +67,7 @@ func (w WebsiteDnsAccountService) Update(update request.WebsiteDnsAccountUpdate) if err != nil { return request.WebsiteDnsAccountUpdate{}, err } - exists, _ := websiteDnsRepo.List(commonRepo.WithByName(update.Name)) + exists, _ := websiteDnsRepo.List(repo.WithByName(update.Name)) for _, exist := range exists { if exist.ID != update.ID { return request.WebsiteDnsAccountUpdate{}, buserr.New(constant.ErrNameIsExist) @@ -90,5 +91,5 @@ func (w WebsiteDnsAccountService) Delete(id uint) error { if ssls, _ := websiteSSLRepo.List(websiteSSLRepo.WithByDnsAccountId(id)); len(ssls) > 0 { return buserr.New(constant.ErrAccountCannotDelete) } - return websiteDnsRepo.DeleteBy(commonRepo.WithByID(id)) + return websiteDnsRepo.DeleteBy(repo.WithByID(id)) } diff --git a/agent/app/service/website_ssl.go b/agent/app/service/website_ssl.go index b9cf92188f8a..828432e4b094 100644 --- a/agent/app/service/website_ssl.go +++ b/agent/app/service/website_ssl.go @@ -57,7 +57,7 @@ func (w WebsiteSSLService) Page(search request.WebsiteSSLSearch) (int64, []respo var ( result []response.WebsiteSSLDTO ) - total, sslList, err := websiteSSLRepo.Page(search.Page, search.PageSize, commonRepo.WithOrderBy("created_at desc")) + total, sslList, err := websiteSSLRepo.Page(search.Page, search.PageSize, repo.WithOrderBy("created_at desc")) if err != nil { return 0, nil, err } @@ -72,7 +72,7 @@ func (w WebsiteSSLService) Page(search request.WebsiteSSLSearch) (int64, []respo func (w WebsiteSSLService) GetSSL(id uint) (*response.WebsiteSSLDTO, error) { var res response.WebsiteSSLDTO - websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(id)) + websiteSSL, err := websiteSSLRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } @@ -85,7 +85,7 @@ func (w WebsiteSSLService) Search(search request.WebsiteSSLSearch) ([]response.W opts []repo.DBOption result []response.WebsiteSSLDTO ) - opts = append(opts, commonRepo.WithOrderBy("created_at desc")) + opts = append(opts, repo.WithOrderBy("created_at desc")) if search.AcmeAccountID != "" { acmeAccountID, err := strconv.ParseUint(search.AcmeAccountID, 10, 64) if err != nil { @@ -113,7 +113,7 @@ func (w WebsiteSSLService) Create(create request.WebsiteSSLCreate) (request.Webs return create, buserr.New("ErrParseIP") } var res request.WebsiteSSLCreate - acmeAccount, err := websiteAcmeRepo.GetFirst(commonRepo.WithByID(create.AcmeAccountID)) + acmeAccount, err := websiteAcmeRepo.GetFirst(repo.WithByID(create.AcmeAccountID)) if err != nil { return res, err } @@ -160,7 +160,7 @@ func (w WebsiteSSLService) Create(create request.WebsiteSSLCreate) (request.Webs websiteSSL.AutoRenew = create.AutoRenew } if create.Provider == constant.DNSAccount { - dnsAccount, err := websiteDnsRepo.GetFirst(commonRepo.WithByID(create.DnsAccountID)) + dnsAccount, err := websiteDnsRepo.GetFirst(repo.WithByID(create.DnsAccountID)) if err != nil { return res, err } @@ -221,11 +221,11 @@ func (w WebsiteSSLService) ObtainSSL(apply request.WebsiteSSLApply) error { dnsAccount *model.WebsiteDnsAccount ) - websiteSSL, err = websiteSSLRepo.GetFirst(commonRepo.WithByID(apply.ID)) + websiteSSL, err = websiteSSLRepo.GetFirst(repo.WithByID(apply.ID)) if err != nil { return err } - acmeAccount, err = websiteAcmeRepo.GetFirst(commonRepo.WithByID(websiteSSL.AcmeAccountID)) + acmeAccount, err = websiteAcmeRepo.GetFirst(repo.WithByID(websiteSSL.AcmeAccountID)) if err != nil { return err } @@ -236,7 +236,7 @@ func (w WebsiteSSLService) ObtainSSL(apply request.WebsiteSSLApply) error { switch websiteSSL.Provider { case constant.DNSAccount: - dnsAccount, err = websiteDnsRepo.GetFirst(commonRepo.WithByID(websiteSSL.DnsAccountID)) + dnsAccount, err = websiteDnsRepo.GetFirst(repo.WithByID(websiteSSL.DnsAccountID)) if err != nil { return err } @@ -387,7 +387,7 @@ func handleError(websiteSSL *model.WebsiteSSL, err error) { } func (w WebsiteSSLService) GetDNSResolve(req request.WebsiteDNSReq) ([]response.WebsiteDNSRes, error) { - acmeAccount, err := websiteAcmeRepo.GetFirst(commonRepo.WithByID(req.AcmeAccountID)) + acmeAccount, err := websiteAcmeRepo.GetFirst(repo.WithByID(req.AcmeAccountID)) if err != nil { return nil, err } @@ -414,11 +414,11 @@ func (w WebsiteSSLService) GetDNSResolve(req request.WebsiteDNSReq) ([]response. func (w WebsiteSSLService) GetWebsiteSSL(websiteId uint) (response.WebsiteSSLDTO, error) { var res response.WebsiteSSLDTO - website, err := websiteRepo.GetFirst(commonRepo.WithByID(websiteId)) + website, err := websiteRepo.GetFirst(repo.WithByID(websiteId)) if err != nil { return res, err } - websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(website.WebsiteSSLID)) + websiteSSL, err := websiteSSLRepo.GetFirst(repo.WithByID(website.WebsiteSSLID)) if err != nil { return res, err } @@ -430,7 +430,7 @@ func (w WebsiteSSLService) Delete(ids []uint) error { var names []string for _, id := range ids { if websites, _ := websiteRepo.GetBy(websiteRepo.WithWebsiteSSLID(id)); len(websites) > 0 { - oldSSL, _ := websiteSSLRepo.GetFirst(commonRepo.WithByID(id)) + oldSSL, _ := websiteSSLRepo.GetFirst(repo.WithByID(id)) if oldSSL.ID > 0 { names = append(names, oldSSL.PrimaryDomain) } @@ -444,11 +444,11 @@ func (w WebsiteSSLService) Delete(ids []uint) error { return buserr.New("ErrDeleteWithPanelSSL") } } - websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(id)) + websiteSSL, err := websiteSSLRepo.GetFirst(repo.WithByID(id)) if err != nil { return err } - acmeAccount, err := websiteAcmeRepo.GetFirst(commonRepo.WithByID(websiteSSL.AcmeAccountID)) + acmeAccount, err := websiteAcmeRepo.GetFirst(repo.WithByID(websiteSSL.AcmeAccountID)) if err != nil { return err } @@ -457,7 +457,7 @@ func (w WebsiteSSLService) Delete(ids []uint) error { return err } _ = client.RevokeSSL([]byte(websiteSSL.Pem)) - _ = websiteSSLRepo.DeleteBy(commonRepo.WithByID(id)) + _ = websiteSSLRepo.DeleteBy(repo.WithByID(id)) } if len(names) > 0 { return buserr.WithName("ErrSSLCannotDelete", strings.Join(names, ",")) @@ -466,7 +466,7 @@ func (w WebsiteSSLService) Delete(ids []uint) error { } func (w WebsiteSSLService) Update(update request.WebsiteSSLUpdate) error { - websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(update.ID)) + websiteSSL, err := websiteSSLRepo.GetFirst(repo.WithByID(update.ID)) if err != nil { return err } @@ -487,7 +487,7 @@ func (w WebsiteSSLService) Update(update request.WebsiteSSLUpdate) error { } if websiteSSL.Provider != constant.SelfSigned { - acmeAccount, err := websiteAcmeRepo.GetFirst(commonRepo.WithByID(update.AcmeAccountID)) + acmeAccount, err := websiteAcmeRepo.GetFirst(repo.WithByID(update.AcmeAccountID)) if err != nil { return err } @@ -518,7 +518,7 @@ func (w WebsiteSSLService) Update(update request.WebsiteSSLUpdate) error { updateParams["auto_renew"] = false } if update.Provider == constant.DNSAccount { - dnsAccount, err := websiteDnsRepo.GetFirst(commonRepo.WithByID(update.DnsAccountID)) + dnsAccount, err := websiteDnsRepo.GetFirst(repo.WithByID(update.DnsAccountID)) if err != nil { return err } @@ -535,7 +535,7 @@ func (w WebsiteSSLService) Upload(req request.WebsiteSSLUpload) error { } var err error if req.SSLID > 0 { - websiteSSL, err = websiteSSLRepo.GetFirst(commonRepo.WithByID(req.SSLID)) + websiteSSL, err = websiteSSLRepo.GetFirst(repo.WithByID(req.SSLID)) if err != nil { return err } @@ -629,7 +629,7 @@ func (w WebsiteSSLService) Upload(req request.WebsiteSSLUpload) error { } func (w WebsiteSSLService) DownloadFile(id uint) (*os.File, error) { - websiteSSL, err := websiteSSLRepo.GetFirst(commonRepo.WithByID(id)) + websiteSSL, err := websiteSSLRepo.GetFirst(repo.WithByID(id)) if err != nil { return nil, err } diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go index 439113799199..91502412865e 100644 --- a/agent/app/service/website_utils.go +++ b/agent/app/service/website_utils.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "fmt" + "github.com/1Panel-dev/1Panel/agent/app/repo" "log" "os" "path" @@ -232,7 +233,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a server.UpdateRootProxy([]string{proxy}) } case constant.Subsite: - parentWebsite, err := websiteRepo.GetFirst(commonRepo.WithByID(website.ParentWebsiteID)) + parentWebsite, err := websiteRepo.GetFirst(repo.WithByID(website.ParentWebsiteID)) if err != nil { return err } @@ -240,7 +241,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a rootIndex = path.Join("/www/sites", parentWebsite.Alias, "index", website.SiteDir) server.UpdateDirective("error_page", []string{"404", "/404.html"}) if parentWebsite.Type == constant.Runtime { - parentRuntime, err := runtimeRepo.GetFirst(commonRepo.WithByID(parentWebsite.RuntimeID)) + parentRuntime, err := runtimeRepo.GetFirst(repo.WithByID(parentWebsite.RuntimeID)) if err != nil { return err } @@ -801,7 +802,7 @@ func opWebsite(website *model.Website, operate string) error { case constant.Deployment: server.RemoveDirective("location", []string{"/"}) case constant.Runtime: - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return err } @@ -833,7 +834,7 @@ func opWebsite(website *model.Website, operate string) error { switch website.Type { case constant.Deployment: server.RemoveDirective("root", nil) - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(website.AppInstallID)) + appInstall, err := appInstallRepo.GetFirst(repo.WithByID(website.AppInstallID)) if err != nil { return err } @@ -847,7 +848,7 @@ func opWebsite(website *model.Website, operate string) error { case constant.Runtime: server.UpdateRoot(rootIndex) localPath := "" - runtime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, err := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) if err != nil { return err } @@ -918,7 +919,7 @@ func checkIsLinkApp(website model.Website) bool { return true } if website.Type == constant.Runtime { - runtime, _ := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID)) + runtime, _ := runtimeRepo.GetFirst(repo.WithByID(website.RuntimeID)) return runtime.Resource == constant.ResourceAppstore } return false @@ -971,7 +972,7 @@ func getWebsiteDomains(domains []request.WebsiteDomain, defaultPort int, website } for _, domain := range domainModels { if exist, _ := websiteDomainRepo.GetFirst(websiteDomainRepo.WithDomain(domain.Domain), websiteDomainRepo.WithPort(domain.Port)); exist.ID > 0 { - website, _ := websiteRepo.GetFirst(commonRepo.WithByID(exist.WebsiteID)) + website, _ := websiteRepo.GetFirst(repo.WithByID(exist.WebsiteID)) err = buserr.WithName(constant.ErrDomainIsUsed, website.PrimaryDomain) return } diff --git a/agent/app/task/task.go b/agent/app/task/task.go index ce0bc43320e4..243d5fcf6ed9 100644 --- a/agent/app/task/task.go +++ b/agent/app/task/task.go @@ -88,8 +88,7 @@ func NewTaskWithOps(resourceName, operate, scope, taskID string, resourceID uint func CheckTaskIsExecuting(name string) error { taskRepo := repo.NewITaskRepo() - commonRepo := repo.NewCommonRepo() - task, _ := taskRepo.GetFirst(commonRepo.WithByStatus(constant.StatusExecuting), commonRepo.WithByName(name)) + task, _ := taskRepo.GetFirst(taskRepo.WithByStatus(constant.StatusExecuting), repo.WithByName(name)) if task.ID != "" { return buserr.New("TaskIsExecuting") }