From 322513c71fd388a67e76ae3540bdb8b97b302bdb Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 17 Feb 2023 16:22:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=8C=85=E6=94=B9=E4=B8=BA=E4=BB=8E=20OSS=20=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/setting.go | 1 - backend/app/service/upgrade.go | 112 ++++++--------------- cmd/server/docs/docs.go | 3 - cmd/server/docs/swagger.json | 3 - cmd/server/docs/swagger.yaml | 2 - frontend/src/api/interface/setting.ts | 1 - frontend/src/views/setting/about/index.vue | 3 - go.mod | 5 - go.sum | 8 -- 9 files changed, 28 insertions(+), 110 deletions(-) diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go index cd7b517a6..6290f3203 100644 --- a/backend/app/dto/setting.go +++ b/backend/app/dto/setting.go @@ -84,7 +84,6 @@ type SnapshotInfo struct { type UpgradeInfo struct { NewVersion string `json:"newVersion"` ReleaseNote string `json:"releaseNote"` - CreatedAt string `json:"createdAt"` } type Upgrade struct { Version string `json:"version"` diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 5dd4211c5..c3f18a2f1 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -1,10 +1,8 @@ package service import ( - "context" - "crypto/tls" - "errors" "fmt" + "io/ioutil" "net/http" "os" "runtime" @@ -12,12 +10,10 @@ import ( "strings" "time" - "gitee.com/openeuler/go-gitee/gitee" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/files" - "github.com/google/go-github/github" ) type UpgradeService struct{} @@ -32,38 +28,40 @@ func NewIUpgradeService() IUpgradeService { } func (u *UpgradeService) SearchUpgrade() (*dto.UpgradeInfo, error) { + var upgrade dto.UpgradeInfo currentVersion, err := settingRepo.Get(settingRepo.WithByKey("SystemVersion")) if err != nil { return nil, err } - var releaseInfo dto.UpgradeInfo - isGiteeOK := checkValid("https://gitee.com/wanghe-fit2cloud/1Panel") - if isGiteeOK { - releaseInfo, err = u.loadLatestFromGitee() - if err != nil { - global.LOG.Error(err) - } + versionRes, err := http.Get(fmt.Sprintf("%s/%s/latest", global.CONF.System.RepoUrl, global.CONF.System.Mode)) + if err != nil { + return nil, err } - if len(releaseInfo.NewVersion) == 0 { - isGithubOK := checkValid("https://gitee.com/1Panel-dev/1Panel") - if isGithubOK { - releaseInfo, err = u.loadLatestFromGithub() - if err != nil { - global.LOG.Error(err) - return nil, err - } - } + defer versionRes.Body.Close() + version, err := ioutil.ReadAll(versionRes.Body) + if err != nil { + return nil, err } - if len(releaseInfo.NewVersion) != 0 { - isNew, err := compareVersion(currentVersion.Value, releaseInfo.NewVersion) - if !isNew || err != nil { - return nil, err - } - return &releaseInfo, nil + isNew, err := compareVersion(currentVersion.Value, string(version)) + if !isNew || err != nil { + return nil, err } - return nil, errors.New("both gitee and github were unavailable") + upgrade.NewVersion = string(version) + + releaseNotes, err := http.Get(fmt.Sprintf("%s/%s/%s/release/1panel-%s-release-notes", global.CONF.System.RepoUrl, global.CONF.System.Mode, upgrade.NewVersion, upgrade.NewVersion)) + if err != nil { + return nil, err + } + defer releaseNotes.Body.Close() + release, err := ioutil.ReadAll(releaseNotes.Body) + if err != nil { + return nil, err + } + upgrade.ReleaseNote = string(release) + + return &upgrade, nil } func (u *UpgradeService) Upgrade(req dto.Upgrade) error { @@ -79,20 +77,11 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error { return err } - downloadPath := fmt.Sprintf("https://gitee.com/%s/%s/releases/download/%s/", "wanghe-fit2cloud", "1Panel", req.Version) - isGiteeOK := checkValid(downloadPath) - if !isGiteeOK { - downloadPath = fmt.Sprintf("https://github.com/%s/%s/releases/download/%s/", "wanghe-fit2cloud", "1Panel", req.Version) - isGithubOK := checkValid(downloadPath) - if !isGithubOK { - return errors.New("both gitee and github were unavailabl") - } - } - + downloadPath := fmt.Sprintf("%s/%s/%s/release", global.CONF.System.RepoUrl, global.CONF.System.Mode, req.Version) fileName := fmt.Sprintf("1panel-%s-%s-%s.tar.gz", req.Version, "linux", runtime.GOARCH) _ = settingRepo.Update("SystemStatus", "Upgrading") go func() { - if err := fileOp.DownloadFile(downloadPath+fileName, rootDir+"/service.tar.gz"); err != nil { + if err := fileOp.DownloadFile(downloadPath+"/"+fileName, rootDir+"/service.tar.gz"); err != nil { global.LOG.Errorf("download service file failed, err: %v", err) _ = settingRepo.Update("SystemStatus", "Free") return @@ -179,36 +168,6 @@ func (u *UpgradeService) handleRollback(fileOp files.FileOp, originalDir string, } -func (u *UpgradeService) loadLatestFromGithub() (dto.UpgradeInfo, error) { - var info dto.UpgradeInfo - client := github.NewClient(nil) - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - defer cancel() - stats, res, err := client.Repositories.GetLatestRelease(ctx, "wanghe-fit2cloud", "1Panel") - if res.StatusCode != 200 || err != nil { - return info, fmt.Errorf("load upgrade info from github failed, err: %v", err) - } - info.NewVersion = string(*stats.Name) - info.ReleaseNote = string(*stats.Body) - info.CreatedAt = stats.PublishedAt.Add(8 * time.Hour).Format("2006-01-02 15:04:05") - return info, nil -} - -func (u *UpgradeService) loadLatestFromGitee() (dto.UpgradeInfo, error) { - var info dto.UpgradeInfo - client := gitee.NewAPIClient(gitee.NewConfiguration()) - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - defer cancel() - stats, res, err := client.RepositoriesApi.GetV5ReposOwnerRepoReleasesLatest(ctx, "wanghe-fit2cloud", "1Panel", &gitee.GetV5ReposOwnerRepoReleasesLatestOpts{}) - if res.StatusCode != 200 || err != nil { - return info, fmt.Errorf("load upgrade info from gitee failed, err: %v", err) - } - info.NewVersion = string(stats.Name) - info.ReleaseNote = string(stats.Body) - info.CreatedAt = stats.CreatedAt.Format("2006-01-02 15:04:05") - return info, nil -} - func compareVersion(version, newVersion string) (bool, error) { if version == newVersion { return false, nil @@ -248,18 +207,3 @@ func compareVersion(version, newVersion string) (bool, error) { return false, nil } } - -func checkValid(addr string) bool { - timeout := time.Duration(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 -} diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 433f26680..e08b9983a 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -10593,9 +10593,6 @@ var doc = `{ "dto.UpgradeInfo": { "type": "object", "properties": { - "createdAt": { - "type": "string" - }, "newVersion": { "type": "string" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 04c710710..5857a3474 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -10579,9 +10579,6 @@ "dto.UpgradeInfo": { "type": "object", "properties": { - "createdAt": { - "type": "string" - }, "newVersion": { "type": "string" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index e91f3ac8b..f65a5eac9 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -1383,8 +1383,6 @@ definitions: type: object dto.UpgradeInfo: properties: - createdAt: - type: string newVersion: type: string releaseNote: diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index cad1609e9..20a1f0aa4 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -83,6 +83,5 @@ export namespace Setting { export interface UpgradeInfo { newVersion: string; releaseNote: string; - createdAt: string; } } diff --git a/frontend/src/views/setting/about/index.vue b/frontend/src/views/setting/about/index.vue index 1d519d30e..201e894d3 100644 --- a/frontend/src/views/setting/about/index.vue +++ b/frontend/src/views/setting/about/index.vue @@ -43,9 +43,6 @@ {{ upgradeInfo.newVersion }} - - {{ upgradeInfo.createdAt }} - diff --git a/go.mod b/go.mod index 7f86ca545..136c74343 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,7 @@ module github.com/1Panel-dev/1Panel go 1.18 require ( - gitee.com/openeuler/go-gitee v0.0.0-20220530104019-3af895bc380c github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible - github.com/antihax/optional v1.0.0 github.com/aws/aws-sdk-go v1.44.99 github.com/compose-spec/compose-go v1.6.0 github.com/creack/pty v1.1.18 @@ -23,7 +21,6 @@ require ( github.com/go-sql-driver/mysql v1.6.0 github.com/gogf/gf v1.16.9 github.com/golang-jwt/jwt/v4 v4.4.2 - github.com/google/go-github v17.0.0+incompatible github.com/gorilla/websocket v1.5.0 github.com/jinzhu/copier v0.3.5 github.com/joho/godotenv v1.4.0 @@ -154,12 +151,10 @@ require ( go.opentelemetry.io/otel/trace v1.3.0 // indirect golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect golang.org/x/sys v0.4.0 // indirect golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect golang.org/x/tools v0.1.12 // indirect - google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/ini.v1 v1.66.6 // indirect ) diff --git a/go.sum b/go.sum index dc97201f5..73c21eba8 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,6 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -gitee.com/openeuler/go-gitee v0.0.0-20220530104019-3af895bc380c h1:miClKCIA2Zyqif+Mf0GOdd/1u2q2wW7/vVuHpQprwDw= -gitee.com/openeuler/go-gitee v0.0.0-20220530104019-3af895bc380c/go.mod h1:qGJhn1KxC5UE4BUmxCE/hTpFfuKbd3U3V9fNROrspfE= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= @@ -102,7 +100,6 @@ github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible h1:QoRMR0TCctLDqBCMyOu1e github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= -github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= @@ -501,8 +498,6 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -1147,8 +1142,6 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 h1:lxqLZaMad/dJHMFZH0NiNpiEZI/nhgWhe4wgzpE+MuA= -golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1375,7 +1368,6 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/cloud v0.0.0-20151119220103-975617b05ea8/go.mod h1:0H1ncTHf11KCFhTc/+EFRbzSCOZx+VUbRMk55Yv5MYk= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=