From 68698217ee7532677684300495499a9a15987757 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Mon, 30 Dec 2024 21:04:11 +0800 Subject: [PATCH] feat(appstore): Optimize Custom Application Logic (#7603) --- agent/app/repo/app.go | 7 +++++++ agent/app/service/app.go | 3 +++ agent/app/service/app_install.go | 4 ---- agent/app/service/app_utils.go | 5 +++++ agent/app/service/setting.go | 5 +++-- agent/constant/app.go | 1 + agent/constant/dir.go | 1 + agent/init/app/app.go | 9 +++++++-- agent/utils/xpack/xpack.go | 4 ++++ frontend/src/components/log-file/index.vue | 4 ++-- frontend/src/components/task-log/index.vue | 8 ++++---- 11 files changed, 37 insertions(+), 14 deletions(-) diff --git a/agent/app/repo/app.go b/agent/app/repo/app.go index d51191701..dfa5b4b48 100644 --- a/agent/app/repo/app.go +++ b/agent/app/repo/app.go @@ -18,6 +18,7 @@ type IAppRepo interface { OrderByRecommend() DBOption GetRecommend() DBOption WithResource(resource string) DBOption + WithNotLocal() DBOption WithByLikeName(name string) DBOption WithArch(arch string) DBOption WithPanelVersion(panelVersion string) DBOption @@ -76,6 +77,12 @@ func (a AppRepo) WithResource(resource string) DBOption { } } +func (a AppRepo) WithNotLocal() DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("resource != local") + } +} + func (a AppRepo) WithArch(arch string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("architectures like ?", fmt.Sprintf("%%%s%%", arch)) diff --git a/agent/app/service/app.go b/agent/app/service/app.go index 237fb0f79..64d3fa0fe 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -843,6 +843,9 @@ var InitTypes = map[string]struct{}{ } func (a AppService) SyncAppListFromRemote(taskID string) (err error) { + if xpack.IsUseCustomApp() { + return nil + } syncTask, err := task.NewTaskWithOps(i18n.GetMsgByKey("App"), task.TaskSync, task.TaskScopeAppStore, taskID, 0) if err != nil { return err diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index 86eaa9baa..8a13b9513 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -125,13 +125,9 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo } installDTOs, err := handleInstalled(installs, req.Update, req.Sync) - if err != nil { - return 0, nil, err - } if req.Update { total = int64(len(installDTOs)) } - return total, installDTOs, nil } diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index c1324640b..f413d8dde 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -935,6 +935,9 @@ func copyData(task *task.Task, app model.App, appDetail model.AppDetail, appInst appKey = strings.TrimPrefix(app.Key, "local") installAppDir = path.Join(constant.LocalAppInstallDir, appKey) } + if app.Resource == constant.AppResourceCustom { + appResourceDir = path.Join(constant.AppResourceDir, "custom") + } resourceDir := path.Join(appResourceDir, appKey, appDetail.Version) if !fileOp.Stat(installAppDir) { @@ -1094,9 +1097,11 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error appInstall.Message = err.Error() } appInstall.Status = constant.UpErr + _ = appInstallRepo.Save(context.Background(), appInstall) return err } else { appInstall.Status = constant.Running + _ = appInstallRepo.Save(context.Background(), appInstall) return nil } } diff --git a/agent/app/service/setting.go b/agent/app/service/setting.go index 1d85afe37..7758f3bca 100644 --- a/agent/app/service/setting.go +++ b/agent/app/service/setting.go @@ -6,7 +6,6 @@ import ( "time" "github.com/1Panel-dev/1Panel/agent/app/dto" - "github.com/1Panel-dev/1Panel/agent/app/repo" "github.com/1Panel-dev/1Panel/agent/constant" "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/utils/encrypt" @@ -81,7 +80,6 @@ func (u *SettingService) ReloadConn() error { return nil } - settingRepo := repo.NewISettingRepo() itemKey, _ := encrypt.StringEncrypt(nodeInfo.ServerKey) if err := settingRepo.Update("ServerKey", itemKey); err != nil { global.LOG.Errorf("update server key failed, err: %v", err) @@ -112,6 +110,9 @@ func (u *SettingService) ReloadConn() error { global.CONF.System.BaseDir = nodeInfo.BaseDir global.CONF.System.Version = nodeInfo.Version global.CONF.System.Port = fmt.Sprintf("%v", nodeInfo.NodePort) + if global.CONF.System.Port == "0" { + global.CONF.System.Port = "9999" + } global.IsMaster = nodeInfo.Scope == "master" return nil } diff --git a/agent/constant/app.go b/agent/constant/app.go index 73039cd12..5130ec2ee 100644 --- a/agent/constant/app.go +++ b/agent/constant/app.go @@ -33,6 +33,7 @@ const ( AppResourceLocal = "local" AppResourceRemote = "remote" + AppResourceCustom = "custom" CPUS = "CPUS" MemoryLimit = "MEMORY_LIMIT" diff --git a/agent/constant/dir.go b/agent/constant/dir.go index 7cd6e1504..743d50c0e 100644 --- a/agent/constant/dir.go +++ b/agent/constant/dir.go @@ -14,6 +14,7 @@ var ( LocalAppResourceDir = path.Join(AppResourceDir, "local") LocalAppInstallDir = path.Join(AppInstallDir, "local") RemoteAppResourceDir = path.Join(AppResourceDir, "remote") + CustomAppResourceDir = path.Join(AppResourceDir, "custom") RuntimeDir = path.Join(DataDir, "runtime") RecycleBinDir = "/.1panel_clash" SSLLogDir = path.Join(global.CONF.System.DataDir, "log", "ssl") diff --git a/agent/init/app/app.go b/agent/init/app/app.go index 280496b08..9bc5c6dcf 100644 --- a/agent/init/app/app.go +++ b/agent/init/app/app.go @@ -21,12 +21,17 @@ func Init() { constant.LocalAppResourceDir = path.Join(constant.AppResourceDir, "local") constant.LocalAppInstallDir = path.Join(constant.AppInstallDir, "local") constant.RemoteAppResourceDir = path.Join(constant.AppResourceDir, "remote") + constant.CustomAppResourceDir = path.Join(constant.AppResourceDir, "custom") constant.LogDir = path.Join(global.CONF.System.DataDir, "log") constant.SSLLogDir = path.Join(constant.LogDir, "ssl") - dirs := []string{constant.DataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, - global.CONF.System.Backup, constant.RuntimeDir, constant.LocalAppResourceDir, constant.RemoteAppResourceDir, constant.SSLLogDir} + dirs := []string{ + constant.DataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir, + global.CONF.System.Backup, constant.RuntimeDir, constant.LocalAppResourceDir, + constant.RemoteAppResourceDir, constant.SSLLogDir, + constant.CustomAppResourceDir, + } fileOp := files.NewFileOp() for _, dir := range dirs { diff --git a/agent/utils/xpack/xpack.go b/agent/utils/xpack/xpack.go index 478e62894..bd3cbbb29 100644 --- a/agent/utils/xpack/xpack.go +++ b/agent/utils/xpack/xpack.go @@ -66,3 +66,7 @@ func loadParams(param string) string { func GetImagePrefix() string { return "" } + +func IsUseCustomApp() bool { + return false +} diff --git a/frontend/src/components/log-file/index.vue b/frontend/src/components/log-file/index.vue index 9715f634e..580ffd43b 100644 --- a/frontend/src/components/log-file/index.vue +++ b/frontend/src/components/log-file/index.vue @@ -90,7 +90,7 @@ const stopSignals = [ '[TASK-END]', ]; const emit = defineEmits(['update:loading', 'update:hasContent', 'update:isReading']); -const tailLog = ref(false); +const tailLog = ref(true); const loading = ref(props.loading); const readReq = reactive({ id: 0, @@ -117,7 +117,7 @@ const logHeight = 20; const logCount = ref(0); const totalHeight = computed(() => logHeight * logCount.value); const containerHeight = ref(500); -const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight)); // 计算可见日志条数(容器高度 / 日志高度) +const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight)); const startIndex = ref(0); const visibleLogs = computed(() => { diff --git a/frontend/src/components/task-log/index.vue b/frontend/src/components/task-log/index.vue index 9fe1b118d..b25ad8c93 100644 --- a/frontend/src/components/task-log/index.vue +++ b/frontend/src/components/task-log/index.vue @@ -37,7 +37,7 @@ const config = reactive({ taskOperate: '', resourceID: 0, taskType: '', - tail: false, + tail: true, }); const open = ref(false); const showTail = ref(true); @@ -45,10 +45,10 @@ const showTail = ref(true); const openWithTaskID = (id: string, tail: boolean) => { console.log('openWithTaskID', id, tail); config.taskID = id; - if (!tail) { - config.tail = false; - } else { + if (tail === undefined) { config.tail = true; + } else { + config.tail = tail; } open.value = true; };