Skip to content

Commit 8e4b162

Browse files
feat(website): Fix Issue with Creating Reverse Proxy Website (#7633)
1 parent 6122aa3 commit 8e4b162

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

agent/app/repo/app.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type IAppRepo interface {
3232
Save(ctx context.Context, app *model.App) error
3333
BatchDelete(ctx context.Context, apps []model.App) error
3434
DeleteByIDs(ctx context.Context, ids []uint) error
35+
DeleteBy(opts ...DBOption) error
3536
}
3637

3738
func NewIAppRepo() IAppRepo {
@@ -79,7 +80,7 @@ func (a AppRepo) WithResource(resource string) DBOption {
7980

8081
func (a AppRepo) WithNotLocal() DBOption {
8182
return func(g *gorm.DB) *gorm.DB {
82-
return g.Where("resource != local")
83+
return g.Where("resource != 'local'")
8384
}
8485
}
8586

@@ -149,3 +150,7 @@ func (a AppRepo) BatchDelete(ctx context.Context, apps []model.App) error {
149150
func (a AppRepo) DeleteByIDs(ctx context.Context, ids []uint) error {
150151
return getTx(ctx).Where("id in (?)", ids).Delete(&model.App{}).Error
151152
}
153+
154+
func (a AppRepo) DeleteBy(opts ...DBOption) error {
155+
return getDb().Delete(&model.App{}, opts).Error
156+
}

agent/app/repo/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ func WithByIDs(ids []uint) DBOption {
2424
}
2525
}
2626

27+
func WithByIDNotIn(ids []uint) DBOption {
28+
return func(g *gorm.DB) *gorm.DB {
29+
return g.Where("id not in (?)", ids)
30+
}
31+
}
32+
2733
func WithByName(name string) DBOption {
2834
return func(g *gorm.DB) *gorm.DB {
2935
return g.Where("name = ?", name)

agent/app/service/app.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,28 @@ var InitTypes = map[string]struct{}{
842842
"node": {},
843843
}
844844

845+
func deleteCustomApp() {
846+
var appIDS []uint
847+
installs, _ := appInstallRepo.ListBy()
848+
for _, install := range installs {
849+
appIDS = append(appIDS, install.AppId)
850+
}
851+
var ops []repo.DBOption
852+
ops = append(ops, repo.WithByIDNotIn(appIDS))
853+
if len(appIDS) > 0 {
854+
ops = append(ops, repo.WithByIDNotIn(appIDS))
855+
}
856+
apps, _ := appRepo.GetBy(ops...)
857+
var deleteIDS []uint
858+
for _, app := range apps {
859+
if app.Resource == constant.AppResourceCustom {
860+
deleteIDS = append(deleteIDS, app.ID)
861+
}
862+
}
863+
_ = appRepo.DeleteByIDs(context.Background(), deleteIDS)
864+
_ = appDetailRepo.DeleteByAppIds(context.Background(), deleteIDS)
865+
}
866+
845867
func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
846868
if xpack.IsUseCustomApp() {
847869
return nil
@@ -891,7 +913,8 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
891913
Sort: t.Sort,
892914
})
893915
}
894-
oldApps, err := appRepo.GetBy(appRepo.WithResource(constant.AppResourceRemote))
916+
deleteCustomApp()
917+
oldApps, err := appRepo.GetBy(appRepo.WithNotLocal())
895918
if err != nil {
896919
return err
897920
}
@@ -1104,6 +1127,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
11041127

11051128
go func() {
11061129
if err = syncTask.Execute(); err != nil {
1130+
_ = NewISettingService().Update("AppStoreLastModified", "0")
11071131
_ = NewISettingService().Update("AppStoreSyncStatus", constant.Error)
11081132
}
11091133
}()

agent/app/service/website_utils.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ func createIndexFile(website *model.Website, runtime *model.Runtime) error {
9191
}
9292

9393
func createProxyFile(website *model.Website) error {
94-
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
95-
if err != nil {
96-
return err
97-
}
98-
proxyFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "proxy")
94+
//nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
95+
//if err != nil {
96+
// return err
97+
//}
98+
//
99+
//proxyFolder := path.Join(constant.AppInstallDir, constant.AppOpenresty, nginxInstall.Name, "www", "sites", website.Alias, "proxy")
100+
proxyFolder := GetSitePath(*website, SiteProxyDir)
99101
filePath := path.Join(proxyFolder, "root.conf")
100102
fileOp := files.NewFileOp()
101103
if !fileOp.Stat(proxyFolder) {

frontend/src/components/log-file/index.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div v-loading="initLog && isLoading">
2+
<div v-loading="firstLoading">
33
<div v-if="defaultButton">
44
<el-checkbox border v-model="tailLog" class="float-left" @change="changeTail(false)" v-if="showTail">
55
{{ $t('commons.button.watch') }}
@@ -110,7 +110,6 @@ const maxPage = ref(0);
110110
const minPage = ref(0);
111111
let timer: NodeJS.Timer | null = null;
112112
const logPath = ref('');
113-
const initLog = ref(false);
114113
115114
const firstLoading = ref(false);
116115
const logs = ref<string[]>([]);
@@ -273,7 +272,6 @@ const onCloseLog = async () => {
273272
timer = null;
274273
isLoading.value = false;
275274
emit('update:isReading', false);
276-
initLog.value = false;
277275
};
278276
279277
watch(
@@ -284,7 +282,6 @@ watch(
284282
);
285283
286284
const init = async () => {
287-
initLog.value = true;
288285
if (props.config.tail) {
289286
tailLog.value = props.config.tail;
290287
} else {

0 commit comments

Comments
 (0)