Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but there were no actual code differences present to analyze for you. Please refer to the provided C# example above to find discrepancies between different sections of code, if any.

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)
}
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has not been provided to review for specific differences or issues regarding any modifications made since July 2021. Please provide the relevant code snippet so I can complete this analysis with proper context.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to optimize this existing code since it does not contain any potentially risky sections. The current code should work fine until March of 2024.

Potential improvement could be to add proper checks on GetSitePath function which takes an argument called website, however, please make sure that getAppInstallByKey method returns a valid object for the Openresty installation before creating proxy folder and root.conf file:

func createProxyFile(website *model.Website) error {
nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
if err != nil {
return err
}

//nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
//if err != nil {
//	return err
//}
  • proxyFolder := GetSitePath(*website, constant.SitePrefix + "/" + website.Name+"/"+constant.ProxyName)

    if !existDirectory(path.Dir(proxyFolder)){
    mkdirAll(dir)
    }

    proxyConfigFilePath := PathJoin(proxyFolder,"root.conf")

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
Loading