mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
parent
75ac8bae4d
commit
d60e8167b0
@ -1,5 +1,11 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
Name string `json:"name" gorm:"type:varchar(64);not null"`
|
Name string `json:"name" gorm:"type:varchar(64);not null"`
|
||||||
@ -24,3 +30,14 @@ type App struct {
|
|||||||
TagsKey []string `json:"tags" yaml:"tags" gorm:"-"`
|
TagsKey []string `json:"tags" yaml:"tags" gorm:"-"`
|
||||||
AppTags []AppTag `json:"-" gorm:"-:migration"`
|
AppTags []AppTag `json:"-" gorm:"-:migration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *App) IsLocalApp() bool {
|
||||||
|
return i.Resource == constant.ResourceLocal
|
||||||
|
}
|
||||||
|
func (i *App) GetAppResourcePath() string {
|
||||||
|
if i.IsLocalApp() {
|
||||||
|
//这里要去掉本地应用的local前缀
|
||||||
|
return filepath.Join(constant.LocalAppResourceDir, strings.TrimPrefix(i.Key, "local"))
|
||||||
|
}
|
||||||
|
return filepath.Join(constant.RemoteAppResourceDir, i.Key)
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -173,7 +173,8 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response.
|
|||||||
return appDetailDTO, err
|
return appDetailDTO, err
|
||||||
}
|
}
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
versionPath := path.Join(constant.AppResourceDir, app.Resource, app.Key, detail.Version)
|
|
||||||
|
versionPath := filepath.Join(app.GetAppResourcePath(), detail.Version)
|
||||||
if !fileOp.Stat(versionPath) || detail.Update {
|
if !fileOp.Stat(versionPath) || detail.Update {
|
||||||
if err = downloadApp(app, detail, nil); err != nil {
|
if err = downloadApp(app, detail, nil); err != nil {
|
||||||
return appDetailDTO, err
|
return appDetailDTO, err
|
||||||
@ -181,8 +182,8 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response.
|
|||||||
}
|
}
|
||||||
switch app.Type {
|
switch app.Type {
|
||||||
case constant.RuntimePHP:
|
case constant.RuntimePHP:
|
||||||
buildPath := path.Join(versionPath, "build")
|
buildPath := filepath.Join(versionPath, "build")
|
||||||
paramsPath := path.Join(buildPath, "config.json")
|
paramsPath := filepath.Join(buildPath, "config.json")
|
||||||
if !fileOp.Stat(paramsPath) {
|
if !fileOp.Stat(paramsPath) {
|
||||||
return appDetailDTO, buserr.New(constant.ErrFileNotExist)
|
return appDetailDTO, buserr.New(constant.ErrFileNotExist)
|
||||||
}
|
}
|
||||||
@ -195,7 +196,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response.
|
|||||||
return appDetailDTO, err
|
return appDetailDTO, err
|
||||||
}
|
}
|
||||||
appDetailDTO.Params = paramMap
|
appDetailDTO.Params = paramMap
|
||||||
composePath := path.Join(buildPath, "docker-compose.yml")
|
composePath := filepath.Join(buildPath, "docker-compose.yml")
|
||||||
if !fileOp.Stat(composePath) {
|
if !fileOp.Stat(composePath) {
|
||||||
return appDetailDTO, buserr.New(constant.ErrFileNotExist)
|
return appDetailDTO, buserr.New(constant.ErrFileNotExist)
|
||||||
}
|
}
|
||||||
@ -223,7 +224,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if appDetailDTO.DockerCompose == "" {
|
if appDetailDTO.DockerCompose == "" {
|
||||||
filename := path.Base(appDetailDTO.DownloadUrl)
|
filename := filepath.Base(appDetailDTO.DownloadUrl)
|
||||||
dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(appDetailDTO.DownloadUrl, filename), "docker-compose.yml")
|
dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(appDetailDTO.DownloadUrl, filename), "docker-compose.yml")
|
||||||
composeRes, err := http.Get(dockerComposeUrl)
|
composeRes, err := http.Get(dockerComposeUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -489,7 +490,7 @@ func (a AppService) SyncAppListFromLocal() {
|
|||||||
}
|
}
|
||||||
for _, dirEntry := range dirEntries {
|
for _, dirEntry := range dirEntries {
|
||||||
if dirEntry.IsDir() {
|
if dirEntry.IsDir() {
|
||||||
appDir := path.Join(localAppDir, dirEntry.Name())
|
appDir := filepath.Join(localAppDir, dirEntry.Name())
|
||||||
appDirEntries, err := os.ReadDir(appDir)
|
appDirEntries, err := os.ReadDir(appDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.LOG.Errorf(i18n.GetMsgWithMap("ErrAppDirNull", map[string]interface{}{"name": dirEntry.Name(), "err": err.Error()}))
|
global.LOG.Errorf(i18n.GetMsgWithMap("ErrAppDirNull", map[string]interface{}{"name": dirEntry.Name(), "err": err.Error()}))
|
||||||
@ -507,7 +508,7 @@ func (a AppService) SyncAppListFromLocal() {
|
|||||||
Version: appDirEntry.Name(),
|
Version: appDirEntry.Name(),
|
||||||
Status: constant.AppNormal,
|
Status: constant.AppNormal,
|
||||||
}
|
}
|
||||||
versionDir := path.Join(appDir, appDirEntry.Name())
|
versionDir := filepath.Join(appDir, appDirEntry.Name())
|
||||||
if err = handleLocalAppDetail(versionDir, &appDetail); err != nil {
|
if err = handleLocalAppDetail(versionDir, &appDetail); err != nil {
|
||||||
global.LOG.Errorf(i18n.GetMsgWithMap("LocalAppVersionErr", map[string]interface{}{"name": app.Name, "version": appDetail.Version, "err": err.Error()}))
|
global.LOG.Errorf(i18n.GetMsgWithMap("LocalAppVersionErr", map[string]interface{}{"name": app.Name, "version": appDetail.Version, "err": err.Error()}))
|
||||||
continue
|
continue
|
||||||
@ -742,7 +743,7 @@ func getAppFromRepo(downloadPath string) error {
|
|||||||
downloadUrl := downloadPath
|
downloadUrl := downloadPath
|
||||||
global.LOG.Infof("[AppStore] download file from %s", downloadUrl)
|
global.LOG.Infof("[AppStore] download file from %s", downloadUrl)
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
packagePath := path.Join(constant.ResourceDir, path.Base(downloadUrl))
|
packagePath := filepath.Join(constant.ResourceDir, filepath.Base(downloadUrl))
|
||||||
if err := fileOp.DownloadFile(downloadUrl, packagePath); err != nil {
|
if err := fileOp.DownloadFile(downloadUrl, packagePath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -760,7 +761,7 @@ func getAppList() (*dto.AppList, error) {
|
|||||||
if err := getAppFromRepo(fmt.Sprintf("%s/%s/1panel.json.zip", global.CONF.System.AppRepo, global.CONF.System.Mode)); err != nil {
|
if err := getAppFromRepo(fmt.Sprintf("%s/%s/1panel.json.zip", global.CONF.System.AppRepo, global.CONF.System.Mode)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
listFile := path.Join(constant.ResourceDir, "1panel.json")
|
listFile := filepath.Join(constant.ResourceDir, "1panel.json")
|
||||||
content, err := os.ReadFile(listFile)
|
content, err := os.ReadFile(listFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -637,8 +637,12 @@ func handleMap(params map[string]interface{}, envParams map[string]string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func downloadApp(app model.App, appDetail model.AppDetail, appInstall *model.AppInstall) (err error) {
|
func downloadApp(app model.App, appDetail model.AppDetail, appInstall *model.AppInstall) (err error) {
|
||||||
|
if app.IsLocalApp() {
|
||||||
|
//本地应用,不去官网下载
|
||||||
|
return nil
|
||||||
|
}
|
||||||
appResourceDir := path.Join(constant.AppResourceDir, app.Resource)
|
appResourceDir := path.Join(constant.AppResourceDir, app.Resource)
|
||||||
appDownloadDir := path.Join(appResourceDir, app.Key)
|
appDownloadDir := app.GetAppResourcePath()
|
||||||
appVersionDir := path.Join(appDownloadDir, appDetail.Version)
|
appVersionDir := path.Join(appDownloadDir, appDetail.Version)
|
||||||
fileOp := files.NewFileOp()
|
fileOp := files.NewFileOp()
|
||||||
if !appDetail.Update && fileOp.Stat(appVersionDir) {
|
if !appDetail.Update && fileOp.Stat(appVersionDir) {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/subosito/gotenv"
|
"github.com/subosito/gotenv"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -107,7 +108,8 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
appVersionDir := path.Join(constant.AppResourceDir, app.Resource, app.Key, appDetail.Version)
|
|
||||||
|
appVersionDir := filepath.Join(app.GetAppResourcePath(), appDetail.Version)
|
||||||
if !fileOp.Stat(appVersionDir) || appDetail.Update {
|
if !fileOp.Stat(appVersionDir) || appDetail.Update {
|
||||||
if err := downloadApp(app, appDetail, nil); err != nil {
|
if err := downloadApp(app, appDetail, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1210,7 +1210,7 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
oldRuntime, err := runtimeRepo.GetFirst(commonRepo.WithByID(req.RuntimeID))
|
oldRuntime, err := runtimeRepo.GetFirst(commonRepo.WithByID(website.RuntimeID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user