From eefec2560c5e224be67eafc410dc623e8e92aa0f Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Mon, 13 Feb 2023 11:38:09 +0400 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=96=E6=B6=88=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app.go | 21 ++++++++++++++------- backend/init/business/business.go | 8 ++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 352a075d3..4e90c8dd2 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -25,6 +25,20 @@ import ( type AppService struct { } +type IAppService interface { + PageApp(req request.AppSearch) (interface{}, error) + GetAppTags() ([]response.TagDTO, error) + GetApp(key string) (*response.AppDTO, error) + GetAppDetail(appId uint, version string) (response.AppDetailDTO, error) + Install(ctx context.Context, req request.AppInstallCreate) (*model.AppInstall, error) + SyncInstalled(installId uint) error + SyncAppList() error +} + +func NewIAppService() IAppService { + return &AppService{} +} + func (a AppService) PageApp(req request.AppSearch) (interface{}, error) { var opts []repo.DBOption opts = append(opts, appRepo.OrderByRecommend()) @@ -131,7 +145,6 @@ func (a AppService) GetAppDetail(appId uint, version string) (response.AppDetail appDetailDTO response.AppDetailDTO opts []repo.DBOption ) - opts = append(opts, appDetailRepo.WithAppId(appId), appDetailRepo.WithVersion(version)) detail, err := appDetailRepo.GetFirst(opts...) if err != nil { @@ -152,7 +165,6 @@ func (a AppService) GetAppDetail(appId uint, version string) (response.AppDetail if err := checkLimit(app); err != nil { appDetailDTO.Enable = false } - return appDetailDTO, nil } @@ -160,7 +172,6 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) ( if list, _ := appInstallRepo.ListBy(commonRepo.WithByName(req.Name)); len(list) > 0 { return nil, buserr.New(constant.ErrNameIsExist) } - httpPort, err := checkPort("PANEL_APP_PORT_HTTP", req.Params) if err != nil { return nil, err @@ -169,7 +180,6 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) ( if err != nil { return nil, err } - appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(req.AppDetailId)) if err != nil { return nil, err @@ -178,14 +188,12 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) ( if err != nil { return nil, err } - if err := checkRequiredAndLimit(app); err != nil { return nil, err } if err := copyAppData(app.Key, appDetail.Version, req.Name, req.Params); err != nil { return nil, err } - paramByte, err := json.Marshal(req.Params) if err != nil { return nil, err @@ -201,7 +209,6 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) ( HttpsPort: httpsPort, App: app, } - composeMap := make(map[string]interface{}) if err := yaml.Unmarshal([]byte(appDetail.DockerCompose), &composeMap); err != nil { return nil, err diff --git a/backend/init/business/business.go b/backend/init/business/business.go index e6e6cd3c3..6e8ffa570 100644 --- a/backend/init/business/business.go +++ b/backend/init/business/business.go @@ -3,9 +3,17 @@ package business import ( "github.com/1Panel-dev/1Panel/backend/app/service" "github.com/1Panel-dev/1Panel/backend/global" + "github.com/1Panel-dev/1Panel/backend/utils/common" ) func Init() { + setting, err := service.NewISettingService().GetSettingInfo() + if err != nil { + global.LOG.Errorf("sync app error: %s", err.Error()) + } + if common.CompareVersion(setting.AppStoreVersion, "0.0") { + return + } appService := service.AppService{} if err := appService.SyncAppList(); err != nil { global.LOG.Errorf("sync app error: %s", err.Error())