From be46fc26dff22cafbb822991ee68e577b464fb49 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:23:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=A4=87=E4=BB=BD=E6=97=A5=E5=BF=97=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98=20(#2798)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/cornjob.go | 4 +- backend/app/service/cronjob_helper.go | 13 ++++++- frontend/src/components/del-dialog/index.vue | 41 +++++++++++--------- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + frontend/src/views/cronjob/index.vue | 30 +++++++++++--- frontend/src/views/cronjob/operate/index.vue | 4 +- frontend/src/views/cronjob/record/index.vue | 13 ++++++- 9 files changed, 77 insertions(+), 31 deletions(-) diff --git a/backend/app/service/cornjob.go b/backend/app/service/cornjob.go index 0c331b076..6e4744251 100644 --- a/backend/app/service/cornjob.go +++ b/backend/app/service/cornjob.go @@ -46,7 +46,7 @@ func (u *CronjobService) SearchWithPage(search dto.SearchWithPage) (int64, inter if err := copier.Copy(&item, &cronjob); err != nil { return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error()) } - if item.Type == "app" || item.Type == "website" || item.Type == "database" || item.Type == "directory" || item.Type == "snapshot" { + if hasBackup(item.Type) { backup, _ := backupRepo.Get(commonRepo.WithByID(uint(item.TargetDirID))) if len(backup.Type) != 0 { item.TargetDir = backup.Type @@ -103,7 +103,7 @@ func (u *CronjobService) CleanRecord(req dto.CronjobClean) error { if err != nil { return err } - if req.CleanData && (cronjob.Type == "app" || cronjob.Type == "database" || cronjob.Type == "website" || cronjob.Type == "directory" || cronjob.Type == "snapshot") { + if req.CleanData && hasBackup(cronjob.Type) { cronjob.RetainCopies = 0 backup, err := backupRepo.Get(commonRepo.WithByID(uint(cronjob.TargetDirID))) if err != nil { diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index eb1c9f4fb..903d3b621 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -677,9 +677,14 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T global.LOG.Debug("backup ssh log successful!") fileName := fmt.Sprintf("system_log_%s.tar.gz", startTime.Format("20060102150405")) - if err := handleTar(pathItem, pathItem, fileName, ""); err != nil { + targetDir := path.Dir(pathItem) + if err := handleTar(pathItem, targetDir, fileName, ""); err != nil { return "", err } + defer func() { + os.RemoveAll(pathItem) + os.RemoveAll(path.Join(targetDir, fileName)) + }() client, err := NewIBackupService().NewClient(&backup) if err != nil { @@ -691,10 +696,14 @@ func (u *CronjobService) handleSystemLog(cronjob model.Cronjob, startTime time.T targetPath = strings.TrimPrefix(backup.BackupPath, "/") + "/log/" + fileName } - if _, err = client.Upload(path.Join(pathItem, fileName), targetPath); err != nil { + if _, err = client.Upload(path.Join(targetDir, fileName), targetPath); err != nil { return "", err } u.HandleRmExpired(backup.Type, backup.BackupPath, "", &cronjob, client) return targetPath, nil } + +func hasBackup(cronjobType string) bool { + return cronjobType == "app" || cronjobType == "database" || cronjobType == "website" || cronjobType == "directory" || cronjobType == "snapshot" || cronjobType == "log" +} diff --git a/frontend/src/components/del-dialog/index.vue b/frontend/src/components/del-dialog/index.vue index f493a7ae0..262f8556e 100644 --- a/frontend/src/components/del-dialog/index.vue +++ b/frontend/src/components/del-dialog/index.vue @@ -71,28 +71,31 @@ const acceptParams = (props: DialogProps): void => { open.value = true; }; -const emit = defineEmits(['search', 'cancel']); +const emit = defineEmits(['search', 'cancel', 'submit']); const onConfirm = async () => { - if (form.api) { - loading.value = true; - await form - .api(form.params) - .then(() => { - emit('cancel'); - emit('search'); - if (successMsg.value) { - MsgSuccess(successMsg.value); - } else { - MsgSuccess(i18n.global.t('commons.msg.deleteSuccess')); - } - open.value = false; - loading.value = false; - }) - .catch(() => { - loading.value = false; - }); + if (form.api === null) { + emit('submit'); + open.value = false; + return; } + loading.value = true; + await form + .api(form.params) + .then(() => { + emit('cancel'); + emit('search'); + if (successMsg.value) { + MsgSuccess(successMsg.value); + } else { + MsgSuccess(i18n.global.t('commons.msg.deleteSuccess')); + } + open.value = false; + loading.value = false; + }) + .catch(() => { + loading.value = false; + }); }; onMounted(() => {}); diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 0748b0b81..8863f14ee 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -741,6 +741,7 @@ const message = { record: 'Records', shell: 'Shell script', log: 'Backup logs', + logHelper: 'Backup system log', ogHelper1: '1.1Panel System log ', logHelper2: '2. SSH login log of the server ', logHelper3: '3. All site logs ', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index ded2fa3f3..adf19caf1 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -713,6 +713,7 @@ const message = { record: '報告', shell: 'Shell 腳本', log: '備份日誌', + logHelper: '備份系統日誌', logHelper1: '1. 1Panel 系統日誌', logHelper2: '2. 服務器的 SSH 登錄日誌', logHelper3: '3. 所有網站日誌', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index a92f293fe..b4afffa7b 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -714,6 +714,7 @@ const message = { record: '报告', shell: 'Shell 脚本', log: '备份日志', + logHelper: '备份系统日志', logHelper1: '1. 1Panel 系统日志', logHelper2: '2. 服务器的 SSH 登录日志', logHelper3: '3. 所有网站日志', diff --git a/frontend/src/views/cronjob/index.vue b/frontend/src/views/cronjob/index.vue index b42688c8d..cd62a0287 100644 --- a/frontend/src/views/cronjob/index.vue +++ b/frontend/src/views/cronjob/index.vue @@ -135,7 +135,7 @@ - + {{ dialogData.rowData!.targetDir }} + + + + {{ $t('cronjob.logHelper') }} + +