Skip to content

Commit

Permalink
feat(website): Fix Issue with Creating Reverse Proxy Website
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengkunwang223 committed Jan 3, 2025
1 parent c7936e6 commit f11517a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
7 changes: 6 additions & 1 deletion agent/app/repo/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'")
}
}

Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions agent/app/repo/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}()
Expand Down
12 changes: 7 additions & 5 deletions agent/app/service/website_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/log-file/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-loading="initLog && isLoading">
<div v-loading="firstLoading">
<div v-if="defaultButton">
<el-checkbox border v-model="tailLog" class="float-left" @change="changeTail(false)" v-if="showTail">
{{ $t('commons.button.watch') }}
Expand Down Expand Up @@ -110,7 +110,6 @@ const maxPage = ref(0);
const minPage = ref(0);
let timer: NodeJS.Timer | null = null;
const logPath = ref('');
const initLog = ref(false);
const firstLoading = ref(false);
const logs = ref<string[]>([]);
Expand Down Expand Up @@ -273,7 +272,6 @@ const onCloseLog = async () => {
timer = null;
isLoading.value = false;
emit('update:isReading', false);
initLog.value = false;
};
watch(
Expand All @@ -284,7 +282,6 @@ watch(
);
const init = async () => {
initLog.value = true;
if (props.config.tail) {
tailLog.value = props.config.tail;
} else {
Expand Down

0 comments on commit f11517a

Please sign in to comment.