1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

feat(website): Fix Issue with Creating Reverse Proxy Website (#7633)

This commit is contained in:
zhengkunwang 2025-01-03 16:54:09 +08:00 committed by GitHub
parent 6122aa3a3d
commit 8e4b162b59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 11 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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)
}
}()

View File

@ -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) {

View File

@ -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') }}
@ -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[]>([]);
@ -273,7 +272,6 @@ const onCloseLog = async () => {
timer = null;
isLoading.value = false;
emit('update:isReading', false);
initLog.value = false;
};
watch(
@ -284,7 +282,6 @@ watch(
);
const init = async () => {
initLog.value = true;
if (props.config.tail) {
tailLog.value = props.config.tail;
} else {