diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index d2fc64d4a..74003aaa9 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -23,6 +23,7 @@ type AppDTO struct { type AppDetailDTO struct { model.AppDetail + Enable bool `json:"enable"` Params interface{} `json:"params"` } diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 06a0321d9..a61286567 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -124,6 +124,16 @@ func (a AppService) GetAppDetail(appId uint, version string) (dto.AppDetailDTO, _ = json.Unmarshal([]byte(detail.Params), ¶mMap) appDetailDTO.AppDetail = detail appDetailDTO.Params = paramMap + appDetailDTO.Enable = true + + app, err := appRepo.GetFirst(commonRepo.WithByID(detail.AppId)) + if err != nil { + return appDetailDTO, err + } + if err := checkLimit(app); err != nil { + appDetailDTO.Enable = false + } + return appDetailDTO, nil } diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index ca9cf07e5..d0a7c2445 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -347,17 +347,24 @@ func getContainerNames(install model.AppInstall) ([]string, error) { return containerNames, nil } -func checkRequiredAndLimit(app model.App) error { - +func checkLimit(app model.App) error { if app.Limit > 0 { installs, err := appInstallRepo.GetBy(appInstallRepo.WithAppId(app.ID)) if err != nil { return err } if len(installs) >= app.Limit { - return errors.New(fmt.Sprintf("app install limit %d", app.Limit)) + return buserr.New(constant.ErrAppLimit, "", nil) } } + return nil +} + +func checkRequiredAndLimit(app model.App) error { + + if err := checkLimit(app); err != nil { + return err + } if app.Required != "" { var requiredArray []string @@ -383,7 +390,7 @@ func checkRequiredAndLimit(app model.App) error { _, err = appInstallRepo.GetFirst(appInstallRepo.WithDetailIdsIn(detailIds)) if err != nil { - return errors.New(fmt.Sprintf("%s is required", requireApp.Key)) + return buserr.New(constant.ErrAppRequired, requireApp.Name, nil) } } } diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 29c07ab57..b88f07027 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -44,5 +44,7 @@ var ( // app var ( - ErrPortInUsed = "ErrPortInUsed" + ErrPortInUsed = "ErrPortInUsed" + ErrAppLimit = "ErrAppLimit" + ErrAppRequired = "ErrAppRequired" ) diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index c88d2b11e..b43907edf 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -15,4 +15,6 @@ ErrNotSupportType: "The system does not support the current type: {{ .detail }}" #app -ErrPortInUsed: "{{ .detail }} 端口已被占用" \ No newline at end of file +ErrPortInUsed: "{{ .detail }} port already in use" +ErrAppLimit: "App exceeds install limit" +ErrAppRequired: "{{ .detail }} app is required" \ No newline at end of file diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index 802c8f67e..2b46baeaf 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -16,3 +16,5 @@ ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}" #app ErrPortInUsed: "{{ .detail }} 已被占用!" +ErrAppLimit: "应用超出安装数量限制" +ErrAppRequired: "请先安装 {{ .detail }} 应用" \ No newline at end of file diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 73cfe20c0..0fb9d08e9 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -36,6 +36,7 @@ export namespace App { readme: string; params: AppParams; dockerCompose: string; + enbale: boolean; } export interface AppReq extends ReqPage { diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 1f3b98412..d92695ee5 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -732,6 +732,7 @@ export default { checkInstalledWarn: '未检测到 {0} ,请进入应用商店点击安装!', gotoInstalled: '去安装', search: '搜索', + limitHelper: '该应用已安装,不支持重复安装', }, website: { website: '网站', diff --git a/frontend/src/views/app-store/detail/index.vue b/frontend/src/views/app-store/detail/index.vue index 21bd91cfa..62ef5c1b3 100644 --- a/frontend/src/views/app-store/detail/index.vue +++ b/frontend/src/views/app-store/detail/index.vue @@ -42,7 +42,21 @@ {{ app.author }}
- {{ $t('app.install') }} + + {{ $t('app.install') }} + +
+
+
+ +