From 71b0deddb647d5f990819ce78bbdf5053c71a155 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:00:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=9B=9E=E6=BB=9A=E6=96=87=E4=BB=B6=E6=B8=85?= =?UTF-8?q?=E7=90=86=E9=A1=B9=20(#2458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/setting_clean.go | 103 +++++++++++++++--- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/tw.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../src/views/setting/panel/clean/index.vue | 6 + 5 files changed, 94 insertions(+), 18 deletions(-) diff --git a/backend/app/service/setting_clean.go b/backend/app/service/setting_clean.go index e8914e350..67bd52c4f 100644 --- a/backend/app/service/setting_clean.go +++ b/backend/app/service/setting_clean.go @@ -61,6 +61,21 @@ func (u *SettingService) SystemScan() dto.CleanData { Children: snapTree, }) + rollBackTree := loadRollBackTree(fileOp) + rollbackSize := uint64(0) + for _, rollback := range rollBackTree { + rollbackSize += uint64(rollback.Size) + } + treeData = append(treeData, dto.CleanTree{ + ID: uuid.NewString(), + Label: "rollback", + Size: rollbackSize, + IsCheck: true, + IsRecommend: true, + Type: "rollback", + Children: rollBackTree, + }) + cachePath := path.Join(global.CONF.System.BaseDir, "1panel/cache") cacheSize, _ := fileOp.GetDirSize(cachePath) treeData = append(treeData, dto.CleanTree{ @@ -120,15 +135,34 @@ func (u *SettingService) SystemClean(req []dto.Clean) { case "snapshot_local": dropFileOrDir(path.Join(global.CONF.System.Backup, "system", item.Name)) + case "rollback": + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/app")) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/database")) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/website")) + case "rollback_app": + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/app", item.Name)) + case "rollback_database": + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/database", item.Name)) + case "rollback_website": + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/website", item.Name)) + case "cache": dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/cache", item.Name)) restart = true case "unused": - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "original", item.Name)) - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/resource/apps_bak", item.Name)) - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/download", item.Name)) - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp", item.Name)) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "original")) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/resource/apps_bak")) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/download")) + files, _ := os.ReadDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp")) + if len(files) == 0 { + continue + } + for _, file := range files { + if strings.HasPrefix(file.Name(), "upgrade_") { + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp", file.Name())) + } + } case "old_original": dropFileOrDir(path.Join(global.CONF.System.BaseDir, "original", item.Name)) case "old_apps_bak": @@ -142,7 +176,9 @@ func (u *SettingService) SystemClean(req []dto.Clean) { continue } for _, file := range files { - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp", file.Name())) + if strings.HasPrefix(file.Name(), "upgrade_") { + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp", file.Name())) + } } } else { dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp", item.Name)) @@ -150,6 +186,11 @@ func (u *SettingService) SystemClean(req []dto.Clean) { case "upload": dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/uploads", item.Name)) + if len(item.Name) == 0 { + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/upload")) + } + case "upload_tmp": + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/tmp/upload", item.Name)) case "upload_app": dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/uploads/app", item.Name)) case "upload_database": @@ -159,15 +200,15 @@ func (u *SettingService) SystemClean(req []dto.Clean) { case "upload_directory": dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/uploads/directory", item.Name)) case "download": - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/downloads", item.Name)) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/download", item.Name)) case "download_app": - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/downloads/app", item.Name)) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/download/app", item.Name)) case "download_database": - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/downloads/database", item.Name)) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/download/database", item.Name)) case "download_website": - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/downloads/website", item.Name)) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/download/website", item.Name)) case "download_directory": - dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/downloads/directory", item.Name)) + dropFileOrDir(path.Join(global.CONF.System.BaseDir, "1panel/download/directory", item.Name)) case "system_log": if len(item.Name) == 0 { @@ -235,6 +276,26 @@ func loadSnapshotTree(fileOp fileUtils.FileOp) []dto.CleanTree { return treeData } +func loadRollBackTree(fileOp fileUtils.FileOp) []dto.CleanTree { + var treeData []dto.CleanTree + path1 := path.Join(global.CONF.System.BaseDir, "1panel/tmp/app") + list1 := loadTreeWithAllFile(true, path1, "rollback_app", path1, fileOp) + size1, _ := fileOp.GetDirSize(path1) + treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "rollback_app", Size: uint64(size1), Children: list1, Type: "rollback_app", IsRecommend: true}) + + path2 := path.Join(global.CONF.System.BaseDir, "1panel/tmp/website") + list2 := loadTreeWithAllFile(true, path2, "rollback_website", path2, fileOp) + size2, _ := fileOp.GetDirSize(path2) + treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "rollback_website", Size: uint64(size2), Children: list2, Type: "rollback_website", IsRecommend: true}) + + path3 := path.Join(global.CONF.System.BaseDir, "1panel/tmp/database") + list3 := loadTreeWithAllFile(true, path3, "rollback_database", path3, fileOp) + size3, _ := fileOp.GetDirSize(path3) + treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "rollback_database", Size: uint64(size3), Children: list3, Type: "rollback_database", IsRecommend: true}) + + return treeData +} + func loadUnusedFile(fileOp fileUtils.FileOp) []dto.CleanTree { var treeData []dto.CleanTree path1 := path.Join(global.CONF.System.BaseDir, "original") @@ -272,23 +333,29 @@ func loadUnusedFile(fileOp fileUtils.FileOp) []dto.CleanTree { func loadUploadTree(fileOp fileUtils.FileOp) []dto.CleanTree { var treeData []dto.CleanTree - path1 := path.Join(global.CONF.System.BaseDir, "1panel/upload/app") + + path0 := path.Join(global.CONF.System.BaseDir, "1panel/tmp/upload") + list0 := loadTreeWithAllFile(true, path0, "upload_tmp", path0, fileOp) + size0, _ := fileOp.GetDirSize(path0) + treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "upload_tmp", Size: uint64(size0), Children: list0, Type: "upload_tmp", IsRecommend: true}) + + path1 := path.Join(global.CONF.System.BaseDir, "1panel/uploads/app") list1 := loadTreeWithAllFile(true, path1, "upload_app", path1, fileOp) size1, _ := fileOp.GetDirSize(path1) treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "upload_app", Size: uint64(size1), Children: list1, Type: "upload_app", IsRecommend: true}) - path2 := path.Join(global.CONF.System.BaseDir, "1panel/upload/website") + path2 := path.Join(global.CONF.System.BaseDir, "1panel/uploads/website") list2 := loadTreeWithAllFile(true, path2, "upload_website", path2, fileOp) size2, _ := fileOp.GetDirSize(path2) treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "upload_website", Size: uint64(size2), Children: list2, Type: "upload_website", IsRecommend: true}) - path3 := path.Join(global.CONF.System.BaseDir, "1panel/upload/database") - list3 := loadTreeWithAllFile(true, path3, "upload_app", path3, fileOp) + path3 := path.Join(global.CONF.System.BaseDir, "1panel/uploads/database") + list3 := loadTreeWithAllFile(true, path3, "upload_database", path3, fileOp) size3, _ := fileOp.GetDirSize(path3) treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "upload_database", Size: uint64(size3), Children: list3, Type: "upload_database", IsRecommend: true}) - path4 := path.Join(global.CONF.System.BaseDir, "1panel/upload/directory") - list4 := loadTreeWithAllFile(true, path4, "upload_app", path4, fileOp) + path4 := path.Join(global.CONF.System.BaseDir, "1panel/uploads/directory") + list4 := loadTreeWithAllFile(true, path4, "upload_directory", path4, fileOp) size4, _ := fileOp.GetDirSize(path4) treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "upload_directory", Size: uint64(size4), Children: list4, Type: "upload_directory", IsRecommend: true}) @@ -312,12 +379,12 @@ func loadDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree { treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "download_website", Size: uint64(size2), Children: list2, Type: "download_website", IsRecommend: true}) path3 := path.Join(global.CONF.System.BaseDir, "1panel/download/database") - list3 := loadTreeWithAllFile(true, path3, "download_app", path3, fileOp) + list3 := loadTreeWithAllFile(true, path3, "download_database", path3, fileOp) size3, _ := fileOp.GetDirSize(path3) treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "download_database", Size: uint64(size3), Children: list3, Type: "download_database", IsRecommend: true}) path4 := path.Join(global.CONF.System.BaseDir, "1panel/download/directory") - list4 := loadTreeWithAllFile(true, path4, "download_app", path4, fileOp) + list4 := loadTreeWithAllFile(true, path4, "download_directory", path4, fileOp) size4, _ := fileOp.GetDirSize(path4) treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "download_directory", Size: uint64(size4), Children: list4, Type: "download_directory", IsRecommend: true}) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 1cc668a61..0ae884215 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1240,6 +1240,7 @@ const message = { snapshot: 'System snapshot temporary files', snapshotTmp: 'System snapshot upload temporary files', snapshotLocal: 'System snapshot creation temporary files', + rollback: 'Backup files before recover', unused: 'Unused system directories', oldUpgrade: 'Unused pre-upgrade backup directories', oldOriginal: 'Unused pre-snapshot recovery backup directories', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 187e74af8..951a352d2 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1178,6 +1178,7 @@ const message = { snapshot: '系統快照臨時文件', snapshotTmp: '系統快照上傳臨時文件', snapshotLocal: '系統快照製作臨時文件', + rollback: '恢復前備份目錄', unused: '系統廢棄目錄', oldUpgrade: '廢棄升級前備份目錄', oldOriginal: '廢棄快照恢復前備份目錄', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 33af9a461..c49010d96 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1177,6 +1177,7 @@ const message = { snapshot: '系统快照临时文件', snapshotTmp: '系统快照上传临时文件', snapshotLocal: '系统快照制作临时文件', + rollback: '恢复前备份目录', unused: '系统废弃目录', oldUpgrade: '废弃升级前备份目录', oldOriginal: '废弃快照恢复前备份目录', diff --git a/frontend/src/views/setting/panel/clean/index.vue b/frontend/src/views/setting/panel/clean/index.vue index 32d1cc2ff..51f27963f 100644 --- a/frontend/src/views/setting/panel/clean/index.vue +++ b/frontend/src/views/setting/panel/clean/index.vue @@ -479,6 +479,8 @@ function load18n(label: string) { return i18n.global.t('clean.snapshotTmp'); case 'snapshot_local': return i18n.global.t('clean.snapshotLocal'); + case 'rollback': + return i18n.global.t('clean.rollback'); case 'unused': return i18n.global.t('clean.unused'); case 'old_original': @@ -488,16 +490,20 @@ function load18n(label: string) { case 'old_upgrade': return i18n.global.t('clean.oldUpgrade'); case 'upload': + case 'upload_tmp': return i18n.global.t('clean.upload'); case 'download': return i18n.global.t('clean.download'); case 'upload_website': + case 'rollback_website': case 'download_website': return i18n.global.t('clean.website'); case 'upload_app': + case 'rollback_app': case 'download_app': return i18n.global.t('clean.app'); case 'upload_database': + case 'rollback_database': case 'download_database': return i18n.global.t('clean.database'); case 'upload_directory':