mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-02-08 01:20:07 +08:00
feat: 修改同步应用列表方式 (#1141)
This commit is contained in:
parent
c8237d59be
commit
4b25dafb92
@ -1,7 +1,6 @@
|
|||||||
package response
|
package response
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -16,7 +15,6 @@ type AppRes struct {
|
|||||||
type AppUpdateRes struct {
|
type AppUpdateRes struct {
|
||||||
CanUpdate bool `json:"canUpdate"`
|
CanUpdate bool `json:"canUpdate"`
|
||||||
AppStoreLastModified int `json:"appStoreLastModified"`
|
AppStoreLastModified int `json:"appStoreLastModified"`
|
||||||
List dto.AppList `json:"list"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppDTO struct {
|
type AppDTO struct {
|
||||||
|
@ -356,39 +356,6 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
|
|
||||||
res := &response.AppUpdateRes{
|
|
||||||
CanUpdate: false,
|
|
||||||
}
|
|
||||||
setting, err := NewISettingService().GetSettingInfo()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
versionUrl := fmt.Sprintf("%s/%s/1panel.json", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
|
||||||
versionRes, err := http.Get(versionUrl)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer versionRes.Body.Close()
|
|
||||||
body, err := io.ReadAll(versionRes.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
list := &dto.AppList{}
|
|
||||||
if err = json.Unmarshal(body, list); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res.AppStoreLastModified = list.LastModified
|
|
||||||
res.List = *list
|
|
||||||
|
|
||||||
appStoreLastModified, _ := strconv.Atoi(setting.AppStoreLastModified)
|
|
||||||
if setting.AppStoreLastModified == "" || list.LastModified > appStoreLastModified {
|
|
||||||
res.CanUpdate = true
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AppService) SyncAppListFromLocal() {
|
func (a AppService) SyncAppListFromLocal() {
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
localAppDir := constant.LocalAppResourceDir
|
localAppDir := constant.LocalAppResourceDir
|
||||||
@ -659,6 +626,56 @@ func (a AppService) SyncAppListFromLocal() {
|
|||||||
tx.Commit()
|
tx.Commit()
|
||||||
global.LOG.Infof("sync local apps success")
|
global.LOG.Infof("sync local apps success")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
|
||||||
|
res := &response.AppUpdateRes{
|
||||||
|
CanUpdate: false,
|
||||||
|
}
|
||||||
|
setting, err := NewISettingService().GetSettingInfo()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
versionUrl := fmt.Sprintf("%s/%s/1panel.json.version.txt", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
||||||
|
versionRes, err := http.Get(versionUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer versionRes.Body.Close()
|
||||||
|
body, err := io.ReadAll(versionRes.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lastModifiedStr := string(body)
|
||||||
|
|
||||||
|
lastModified, err := strconv.Atoi(lastModifiedStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
appStoreLastModified, _ := strconv.Atoi(setting.AppStoreLastModified)
|
||||||
|
if setting.AppStoreLastModified == "" || lastModified != appStoreLastModified {
|
||||||
|
res.CanUpdate = true
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAppFromRepo(downloadPath string) error {
|
||||||
|
downloadUrl := downloadPath
|
||||||
|
global.LOG.Infof("download file from %s", downloadUrl)
|
||||||
|
fileOp := files.NewFileOp()
|
||||||
|
packagePath := path.Join(constant.ResourceDir, path.Base(downloadUrl))
|
||||||
|
if err := fileOp.DownloadFile(downloadUrl, packagePath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := fileOp.Decompress(packagePath, constant.ResourceDir, files.Zip); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = fileOp.DeleteFile(packagePath)
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a AppService) SyncAppListFromRemote() error {
|
func (a AppService) SyncAppListFromRemote() error {
|
||||||
updateRes, err := a.GetAppUpdate()
|
updateRes, err := a.GetAppUpdate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -667,10 +684,22 @@ func (a AppService) SyncAppListFromRemote() error {
|
|||||||
if !updateRes.CanUpdate {
|
if !updateRes.CanUpdate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if err = getAppFromRepo(fmt.Sprintf("%s/%s/1panel.json.zip", global.CONF.System.AppRepo, global.CONF.System.Mode)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
listFile := path.Join(constant.ResourceDir, "1panel.json")
|
||||||
|
content, err := os.ReadFile(listFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
list := &dto.AppList{}
|
||||||
|
if err := json.Unmarshal(content, list); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tags []*model.Tag
|
tags []*model.Tag
|
||||||
appTags []*model.AppTag
|
appTags []*model.AppTag
|
||||||
list = updateRes.List
|
|
||||||
oldAppIds []uint
|
oldAppIds []uint
|
||||||
)
|
)
|
||||||
for _, t := range list.Extra.Tags {
|
for _, t := range list.Extra.Tags {
|
||||||
|
@ -1155,6 +1155,8 @@ const message = {
|
|||||||
editComposeHelper: 'Editing the compose file may cause the software installation to fail',
|
editComposeHelper: 'Editing the compose file may cause the software installation to fail',
|
||||||
composeNullErr: 'compose cannot be empty',
|
composeNullErr: 'compose cannot be empty',
|
||||||
takeDown: 'TakeDown',
|
takeDown: 'TakeDown',
|
||||||
|
allReadyInstalled: 'Installed',
|
||||||
|
installHelper: 'Configuring image acceleration can solve the problem of image pull failure',
|
||||||
},
|
},
|
||||||
website: {
|
website: {
|
||||||
website: 'Website',
|
website: 'Website',
|
||||||
|
@ -1140,12 +1140,13 @@ const message = {
|
|||||||
allowPortHelper: '允许外部端口访问会放开防火墙端口,php运行环境请勿放开',
|
allowPortHelper: '允许外部端口访问会放开防火墙端口,php运行环境请勿放开',
|
||||||
appInstallWarn: '应用默认不放开外部访问端口,可以在高级设置中选择放开',
|
appInstallWarn: '应用默认不放开外部访问端口,可以在高级设置中选择放开',
|
||||||
upgradeStart: '开始升级!请稍后刷新页面',
|
upgradeStart: '开始升级!请稍后刷新页面',
|
||||||
toFolder: '打开安装目录',
|
toFolder: '进入安装目录',
|
||||||
editCompose: '编辑 compose 文件',
|
editCompose: '编辑 compose 文件',
|
||||||
editComposeHelper: '编辑 compose 文件可能导致软件安装失败',
|
editComposeHelper: '编辑 compose 文件可能导致软件安装失败',
|
||||||
composeNullErr: 'compose 不能为空',
|
composeNullErr: 'compose 不能为空',
|
||||||
takeDown: '已废弃',
|
takeDown: '已废弃',
|
||||||
allReadyInstalled: '已安装',
|
allReadyInstalled: '已安装',
|
||||||
|
installHelper: '配置镜像加速可以解决镜像拉取失败的问题',
|
||||||
},
|
},
|
||||||
website: {
|
website: {
|
||||||
website: '网站',
|
website: '网站',
|
||||||
|
@ -55,6 +55,21 @@
|
|||||||
<img src="@/assets/images/no_update_app.svg" />
|
<img src="@/assets/images/no_update_app.svg" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<el-alert type="info" :closable="false" v-if="mode === 'installed'">
|
||||||
|
<template #default>
|
||||||
|
<span>
|
||||||
|
<span>{{ $t('app.installHelper') }}</span>
|
||||||
|
<el-link
|
||||||
|
style="font-size: 12px; margin-left: 5px"
|
||||||
|
icon="Position"
|
||||||
|
@click="quickJump()"
|
||||||
|
type="primary"
|
||||||
|
>
|
||||||
|
{{ $t('firewall.quickJump') }}
|
||||||
|
</el-link>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-alert>
|
||||||
<el-row :gutter="5">
|
<el-row :gutter="5">
|
||||||
<el-col
|
<el-col
|
||||||
v-for="(installed, index) in data"
|
v-for="(installed, index) in data"
|
||||||
@ -436,6 +451,10 @@ const isAppErr = (row: any) => {
|
|||||||
return row.status.includes('Err') || row.status.includes('Error');
|
return row.status.includes('Err') || row.status.includes('Error');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const quickJump = () => {
|
||||||
|
router.push({ name: 'ContainerSetting' });
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const path = router.currentRoute.value.path;
|
const path = router.currentRoute.value.path;
|
||||||
if (path == '/apps/upgrade') {
|
if (path == '/apps/upgrade') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user