From d6b21f4ab5008b7dccfc2ac6aec162a181c5c06e Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:28:04 +0800 Subject: [PATCH] fix: remove duplicate code (#7763) --- agent/app/repo/backup.go | 2 +- agent/app/service/clam.go | 3 +-- agent/app/service/docker.go | 3 ++- agent/init/migration/migrate.go | 1 - agent/init/migration/migrations/init.go | 14 ------------- core/init/migration/migrations/init.go | 3 --- frontend/src/api/interface/container.ts | 3 ++- frontend/src/components/status/index.vue | 2 +- .../src/views/container/setting/index.vue | 20 ++++++++----------- 9 files changed, 15 insertions(+), 36 deletions(-) diff --git a/agent/app/repo/backup.go b/agent/app/repo/backup.go index c03a8aef6..6c00cbb51 100644 --- a/agent/app/repo/backup.go +++ b/agent/app/repo/backup.go @@ -159,7 +159,7 @@ func (u *BackupRepo) GetRecord(opts ...DBOption) (*model.BackupRecord, error) { func (u *BackupRepo) SyncAll(data []model.BackupAccount) error { tx := global.DB.Begin() - if err := tx.Where("1 = 1").Delete(&model.BackupAccount{}).Error; err != nil { + if err := tx.Where("is_public = ?", 1).Delete(&model.BackupAccount{}).Error; err != nil { tx.Rollback() return err } diff --git a/agent/app/service/clam.go b/agent/app/service/clam.go index a87d9d887..45bca8848 100644 --- a/agent/app/service/clam.go +++ b/agent/app/service/clam.go @@ -635,8 +635,7 @@ func handleAlert(stdout, clamName string, clamId uint) { lines := strings.Split(stdout, "\n") for _, line := range lines { if strings.HasPrefix(line, "Infected files: ") { - var infectedFiles = 0 - infectedFiles, _ = strconv.Atoi(strings.TrimPrefix(line, "Infected files: ")) + infectedFiles, _ := strconv.Atoi(strings.TrimPrefix(line, "Infected files: ")) if infectedFiles > 0 { pushAlert := dto.PushAlert{ TaskName: clamName, diff --git a/agent/app/service/docker.go b/agent/app/service/docker.go index a716a81cb..0997dbd8b 100644 --- a/agent/app/service/docker.go +++ b/agent/app/service/docker.go @@ -70,11 +70,12 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { var data dto.DaemonJsonConf data.IPTables = true data.Version = "-" - if cmd.Which("docker") { + if !cmd.Which("docker") { data.IsExist = false return &data } data.IsExist = true + data.IsActive = true client, err := docker.NewDockerClient() if err != nil { data.IsActive = false diff --git a/agent/init/migration/migrate.go b/agent/init/migration/migrate.go index aa139c753..76d31f4d4 100644 --- a/agent/init/migration/migrate.go +++ b/agent/init/migration/migrate.go @@ -21,7 +21,6 @@ func InitAgentDB() { migrations.InitImageRepo, migrations.InitDefaultCA, migrations.InitPHPExtensions, - migrations.InitNodePort, migrations.InitBackup, }) if err := m.Migrate(); err != nil { diff --git a/agent/init/migration/migrations/init.go b/agent/init/migration/migrations/init.go index ed741ab38..edf592243 100644 --- a/agent/init/migration/migrations/init.go +++ b/agent/init/migration/migrations/init.go @@ -232,20 +232,6 @@ var AddTaskTable = &gormigrate.Migration{ }, } -var InitNodePort = &gormigrate.Migration{ - ID: "20241226-init-node-port", - Migrate: func(tx *gorm.DB) error { - var itemPort model.Setting - _ = tx.Where("key = ?", "NodePort").First(&itemPort).Error - if itemPort.ID == 0 { - if err := tx.Create(&model.Setting{Key: "NodePort", Value: "9999"}).Error; err != nil { - return err - } - } - return nil - }, -} - var InitBackup = &gormigrate.Migration{ ID: "20241226-init-backup", Migrate: func(tx *gorm.DB) error { diff --git a/core/init/migration/migrations/init.go b/core/init/migration/migrations/init.go index 5067e9448..aad4ca9ff 100644 --- a/core/init/migration/migrations/init.go +++ b/core/init/migration/migrations/init.go @@ -131,9 +131,6 @@ var InitSetting = &gormigrate.Migration{ if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil { return err } - if err := tx.Create(&model.Setting{Key: "MasterRequestAddr", Value: ""}).Error; err != nil { - return err - } if err := tx.Create(&model.Setting{Key: "BindAddress", Value: "0.0.0.0"}).Error; err != nil { return err } diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index 0f564a7ca..611b3ac0b 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -330,7 +330,8 @@ export namespace Container { } export interface DaemonJsonConf { isSwarm: boolean; - status: string; + isExist: boolean; + isActive: boolean; version: string; registryMirrors: Array; insecureRegistries: Array; diff --git a/frontend/src/components/status/index.vue b/frontend/src/components/status/index.vue index 01bb5785f..c9362fdf2 100644 --- a/frontend/src/components/status/index.vue +++ b/frontend/src/components/status/index.vue @@ -41,7 +41,7 @@ const props = defineProps({ }); const statusItem = computed(() => { - return props.status.toLowerCase() || ''; + return props.status?.toLowerCase() || ''; }); const getType = (status: string) => { diff --git a/frontend/src/views/container/setting/index.vue b/frontend/src/views/container/setting/index.vue index 406ab7524..e6a762178 100644 --- a/frontend/src/views/container/setting/index.vue +++ b/frontend/src/views/container/setting/index.vue @@ -5,20 +5,14 @@
Docker - + {{ $t('app.version') }}: {{ form.version }}
-
- +
+ {{ $t('container.stop') }} - - - {{ $t('container.restart') }} - -
-
- + {{ $t('container.start') }} @@ -270,7 +264,8 @@ const sockPathRef = ref(); const form = reactive({ isSwarm: false, - status: '', + isActive: false, + isExist: false, version: '', mirrors: '', registries: '', @@ -480,7 +475,8 @@ const changeMode = async () => { const search = async () => { const res = await loadDaemonJson(); form.isSwarm = res.data.isSwarm; - form.status = res.data.status; + form.isActive = res.data.isActive; + form.isExist = res.data.isExist; form.version = res.data.version; form.cgroupDriver = res.data.cgroupDriver || 'cgroupfs'; form.liveRestore = res.data.liveRestore;