From c61e2cb1913c9a6e650156c2a93425823d39dbd1 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Thu, 1 Dec 2022 19:25:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/app_install.go | 16 ++++++ backend/app/dto/app.go | 5 ++ backend/app/repo/app_install_resource.go | 6 +++ backend/app/service/app_install.go | 52 ++++++++++++++++++ backend/app/service/app_utils.go | 4 ++ backend/router/ro_app.go | 1 + frontend/src/api/interface/app.ts | 5 ++ frontend/src/api/modules/app.ts | 4 ++ frontend/src/components/app-status/index.vue | 12 ++--- frontend/src/lang/modules/zh.ts | 4 ++ .../views/app-store/installed/check/index.vue | 54 +++++++++++++++++++ .../src/views/app-store/installed/index.vue | 20 ++++++- 12 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 frontend/src/views/app-store/installed/check/index.vue diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index ab286213c..3ea662736 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -53,6 +53,22 @@ func (b *BaseApi) CheckAppInstalled(c *gin.Context) { helper.SuccessWithData(c, checkData) } +func (b *BaseApi) DeleteCheck(c *gin.Context) { + + appInstallId, err := helper.GetIntParamByKey(c, "appInstallId") + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil) + return + } + + checkData, err := appInstallService.DeleteCheck(appInstallId) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, checkData) +} + func (b *BaseApi) SyncInstalled(c *gin.Context) { if err := appInstallService.SyncAll(); err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index 74003aaa9..ebb0e8689 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -177,3 +177,8 @@ type AppFormFields struct { Default string `json:"default"` EnvKey string `json:"env_variable"` } + +type AppResource struct { + Type string `json:"type"` + Name string `json:"name"` +} diff --git a/backend/app/repo/app_install_resource.go b/backend/app/repo/app_install_resource.go index 6f9441b37..4a0198a18 100644 --- a/backend/app/repo/app_install_resource.go +++ b/backend/app/repo/app_install_resource.go @@ -17,6 +17,12 @@ func (a AppInstallResourceRpo) WithAppInstallId(appInstallId uint) DBOption { } } +func (a AppInstallResourceRpo) WithLinkId(linkId uint) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("link_id = ?", linkId) + } +} + func (a AppInstallResourceRpo) GetBy(opts ...DBOption) ([]model.AppInstallResource, error) { db := global.DB.Model(&model.AppInstallResource{}) var resources []model.AppInstallResource diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index ad15192a5..3a8c2f97e 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -295,6 +295,58 @@ func (a AppInstallService) ChangeAppPort(req dto.PortUpdate) error { return nil } +func (a AppInstallService) DeleteCheck(installId uint) ([]dto.AppResource, error) { + var res []dto.AppResource + appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId)) + if err != nil { + return nil, err + } + app, err := appRepo.GetFirst(commonRepo.WithByID(appInstall.AppId)) + if err != nil { + return nil, err + } + if app.Type == "website" { + websites, _ := websiteRepo.GetBy(websiteRepo.WithAppInstallId(appInstall.ID)) + for _, website := range websites { + res = append(res, dto.AppResource{ + Type: "website", + Name: website.PrimaryDomain, + }) + } + } + if app.Key == "nginx" { + websites, _ := websiteRepo.GetBy() + for _, website := range websites { + res = append(res, dto.AppResource{ + Type: "website", + Name: website.PrimaryDomain, + }) + } + } + if app.Type == "runtime" { + resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithLinkId(appInstall.ID)) + for _, resource := range resources { + linkInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(resource.AppInstallId)) + res = append(res, dto.AppResource{ + Type: "app", + Name: linkInstall.Name, + }) + } + } + + if app.Key == "mysql" { + databases, _ := mysqlRepo.List() + for _, database := range databases { + res = append(res, dto.AppResource{ + Type: "database", + Name: database.Name, + }) + } + } + + return res, nil +} + func syncById(installId uint) error { appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId)) if err != nil { diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 06ff64e68..0c068f472 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -175,6 +175,10 @@ func deleteAppInstall(ctx context.Context, install model.AppInstall) error { if err := deleteLink(ctx, &install); err != nil { return err } + backups, _ := appInstallBackupRepo.GetBy(appInstallBackupRepo.WithAppInstallID(install.ID)) + for _, backup := range backups { + _ = op.DeleteDir(backup.Path) + } if err := appInstallBackupRepo.Delete(ctx, appInstallBackupRepo.WithAppInstallID(install.ID)); err != nil { return err } diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index e39b137d1..d45b27c2c 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -22,6 +22,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { appRouter.POST("/install", baseApi.InstallApp) appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions) appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled) + appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck) appRouter.POST("/installed", baseApi.SearchAppInstalled) appRouter.POST("/installed/op", baseApi.OperateInstalled) appRouter.POST("/installed/sync", baseApi.SyncInstalled) diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 0fb9d08e9..e142a030b 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -98,6 +98,11 @@ export namespace App { containerName: string; } + export interface AppInstallResource { + type: string; + name: string; + } + export interface AppInstalledOp { installId: number; operate: string; diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index a299e5ff7..bcf864397 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -34,6 +34,10 @@ export const CheckAppInstalled = (key: string) => { return http.get(`apps/installed/check/${key}`); }; +export const AppInstalledDeleteCheck = (appInstallId: number) => { + return http.get(`apps/installed/delete/check/${appInstallId}`); +}; + export const GetAppInstalled = (search: App.AppInstalledSearch) => { return http.post('apps/installed', search); }; diff --git a/frontend/src/components/app-status/index.vue b/frontend/src/components/app-status/index.vue index 863f9f0bb..8195602f7 100644 --- a/frontend/src/components/app-status/index.vue +++ b/frontend/src/components/app-status/index.vue @@ -3,31 +3,31 @@
- +
{{ data.app }}
- +
{{ $t('app.version') }}: {{ data.version }}
- +
{{ $t('commons.table.status') }}: {{ data.status }}
- +
{{ $t('website.lastBackupAt') }}: {{ data.lastBackupAt }} - {{ $t('website.null') }} + {{ $t('website.null') }}
- + {{ $t('app.restart') }} {{ $t('commons.button.set') }} diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index d92695ee5..da3abb20a 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -733,6 +733,10 @@ export default { gotoInstalled: '去安装', search: '搜索', limitHelper: '该应用已安装,不支持重复安装', + deleteHelper: '应用已经关联以下资源,无法删除', + checkTitle: '提示', + website: '网站', + database: '数据库', }, website: { website: '网站', diff --git a/frontend/src/views/app-store/installed/check/index.vue b/frontend/src/views/app-store/installed/check/index.vue new file mode 100644 index 000000000..615c47eb4 --- /dev/null +++ b/frontend/src/views/app-store/installed/check/index.vue @@ -0,0 +1,54 @@ + + diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 6d231639a..e75abac94 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -104,17 +104,25 @@ +