Skip to content

Commit d6b21f4

Browse files
authored
fix: remove duplicate code (#7763)
1 parent e66eb00 commit d6b21f4

File tree

9 files changed

+15
-36
lines changed

9 files changed

+15
-36
lines changed

agent/app/repo/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (u *BackupRepo) GetRecord(opts ...DBOption) (*model.BackupRecord, error) {
159159

160160
func (u *BackupRepo) SyncAll(data []model.BackupAccount) error {
161161
tx := global.DB.Begin()
162-
if err := tx.Where("1 = 1").Delete(&model.BackupAccount{}).Error; err != nil {
162+
if err := tx.Where("is_public = ?", 1).Delete(&model.BackupAccount{}).Error; err != nil {
163163
tx.Rollback()
164164
return err
165165
}

agent/app/service/clam.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,7 @@ func handleAlert(stdout, clamName string, clamId uint) {
635635
lines := strings.Split(stdout, "\n")
636636
for _, line := range lines {
637637
if strings.HasPrefix(line, "Infected files: ") {
638-
var infectedFiles = 0
639-
infectedFiles, _ = strconv.Atoi(strings.TrimPrefix(line, "Infected files: "))
638+
infectedFiles, _ := strconv.Atoi(strings.TrimPrefix(line, "Infected files: "))
640639
if infectedFiles > 0 {
641640
pushAlert := dto.PushAlert{
642641
TaskName: clamName,

agent/app/service/docker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
7070
var data dto.DaemonJsonConf
7171
data.IPTables = true
7272
data.Version = "-"
73-
if cmd.Which("docker") {
73+
if !cmd.Which("docker") {
7474
data.IsExist = false
7575
return &data
7676
}
7777
data.IsExist = true
78+
data.IsActive = true
7879
client, err := docker.NewDockerClient()
7980
if err != nil {
8081
data.IsActive = false

agent/init/migration/migrate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func InitAgentDB() {
2121
migrations.InitImageRepo,
2222
migrations.InitDefaultCA,
2323
migrations.InitPHPExtensions,
24-
migrations.InitNodePort,
2524
migrations.InitBackup,
2625
})
2726
if err := m.Migrate(); err != nil {

agent/init/migration/migrations/init.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,6 @@ var AddTaskTable = &gormigrate.Migration{
232232
},
233233
}
234234

235-
var InitNodePort = &gormigrate.Migration{
236-
ID: "20241226-init-node-port",
237-
Migrate: func(tx *gorm.DB) error {
238-
var itemPort model.Setting
239-
_ = tx.Where("key = ?", "NodePort").First(&itemPort).Error
240-
if itemPort.ID == 0 {
241-
if err := tx.Create(&model.Setting{Key: "NodePort", Value: "9999"}).Error; err != nil {
242-
return err
243-
}
244-
}
245-
return nil
246-
},
247-
}
248-
249235
var InitBackup = &gormigrate.Migration{
250236
ID: "20241226-init-backup",
251237
Migrate: func(tx *gorm.DB) error {

core/init/migration/migrations/init.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ var InitSetting = &gormigrate.Migration{
131131
if err := tx.Create(&model.Setting{Key: "SystemStatus", Value: "Free"}).Error; err != nil {
132132
return err
133133
}
134-
if err := tx.Create(&model.Setting{Key: "MasterRequestAddr", Value: ""}).Error; err != nil {
135-
return err
136-
}
137134
if err := tx.Create(&model.Setting{Key: "BindAddress", Value: "0.0.0.0"}).Error; err != nil {
138135
return err
139136
}

frontend/src/api/interface/container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ export namespace Container {
330330
}
331331
export interface DaemonJsonConf {
332332
isSwarm: boolean;
333-
status: string;
333+
isExist: boolean;
334+
isActive: boolean;
334335
version: string;
335336
registryMirrors: Array<string>;
336337
insecureRegistries: Array<string>;

frontend/src/components/status/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const props = defineProps({
4141
});
4242
4343
const statusItem = computed(() => {
44-
return props.status.toLowerCase() || '';
44+
return props.status?.toLowerCase() || '';
4545
});
4646
4747
const getType = (status: string) => {

frontend/src/views/container/setting/index.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
<div class="flex w-full flex-col gap-4 md:flex-row">
66
<div class="flex flex-wrap gap-4">
77
<el-tag class="float-left" effect="dark" type="success">Docker</el-tag>
8-
<Status class="mt-0.5" :status="form.status" />
8+
<Status class="mt-0.5" :status="form.isActive ? 'enable' : 'disable'" />
99
<el-tag>{{ $t('app.version') }}: {{ form.version }}</el-tag>
1010
</div>
11-
<div class="mt-0.5" v-if="form.status === 'Running'">
12-
<el-button type="primary" @click="onOperator('stop')" link>
11+
<div class="mt-0.5">
12+
<el-button v-if="form.isActive" type="primary" @click="onOperator('stop')" link>
1313
{{ $t('container.stop') }}
1414
</el-button>
15-
<el-divider direction="vertical" />
16-
<el-button type="primary" @click="onOperator('restart')" link>
17-
{{ $t('container.restart') }}
18-
</el-button>
19-
</div>
20-
<div class="mt-0.5" v-if="form.status === 'Stopped'">
21-
<el-button type="primary" @click="onOperator('start')" link>
15+
<el-button v-if="!form.isActive" type="primary" @click="onOperator('start')" link>
2216
{{ $t('container.start') }}
2317
</el-button>
2418
<el-divider direction="vertical" />
@@ -270,7 +264,8 @@ const sockPathRef = ref();
270264
271265
const form = reactive({
272266
isSwarm: false,
273-
status: '',
267+
isActive: false,
268+
isExist: false,
274269
version: '',
275270
mirrors: '',
276271
registries: '',
@@ -480,7 +475,8 @@ const changeMode = async () => {
480475
const search = async () => {
481476
const res = await loadDaemonJson();
482477
form.isSwarm = res.data.isSwarm;
483-
form.status = res.data.status;
478+
form.isActive = res.data.isActive;
479+
form.isExist = res.data.isExist;
484480
form.version = res.data.version;
485481
form.cgroupDriver = res.data.cgroupDriver || 'cgroupfs';
486482
form.liveRestore = res.data.liveRestore;

0 commit comments

Comments
 (0)