From 8e4b162b5975ef32ae4bd5a5dece76f9bf162247 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:54:09 +0800 Subject: [PATCH] feat(website): Fix Issue with Creating Reverse Proxy Website (#7633) --- agent/app/repo/app.go | 7 +++++- agent/app/repo/common.go | 6 +++++ agent/app/service/app.go | 26 +++++++++++++++++++++- agent/app/service/website_utils.go | 12 +++++----- frontend/src/components/log-file/index.vue | 5 +---- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/agent/app/repo/app.go b/agent/app/repo/app.go index dfa5b4b48..853e94528 100644 --- a/agent/app/repo/app.go +++ b/agent/app/repo/app.go @@ -32,6 +32,7 @@ type IAppRepo interface { Save(ctx context.Context, app *model.App) error BatchDelete(ctx context.Context, apps []model.App) error DeleteByIDs(ctx context.Context, ids []uint) error + DeleteBy(opts ...DBOption) error } func NewIAppRepo() IAppRepo { @@ -79,7 +80,7 @@ func (a AppRepo) WithResource(resource string) DBOption { func (a AppRepo) WithNotLocal() DBOption { return func(g *gorm.DB) *gorm.DB { - return g.Where("resource != local") + return g.Where("resource != 'local'") } } @@ -149,3 +150,7 @@ func (a AppRepo) BatchDelete(ctx context.Context, apps []model.App) error { func (a AppRepo) DeleteByIDs(ctx context.Context, ids []uint) error { return getTx(ctx).Where("id in (?)", ids).Delete(&model.App{}).Error } + +func (a AppRepo) DeleteBy(opts ...DBOption) error { + return getDb().Delete(&model.App{}, opts).Error +} diff --git a/agent/app/repo/common.go b/agent/app/repo/common.go index ce9365430..2a9127926 100644 --- a/agent/app/repo/common.go +++ b/agent/app/repo/common.go @@ -24,6 +24,12 @@ func WithByIDs(ids []uint) DBOption { } } +func WithByIDNotIn(ids []uint) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("id not in (?)", ids) + } +} + func WithByName(name string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("name = ?", name) diff --git a/agent/app/service/app.go b/agent/app/service/app.go index 7fa1a1bca..fad0f6c94 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -842,6 +842,28 @@ var InitTypes = map[string]struct{}{ "node": {}, } +func deleteCustomApp() { + var appIDS []uint + installs, _ := appInstallRepo.ListBy() + for _, install := range installs { + appIDS = append(appIDS, install.AppId) + } + var ops []repo.DBOption + ops = append(ops, repo.WithByIDNotIn(appIDS)) + if len(appIDS) > 0 { + ops = append(ops, repo.WithByIDNotIn(appIDS)) + } + apps, _ := appRepo.GetBy(ops...) + var deleteIDS []uint + for _, app := range apps { + if app.Resource == constant.AppResourceCustom { + deleteIDS = append(deleteIDS, app.ID) + } + } + _ = appRepo.DeleteByIDs(context.Background(), deleteIDS) + _ = appDetailRepo.DeleteByAppIds(context.Background(), deleteIDS) +} + func (a AppService) SyncAppListFromRemote(taskID string) (err error) { if xpack.IsUseCustomApp() { return nil @@ -891,7 +913,8 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) { Sort: t.Sort, }) } - oldApps, err := appRepo.GetBy(appRepo.WithResource(constant.AppResourceRemote)) + deleteCustomApp() + oldApps, err := appRepo.GetBy(appRepo.WithNotLocal()) if err != nil { return err } @@ -1104,6 +1127,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) { go func() { if err = syncTask.Execute(); err != nil { + _ = NewISettingService().Update("AppStoreLastModified", "0") _ = NewISettingService().Update("AppStoreSyncStatus", constant.Error) } }() diff --git a/agent/app/service/website_utils.go b/agent/app/service/website_utils.go index 915024128..739595eda 100644 --- a/agent/app/service/website_utils.go +++ b/agent/app/service/website_utils.go @@ -91,11 +91,13 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error { } func createProxyFile(website *model.Website) error { - nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) - if err != nil { - return err - } - proxyFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "proxy") + //nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) + //if err != nil { + // return err + //} + // + //proxyFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "proxy") + proxyFolder := GetSitePath(*website, SiteProxyDir) filePath := path.Join(proxyFolder, "root.conf") fileOp := files.NewFileOp() if !fileOp.Stat(proxyFolder) { diff --git a/frontend/src/components/log-file/index.vue b/frontend/src/components/log-file/index.vue index f2e48ea0b..315d09a5c 100644 --- a/frontend/src/components/log-file/index.vue +++ b/frontend/src/components/log-file/index.vue @@ -1,5 +1,5 @@