diff --git a/backend/app/service/app.go b/backend/app/service/app.go index cc7453132..a4989dc72 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -4,8 +4,10 @@ import ( "context" "encoding/base64" "encoding/json" + "fmt" "github.com/1Panel-dev/1Panel/backend/buserr" - "github.com/1Panel-dev/1Panel/backend/utils/git" + "io/ioutil" + "net/http" "os" "path" "strings" @@ -336,23 +338,30 @@ func (a AppService) SyncInstalled(installId uint) error { } func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) { - res := &response.AppUpdateRes{} + res := &response.AppUpdateRes{ + CanUpdate: false, + } setting, err := NewISettingService().GetSettingInfo() if err != nil { return nil, err } - contentRes, err := git.CheckAndGetContent(global.CONF.System.AppRepoOwner, global.CONF.System.AppRepoName, setting.SystemVersion, "apps/list.json") + versionRes, err := http.Get(fmt.Sprintf("%s/%s/%s/appstore/apps.json", global.CONF.System.RepoUrl, global.CONF.System.Mode, setting.SystemVersion)) + if err != nil { + return nil, err + } + defer versionRes.Body.Close() + body, err := ioutil.ReadAll(versionRes.Body) if err != nil { return nil, err } list := &dto.AppList{} - if err = json.Unmarshal(contentRes.Content, list); err != nil { + if err = json.Unmarshal(body, list); err != nil { return nil, err } res.Version = list.Version if common.CompareVersion(list.Version, setting.AppStoreVersion) { res.CanUpdate = true - res.DownloadPath = contentRes.DownloadPath + res.DownloadPath = fmt.Sprintf("%s/%s/%s/appstore/apps-%s.tar.gz", global.CONF.System.RepoUrl, global.CONF.System.Mode, setting.SystemVersion, list.Version) return res, err } return nil, err @@ -380,7 +389,6 @@ func (a AppService) SyncAppList() error { if err := json.Unmarshal(content, list); err != nil { return err } - var ( tags []*model.Tag appTags []*model.AppTag diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index ab26a4cb3..213e1e762 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -499,7 +499,7 @@ func handleErr(install model.AppInstall, err error, out string) error { } func getAppFromRepo(downloadPath, version string) error { - downloadUrl := fmt.Sprintf("%s/%s/apps-%s.tar.gz", downloadPath, version, version) + downloadUrl := fmt.Sprintf(downloadPath) appDir := constant.AppResourceDir global.LOG.Infof("download file from %s", downloadUrl) diff --git a/backend/configs/system.go b/backend/configs/system.go index aa90b62c2..ee09507ba 100644 --- a/backend/configs/system.go +++ b/backend/configs/system.go @@ -1,17 +1,16 @@ package configs type System struct { - Port string `mapstructure:"port"` - DbFile string `mapstructure:"db_file"` - DbPath string `mapstructure:"db_path"` - LogPath string `mapstructure:"log_path"` - DataDir string `mapstructure:"data_dir"` - TmpDir string `mapstructure:"tmp_dir"` - Cache string `mapstructure:"cache"` - Backup string `mapstructure:"backup"` - AppRepoOwner string `mapstructure:"app_repo_owner"` - AppRepoName string `mapstructure:"app_repo_name"` - EncryptKey string `mapstructure:"encrypt_key"` - BaseDir string `mapstructure:"base_dir"` - Mode string `mapstructure:"mode"` + Port string `mapstructure:"port"` + DbFile string `mapstructure:"db_file"` + DbPath string `mapstructure:"db_path"` + LogPath string `mapstructure:"log_path"` + DataDir string `mapstructure:"data_dir"` + TmpDir string `mapstructure:"tmp_dir"` + Cache string `mapstructure:"cache"` + Backup string `mapstructure:"backup"` + EncryptKey string `mapstructure:"encrypt_key"` + BaseDir string `mapstructure:"base_dir"` + Mode string `mapstructure:"mode"` + RepoUrl string `mapstructure:"repo_url"` } diff --git a/backend/init/viper/viper.go b/backend/init/viper/viper.go index d370a3ff2..709e64dde 100644 --- a/backend/init/viper/viper.go +++ b/backend/init/viper/viper.go @@ -30,10 +30,7 @@ func Init() { if config.System.Mode != "" { mode = config.System.Mode } - if mode != "release" { - if !fileOp.Stat("/opt/1panel/conf/app.yaml") { - panic("conf file is not exist") - } + if mode == "dev" && fileOp.Stat("/opt/1panel/conf/app.yaml") { v.SetConfigName("app") v.AddConfigPath(path.Join("/opt/1panel/conf")) if err := v.ReadInConfig(); err != nil { diff --git a/backend/utils/git/git.go b/backend/utils/git/git.go deleted file mode 100644 index e5dfdfe4c..000000000 --- a/backend/utils/git/git.go +++ /dev/null @@ -1,147 +0,0 @@ -package git - -import ( - "context" - "crypto/tls" - "encoding/base64" - "errors" - "fmt" - "gitee.com/openeuler/go-gitee/gitee" - "github.com/1Panel-dev/1Panel/backend/global" - "github.com/antihax/optional" - "github.com/google/go-github/github" - "net/http" - "time" -) - -type RepoInfo struct { - RepoType string - Version string - ReleaseNote string - CreatedAt string - DownloadPath string -} - -type RepoContent struct { - RepoType string - Content []byte - DownloadPath string -} - -var gitRepoTypes = []string{"gitee", "github"} - -func CheckAndGetInfo(owner, repoName string) (*RepoInfo, error) { - for _, repoType := range gitRepoTypes { - url := fmt.Sprintf("https://%s.com/%s/%s", repoType, owner, repoName) - if checkValid(url) { - res, err := getLatestRepoInfo(repoType, owner, repoName) - if err == nil { - return res, nil - } else { - global.LOG.Errorf("get %s last release version failed %s", repoType, err.Error()) - } - } else { - global.LOG.Errorf("get %s remote repo [%s] failed", repoType, url) - } - } - return nil, errors.New("all remote repo get failed") -} - -func CheckAndGetContent(owner, repoName, branch, path string) (*RepoContent, error) { - for _, repoType := range gitRepoTypes { - url := fmt.Sprintf("https://%s.com/%s/%s", repoType, owner, repoName) - if checkValid(url) { - res, err := getContentFromBranch(repoType, owner, repoName, branch, path) - if err == nil { - return res, nil - } else { - global.LOG.Errorf("get %s last version failed %s", repoType, err.Error()) - } - } else { - global.LOG.Errorf("check %s valid [%s] failed", repoType, url) - } - } - return nil, errors.New("all repo get failed") -} - -func checkValid(addr string) bool { - timeout := 2 * time.Second - tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } - client := http.Client{ - Transport: tr, - Timeout: timeout, - } - if _, err := client.Get(addr); err != nil { - return false - } - return true -} - -func getLatestRepoInfo(repoType, owner, repoName string) (*RepoInfo, error) { - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - defer cancel() - var repoInfo RepoInfo - repoInfo.RepoType = repoType - if repoType == "gitee" { - client := gitee.NewAPIClient(gitee.NewConfiguration()) - stats, res, err := client.RepositoriesApi.GetV5ReposOwnerRepoReleasesLatest(ctx, owner, repoName, &gitee.GetV5ReposOwnerRepoReleasesLatestOpts{}) - if res.StatusCode != 200 || err != nil { - return nil, err - } - repoInfo.Version = stats.Name - repoInfo.ReleaseNote = stats.Body - repoInfo.CreatedAt = stats.CreatedAt.Format("2006-01-02 15:04:05") - repoInfo.DownloadPath = fmt.Sprintf("https://gitee.com/%s/%s/releases/download/%s/", owner, repoName, repoInfo.Version) - } else { - client := github.NewClient(nil) - stats, res, err := client.Repositories.GetLatestRelease(ctx, owner, repoName) - if res.StatusCode != 200 || err != nil { - return nil, err - } - repoInfo.Version = *stats.Name - repoInfo.ReleaseNote = *stats.Body - repoInfo.CreatedAt = stats.PublishedAt.Add(8 * time.Hour).Format("2006-01-02 15:04:05") - repoInfo.DownloadPath = fmt.Sprintf("https://github.com/%s/%s/releases/download/%s/", owner, repoName, repoInfo.Version) - } - return &repoInfo, nil -} - -func getContentFromBranch(repoType, owner, repoName, branch, path string) (*RepoContent, error) { - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - defer cancel() - var repoContent RepoContent - repoContent.RepoType = repoType - if repoType == "gitee" { - client := gitee.NewAPIClient(gitee.NewConfiguration()) - content, res, err := client.RepositoriesApi.GetV5ReposOwnerRepoContentsPath(ctx, owner, repoName, path, &gitee.GetV5ReposOwnerRepoContentsPathOpts{ - Ref: optional.NewString(branch), - }) - if res.StatusCode != 200 || err != nil { - return nil, err - } - bs64Bytes, err := base64.StdEncoding.DecodeString(content.Content) - if err != nil { - return nil, err - } - repoContent.Content = bs64Bytes - repoContent.DownloadPath = fmt.Sprintf("https://gitee.com/%s/%s/releases/download/", owner, repoName) - return &repoContent, nil - } else { - client := github.NewClient(nil) - content, _, res, err := client.Repositories.GetContents(ctx, owner, repoName, path, &github.RepositoryContentGetOptions{ - Ref: branch, - }) - if res.StatusCode != 200 || err != nil { - return nil, err - } - bs64Bytes, err := base64.StdEncoding.DecodeString(*content.Content) - if err != nil { - return nil, err - } - repoContent.Content = bs64Bytes - repoContent.DownloadPath = fmt.Sprintf("https://github.com/%s/%s/releases/download", owner, repoName) - return &repoContent, nil - } -} diff --git a/cmd/server/conf/app.yaml b/cmd/server/conf/app.yaml index ba776ab65..e7eb127d8 100644 --- a/cmd/server/conf/app.yaml +++ b/cmd/server/conf/app.yaml @@ -1,9 +1,8 @@ system: db_file: 1Panel.db - app_repo_owner: zhengkunwang223 - app_repo_name: appstore base_dir: /opt mode: dev + repo_url: https://1panel.oss-cn-hangzhou.aliyuncs.com/package log: level: debug @@ -11,17 +10,3 @@ log: log_name: 1Panel log_suffix: .log log_backup: 10 - -cors: - mode: whitelist - whitelist: - - allow-origin: example1.com - allow-headers: content-type - allow-methods: GET, POST - expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type - allow-credentials: true - - allow-origin: example2.com - allow-headers: content-type - allow-methods: GET, POST - expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type - allow-credentials: true \ No newline at end of file diff --git a/frontend/src/styles/var.scss b/frontend/src/styles/var.scss index d72247789..6e07607d8 100644 --- a/frontend/src/styles/var.scss +++ b/frontend/src/styles/var.scss @@ -1,24 +1 @@ $primary-color: #005eeb; -$menu-item-backgroup-color: rgba(255, 255, 255, 0.3); -@forward 'element-plus/theme-chalk/src/common/var.scss' with ( - $colors: ( - 'primary': ( - 'base': $primary-color, - ), - 'success': ( - 'base': #67c23a, - ), - 'warning': ( - 'base': #e6a23c, - ), - 'danger': ( - 'base': #f56c6c, - ), - 'error': ( - 'base': #f56c6c, - ), - 'info': ( - 'base': #909399, - ), - ) -);