From 53cfb2e755d01431e7a717dc9a8715b392090972 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:37:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?Web=20=E8=AE=BF=E9=97=AE=E5=9C=B0=E5=9D=80=20(#6248)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/app/api/v2/app_install.go | 21 ++++++++ agent/app/dto/request/app.go | 7 +++ agent/app/dto/response/app.go | 1 + agent/app/model/app_install.go | 5 +- agent/app/service/app_install.go | 15 ++++++ agent/app/service/app_utils.go | 1 + agent/init/migration/migrate.go | 1 + agent/init/migration/migrations/init.go | 8 +++ agent/router/ro_app.go | 1 + frontend/src/api/interface/app.ts | 7 +++ frontend/src/api/modules/app.ts | 4 ++ frontend/src/lang/modules/en.ts | 2 + frontend/src/lang/modules/tw.ts | 2 + frontend/src/lang/modules/zh.ts | 2 + .../app-store/installed/detail/index.vue | 50 ++++++++++++++++--- .../src/views/app-store/installed/index.vue | 20 ++++++++ 16 files changed, 137 insertions(+), 10 deletions(-) diff --git a/agent/app/api/v2/app_install.go b/agent/app/api/v2/app_install.go index 4d6bc8c98..172656f80 100644 --- a/agent/app/api/v2/app_install.go +++ b/agent/app/api/v2/app_install.go @@ -325,3 +325,24 @@ func (b *BaseApi) IgnoreUpgrade(c *gin.Context) { } helper.SuccessWithOutData(c) } + +// @Tags App +// @Summary Update app config +// @Description 更新应用配置 +// @Accept json +// @Param request body request.AppConfigUpdate true "request" +// @Success 200 +// @Security ApiKeyAuth +// @Router /apps/installed/config/update [post] +// @x-panel-log {"bodyKeys":["installID","webUI"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"应用配置更新 [installID]","formatEN":"Application config update [installID]"} +func (b *BaseApi) UpdateAppConfig(c *gin.Context) { + var req request.AppConfigUpdate + if err := helper.CheckBindAndValidate(&req, c); err != nil { + return + } + if err := appInstallService.UpdateAppConfig(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithOutData(c) +} diff --git a/agent/app/dto/request/app.go b/agent/app/dto/request/app.go index 47b5fc0fb..465d2c812 100644 --- a/agent/app/dto/request/app.go +++ b/agent/app/dto/request/app.go @@ -37,6 +37,8 @@ type AppContainerConfig struct { HostMode bool `json:"hostMode"` PullImage bool `json:"pullImage"` GpuConfig bool `json:"gpuConfig"` + WebUI string `json:"webUI"` + Type string `json:"type"` } type AppInstalledSearch struct { @@ -103,6 +105,11 @@ type AppInstalledUpdate struct { AppContainerConfig } +type AppConfigUpdate struct { + InstallID uint `json:"installID" validate:"required"` + WebUI string `json:"webUI"` +} + type AppInstalledIgnoreUpgrade struct { DetailID uint `json:"detailID" validate:"required"` Operate string `json:"operate" validate:"required,oneof=cancel ignore"` diff --git a/agent/app/dto/response/app.go b/agent/app/dto/response/app.go index 664e0061f..a0c1e19ff 100644 --- a/agent/app/dto/response/app.go +++ b/agent/app/dto/response/app.go @@ -120,6 +120,7 @@ type AppInstallDTO struct { AppType string `json:"appType"` AppStatus string `json:"appStatus"` DockerCompose string `json:"dockerCompose"` + WebUI string `json:"webUI"` CreatedAt time.Time `json:"createdAt"` App AppDetail `json:"app"` } diff --git a/agent/app/model/app_install.go b/agent/app/model/app_install.go index 1a88b781b..d753003b0 100644 --- a/agent/app/model/app_install.go +++ b/agent/app/model/app_install.go @@ -21,8 +21,9 @@ type AppInstall struct { Message string `json:"message"` ContainerName string `json:"containerName" gorm:"not null"` ServiceName string `json:"serviceName" gorm:"not null"` - HttpPort int `json:"httpPort" gorm:"not null"` - HttpsPort int `json:"httpsPort" gorm:"not null"` + HttpPort int `json:"httpPort"` + HttpsPort int `json:"httpsPort"` + WebUI string `json:"webUI"` App App `json:"app" gorm:"-:migration"` } diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index eb28a5263..bd44c7504 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -59,6 +59,7 @@ type IAppInstallService interface { GetDefaultConfigByKey(key, name string) (string, error) DeleteCheck(installId uint) ([]dto.AppResource, error) + UpdateAppConfig(req request.AppConfigUpdate) error GetInstallList() ([]dto.AppInstallInfo, error) } @@ -304,6 +305,18 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error { } } +func (a *AppInstallService) UpdateAppConfig(req request.AppConfigUpdate) error { + installed, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallID)) + if err != nil { + return err + } + installed.WebUI = "" + if req.WebUI != "" { + installed.WebUI = req.WebUI + } + return appInstallRepo.Save(context.Background(), &installed) +} + func (a *AppInstallService) Update(req request.AppInstalledUpdate) error { installed, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId)) if err != nil { @@ -767,6 +780,8 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) { } res.AppContainerConfig = config res.HostMode = isHostModel(install.DockerCompose) + res.WebUI = install.WebUI + res.Type = install.App.Type return &res, nil } diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index 918b798f9..4005c7f74 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -1363,6 +1363,7 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) AppType: installed.App.Type, Path: installed.GetPath(), CreatedAt: installed.CreatedAt, + WebUI: installed.WebUI, App: response.AppDetail{ Github: installed.App.Github, Website: installed.App.Website, diff --git a/agent/init/migration/migrate.go b/agent/init/migration/migrate.go index bf5d3e3c4..54f693f19 100644 --- a/agent/init/migration/migrate.go +++ b/agent/init/migration/migrate.go @@ -20,6 +20,7 @@ func Init() { migrations.UpdateWebsiteDomain, migrations.UpdateApp, migrations.AddTaskDB, + migrations.UpdateAppInstall, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/agent/init/migration/migrations/init.go b/agent/init/migration/migrations/init.go index e48c41285..8e09ccc82 100644 --- a/agent/init/migration/migrations/init.go +++ b/agent/init/migration/migrations/init.go @@ -251,3 +251,11 @@ var UpdateApp = &gormigrate.Migration{ &model.App{}) }, } + +var UpdateAppInstall = &gormigrate.Migration{ + ID: "20240828-update-app-install", + Migrate: func(tx *gorm.DB) error { + return tx.AutoMigrate( + &model.AppInstall{}) + }, +} diff --git a/agent/router/ro_app.go b/agent/router/ro_app.go index 1d8bf9685..41797bea8 100644 --- a/agent/router/ro_app.go +++ b/agent/router/ro_app.go @@ -38,5 +38,6 @@ func (a *AppRouter) InitRouter(Router *gin.RouterGroup) { appRouter.POST("/installed/ignore", baseApi.IgnoreUpgrade) appRouter.GET("/ignored/detail", baseApi.GetIgnoredApp) appRouter.POST("/installed/update/versions", baseApi.GetUpdateVersions) + appRouter.POST("/installed/config/update", baseApi.UpdateAppConfig) } } diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 699961bbb..3cdb31381 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -239,6 +239,8 @@ export namespace App { allowPort: boolean; dockerCompose: string; hostMode?: boolean; + type: string; + webUI: string; } export interface IgnoredApp { @@ -256,4 +258,9 @@ export namespace App { export interface AppStoreSync { taskID: string; } + + export interface AppConfigUpdate { + installID: number; + webUI: string; + } } diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index e5a3f6378..7b271ecba 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -106,3 +106,7 @@ export const IgnoreUpgrade = (req: any) => { export const GetIgnoredApp = () => { return http.get(`apps/ignored/detail`); }; + +export const UpdateInstallConfig = (req: App.AppConfigUpdate) => { + return http.post(`apps/installed/config/update`, req); +}; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index c5ae5412f..4d64924c0 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1883,6 +1883,8 @@ const message = { gpuConfig: 'Enable GPU Support', gpuConfigHelper: 'Please ensure the machine has an NVIDIA GPU and that NVIDIA drivers and the NVIDIA Docker Container Toolkit are installed', + webUI: 'Web Access Address', + webUIPlaceholder: 'For example: http://example.com:8080/login', }, website: { website: 'Website', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 86f9498a0..93718d475 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1748,6 +1748,8 @@ const message = { memoryRequiredHelper: '目前應用記憶體需求 {0}', gpuConfig: '開啟 GPU 支援', gpuConfigHelper: '請確保機器有 NVIDIA GPU 並且安裝 NVIDIA 驅動 和 NVIDIA docker Container Toolkit', + webUI: 'Web 訪問地址', + webUIPlaceholder: '例如:http://example.com:8080/login', }, website: { website: '網站', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index e3975ef4f..b1a79ebc8 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1749,6 +1749,8 @@ const message = { memoryRequiredHelper: '当前应用内存需求 {0}', gpuConfig: '开启 GPU 支持', gpuConfigHelper: '请确保机器有 NVIDIA GPU 并且安装 NVIDIA 驱动 和 NVIDIA docker Container Toolkit', + webUI: 'Web 访问地址', + webUIPlaceholder: '例如:http://example.com:8080/login', }, website: { website: '网站', diff --git a/frontend/src/views/app-store/installed/detail/index.vue b/frontend/src/views/app-store/installed/detail/index.vue index ddfaaa224..87d6ea938 100644 --- a/frontend/src/views/app-store/installed/detail/index.vue +++ b/frontend/src/views/app-store/installed/detail/index.vue @@ -5,15 +5,29 @@ {{ edit ? $t('app.detail') : $t('commons.button.edit') }} - - - {{ param.showValue && param.showValue != '' ? param.showValue : param.value }} - - - +
+ + + {{ param.showValue && param.showValue != '' ? param.showValue : param.value }} + + + + + + + + + {{ $t('commons.button.confirm') }} + + + +
+ + +
diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 548c059d3..1cf77edcf 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -175,6 +175,22 @@ + + + + + + + { } }; +const toLink = (link: string) => { + window.open(link, '_blank'); +}; + onMounted(() => { const path = router.currentRoute.value.path; if (path == '/apps/upgrade') {