Skip to content

Commit 6869821

Browse files
feat(appstore): Optimize Custom Application Logic (#7603)
1 parent 79fea27 commit 6869821

File tree

11 files changed

+37
-14
lines changed

11 files changed

+37
-14
lines changed

agent/app/repo/app.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type IAppRepo interface {
1818
OrderByRecommend() DBOption
1919
GetRecommend() DBOption
2020
WithResource(resource string) DBOption
21+
WithNotLocal() DBOption
2122
WithByLikeName(name string) DBOption
2223
WithArch(arch string) DBOption
2324
WithPanelVersion(panelVersion string) DBOption
@@ -76,6 +77,12 @@ func (a AppRepo) WithResource(resource string) DBOption {
7677
}
7778
}
7879

80+
func (a AppRepo) WithNotLocal() DBOption {
81+
return func(g *gorm.DB) *gorm.DB {
82+
return g.Where("resource != local")
83+
}
84+
}
85+
7986
func (a AppRepo) WithArch(arch string) DBOption {
8087
return func(g *gorm.DB) *gorm.DB {
8188
return g.Where("architectures like ?", fmt.Sprintf("%%%s%%", arch))

agent/app/service/app.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ var InitTypes = map[string]struct{}{
843843
}
844844

845845
func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
846+
if xpack.IsUseCustomApp() {
847+
return nil
848+
}
846849
syncTask, err := task.NewTaskWithOps(i18n.GetMsgByKey("App"), task.TaskSync, task.TaskScopeAppStore, taskID, 0)
847850
if err != nil {
848851
return err

agent/app/service/app_install.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,9 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo
125125
}
126126

127127
installDTOs, err := handleInstalled(installs, req.Update, req.Sync)
128-
if err != nil {
129-
return 0, nil, err
130-
}
131128
if req.Update {
132129
total = int64(len(installDTOs))
133130
}
134-
135131
return total, installDTOs, nil
136132
}
137133

agent/app/service/app_utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ func copyData(task *task.Task, app model.App, appDetail model.AppDetail, appInst
935935
appKey = strings.TrimPrefix(app.Key, "local")
936936
installAppDir = path.Join(constant.LocalAppInstallDir, appKey)
937937
}
938+
if app.Resource == constant.AppResourceCustom {
939+
appResourceDir = path.Join(constant.AppResourceDir, "custom")
940+
}
938941
resourceDir := path.Join(appResourceDir, appKey, appDetail.Version)
939942

940943
if !fileOp.Stat(installAppDir) {
@@ -1094,9 +1097,11 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error
10941097
appInstall.Message = err.Error()
10951098
}
10961099
appInstall.Status = constant.UpErr
1100+
_ = appInstallRepo.Save(context.Background(), appInstall)
10971101
return err
10981102
} else {
10991103
appInstall.Status = constant.Running
1104+
_ = appInstallRepo.Save(context.Background(), appInstall)
11001105
return nil
11011106
}
11021107
}

agent/app/service/setting.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/1Panel-dev/1Panel/agent/app/dto"
9-
"github.com/1Panel-dev/1Panel/agent/app/repo"
109
"github.com/1Panel-dev/1Panel/agent/constant"
1110
"github.com/1Panel-dev/1Panel/agent/global"
1211
"github.com/1Panel-dev/1Panel/agent/utils/encrypt"
@@ -81,7 +80,6 @@ func (u *SettingService) ReloadConn() error {
8180
return nil
8281
}
8382

84-
settingRepo := repo.NewISettingRepo()
8583
itemKey, _ := encrypt.StringEncrypt(nodeInfo.ServerKey)
8684
if err := settingRepo.Update("ServerKey", itemKey); err != nil {
8785
global.LOG.Errorf("update server key failed, err: %v", err)
@@ -112,6 +110,9 @@ func (u *SettingService) ReloadConn() error {
112110
global.CONF.System.BaseDir = nodeInfo.BaseDir
113111
global.CONF.System.Version = nodeInfo.Version
114112
global.CONF.System.Port = fmt.Sprintf("%v", nodeInfo.NodePort)
113+
if global.CONF.System.Port == "0" {
114+
global.CONF.System.Port = "9999"
115+
}
115116
global.IsMaster = nodeInfo.Scope == "master"
116117
return nil
117118
}

agent/constant/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333

3434
AppResourceLocal = "local"
3535
AppResourceRemote = "remote"
36+
AppResourceCustom = "custom"
3637

3738
CPUS = "CPUS"
3839
MemoryLimit = "MEMORY_LIMIT"

agent/constant/dir.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var (
1414
LocalAppResourceDir = path.Join(AppResourceDir, "local")
1515
LocalAppInstallDir = path.Join(AppInstallDir, "local")
1616
RemoteAppResourceDir = path.Join(AppResourceDir, "remote")
17+
CustomAppResourceDir = path.Join(AppResourceDir, "custom")
1718
RuntimeDir = path.Join(DataDir, "runtime")
1819
RecycleBinDir = "/.1panel_clash"
1920
SSLLogDir = path.Join(global.CONF.System.DataDir, "log", "ssl")

agent/init/app/app.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ func Init() {
2121
constant.LocalAppResourceDir = path.Join(constant.AppResourceDir, "local")
2222
constant.LocalAppInstallDir = path.Join(constant.AppInstallDir, "local")
2323
constant.RemoteAppResourceDir = path.Join(constant.AppResourceDir, "remote")
24+
constant.CustomAppResourceDir = path.Join(constant.AppResourceDir, "custom")
2425

2526
constant.LogDir = path.Join(global.CONF.System.DataDir, "log")
2627
constant.SSLLogDir = path.Join(constant.LogDir, "ssl")
2728

28-
dirs := []string{constant.DataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir,
29-
global.CONF.System.Backup, constant.RuntimeDir, constant.LocalAppResourceDir, constant.RemoteAppResourceDir, constant.SSLLogDir}
29+
dirs := []string{
30+
constant.DataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir,
31+
global.CONF.System.Backup, constant.RuntimeDir, constant.LocalAppResourceDir,
32+
constant.RemoteAppResourceDir, constant.SSLLogDir,
33+
constant.CustomAppResourceDir,
34+
}
3035

3136
fileOp := files.NewFileOp()
3237
for _, dir := range dirs {

agent/utils/xpack/xpack.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ func loadParams(param string) string {
6666
func GetImagePrefix() string {
6767
return ""
6868
}
69+
70+
func IsUseCustomApp() bool {
71+
return false
72+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const stopSignals = [
9090
'[TASK-END]',
9191
];
9292
const emit = defineEmits(['update:loading', 'update:hasContent', 'update:isReading']);
93-
const tailLog = ref(false);
93+
const tailLog = ref(true);
9494
const loading = ref(props.loading);
9595
const readReq = reactive({
9696
id: 0,
@@ -117,7 +117,7 @@ const logHeight = 20;
117117
const logCount = ref(0);
118118
const totalHeight = computed(() => logHeight * logCount.value);
119119
const containerHeight = ref(500);
120-
const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight)); // 计算可见日志条数(容器高度 / 日志高度)
120+
const visibleCount = computed(() => Math.ceil(containerHeight.value / logHeight));
121121
const startIndex = ref(0);
122122
123123
const visibleLogs = computed(() => {

0 commit comments

Comments
 (0)