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

feat(appstore): Optimize Custom Application Logic (#7603)

This commit is contained in:
zhengkunwang 2024-12-30 21:04:11 +08:00 committed by GitHub
parent 79fea272aa
commit 68698217ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 37 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -33,6 +33,7 @@ const (
AppResourceLocal = "local"
AppResourceRemote = "remote"
AppResourceCustom = "custom"
CPUS = "CPUS"
MemoryLimit = "MEMORY_LIMIT"

View File

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

View File

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

View File

@ -66,3 +66,7 @@ func loadParams(param string) string {
func GetImagePrefix() string {
return ""
}
func IsUseCustomApp() bool {
return false
}

View File

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

View File

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