From 1bdc531c7d49533ac5eedccb4f49dc8fd9e90741 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Tue, 7 Feb 2023 15:33:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=87=E7=BA=A7=E6=8A=BD=E5=B1=89?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4=EF=BC=8C=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=8C=85=E6=97=B6=E9=97=B4=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + backend/app/dto/setting.go | 2 - backend/app/service/upgrade.go | 97 ++++++--- frontend/components.d.ts | 2 - frontend/src/api/interface/setting.ts | 4 - frontend/src/api/modules/setting.ts | 4 +- frontend/src/lang/modules/zh.ts | 2 +- frontend/src/routers/modules/error.ts | 23 -- .../container/container/reName/index.vue | 19 +- .../src/views/container/image/load/index.vue | 13 +- .../src/views/container/setting/index.vue | 2 +- frontend/src/views/cronjob/index.vue | 20 +- frontend/src/views/cronjob/operate/index.vue | 2 +- frontend/src/views/cronjob/record/index.vue | 30 ++- .../src/views/database/mysql/create/index.vue | 2 +- frontend/src/views/database/mysql/index.vue | 183 +++------------- .../views/database/mysql/password/index.vue | 197 ++++++++++++------ .../src/views/database/mysql/remote/index.vue | 27 ++- .../database/mysql/root-password/index.vue | 97 +++++++++ frontend/src/views/setting/about/index.vue | 45 ++-- .../views/website/website/status/index.vue | 2 +- 21 files changed, 418 insertions(+), 356 deletions(-) create mode 100644 frontend/src/views/database/mysql/root-password/index.vue diff --git a/.gitignore b/.gitignore index a04c14bdf..d3c5a3b49 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ build /pkg/ backend/__debug_bin cmd/server/__debug_bin +cmd/server/web diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go index d64d42913..b87bc603e 100644 --- a/backend/app/dto/setting.go +++ b/backend/app/dto/setting.go @@ -75,12 +75,10 @@ type SnapshotInfo struct { } type UpgradeInfo struct { - ID int64 `json:"id"` NewVersion string `json:"newVersion"` ReleaseNote string `json:"releaseNote"` CreatedAt string `json:"createdAt"` } type Upgrade struct { - Source string `json:"source" validate:"required,oneof=github gitee"` Version string `json:"version"` } diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 97904de82..cf79bb513 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -2,7 +2,10 @@ package service import ( "context" + "crypto/tls" + "errors" "fmt" + "net/http" "os" "runtime" "strconv" @@ -34,27 +37,34 @@ func (u *UpgradeService) SearchUpgrade() (*dto.UpgradeInfo, error) { if err != nil { return nil, err } - infoFromGithub, err := u.loadLatestFromGithub() - if err != nil { - global.LOG.Error(err) - } else { - isNew, err := compareVersion(currentVerion.Value, infoFromGithub.NewVersion) - if !isNew || err != nil { + + 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) + } + } + 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 + } + } + } + if len(releaseInfo.NewVersion) != 0 { + isNew, err := compareVersion(currentVerion.Value, releaseInfo.NewVersion) + if !isNew && err != nil { return nil, err } - return infoFromGithub, nil + return &releaseInfo, nil } - infoFromGitee, err := u.loadLatestFromGitee() - if err != nil { - global.LOG.Error(err) - return nil, err - } - isNew, err := compareVersion(currentVerion.Value, infoFromGitee.NewVersion) - if !isNew && err != nil { - return nil, err - } - return infoFromGitee, nil + return nil, errors.New("both gitee and github were unavailable") } func (u *UpgradeService) Upgrade(req dto.Upgrade) error { @@ -71,9 +81,15 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error { } downloadPath := fmt.Sprintf("https://gitee.com/%s/%s/releases/download/%s/", "wanghe-fit2cloud", "1Panel", req.Version) - if req.Source == "github" { + 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") + } } + panelName := fmt.Sprintf("1panel-%s-%s", "linux", runtime.GOARCH) fileName := fmt.Sprintf("1panel-online-installer-%s.tar.gz", req.Version) _ = settingRepo.Update("SystemStatus", "Upgrading") @@ -174,36 +190,34 @@ func (u *UpgradeService) handleRollback(fileOp files.FileOp, originalDir string, } } -func (u *UpgradeService) loadLatestFromGithub() (*dto.UpgradeInfo, error) { +func (u *UpgradeService) loadLatestFromGithub() (dto.UpgradeInfo, error) { + var info dto.UpgradeInfo client := github.NewClient(nil) ctx, cancle := context.WithTimeout(context.Background(), 3*time.Second) defer cancle() stats, res, err := client.Repositories.GetLatestRelease(ctx, "wanghe-fit2cloud", "1Panel") if res.StatusCode != 200 || err != nil { - return nil, fmt.Errorf("load upgrade info from github failed, err: %v", err) + return info, fmt.Errorf("load upgrade info from github failed, err: %v", err) } - info := dto.UpgradeInfo{ - NewVersion: string(*stats.Name), - ReleaseNote: string(*stats.Body), - CreatedAt: github.Timestamp(*stats.CreatedAt).Format("2006-01-02 15:04:05"), - } - return &info, nil + 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) { +func (u *UpgradeService) loadLatestFromGitee() (dto.UpgradeInfo, error) { + var info dto.UpgradeInfo client := gitee.NewAPIClient(gitee.NewConfiguration()) ctx, cancle := context.WithTimeout(context.Background(), 3*time.Second) defer cancle() stats, res, err := client.RepositoriesApi.GetV5ReposOwnerRepoReleasesLatest(ctx, "wanghe-fit2cloud", "1Panel", &gitee.GetV5ReposOwnerRepoReleasesLatestOpts{}) if res.StatusCode != 200 || err != nil { - return nil, fmt.Errorf("load upgrade info from gitee failed, err: %v", err) + return info, fmt.Errorf("load upgrade info from gitee failed, err: %v", err) } - info := dto.UpgradeInfo{ - NewVersion: string(stats.Name), - ReleaseNote: string(stats.Body), - CreatedAt: stats.CreatedAt.Format("2006-01-02 15:04:05"), - } - return &info, nil + 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) { @@ -245,3 +259,18 @@ 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/frontend/components.d.ts b/frontend/components.d.ts index 29b4478a3..b987f0e7d 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -4,9 +4,7 @@ declare module 'vue' { export interface GlobalComponents { - 403: typeof import('./src/components/error-message/403.vue')['default'] 404: typeof import('./src/components/error-message/404.vue')['default'] - 500: typeof import('./src/components/error-message/500.vue')['default'] AppLayout: typeof import('./src/components/app-layout/index.vue')['default'] AppStatus: typeof import('./src/components/app-status/index.vue')['default'] BackButton: typeof import('./src/components/back-button/index.vue')['default'] diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index 34db0c3aa..bf3c5f372 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -80,8 +80,4 @@ export namespace Setting { releaseNote: string; createdAt: string; } - export interface Upgrade { - source: string; - version: string; - } } diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index 0e5aea07a..4d70b30be 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -70,6 +70,6 @@ export const searchSnapshotPage = (param: ReqPage) => { export const loadUpgradeInfo = () => { return http.get(`/settings/upgrade`); }; -export const upgrade = (param: Setting.Upgrade) => { - return http.post(`/settings/upgrade`, param); +export const upgrade = (version: string) => { + return http.post(`/settings/upgrade`, { version: version }); }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 57fdc8b21..4bc5738d5 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -535,7 +535,7 @@ export default { missBackupAccount: '未能找到备份账号', syncDate: '同步时间 ', releaseMemory: '释放内存', - curl: '访问', + curl: '访问 URL', taskName: '任务名称', cronSpec: '执行周期', directory: '备份目录', diff --git a/frontend/src/routers/modules/error.ts b/frontend/src/routers/modules/error.ts index 0df3ada68..3fd4ff3b2 100644 --- a/frontend/src/routers/modules/error.ts +++ b/frontend/src/routers/modules/error.ts @@ -1,21 +1,9 @@ import { Layout } from '@/routers/constant'; -// 错误页面模块 const errorRouter = { path: '/error', component: Layout, children: [ - { - path: '403', - name: '403', - hidden: true, - component: () => import('@/components/error-message/403.vue'), - meta: { - requiresAuth: true, - title: '403页面', - key: '403', - }, - }, { path: '404', name: '404', @@ -27,17 +15,6 @@ const errorRouter = { key: '404', }, }, - { - path: '500', - name: '500', - hidden: true, - component: () => import('@/components/error-message/500.vue'), - meta: { - requiresAuth: false, - title: '500页面', - key: '500', - }, - }, ], }; export default errorRouter; diff --git a/frontend/src/views/container/container/reName/index.vue b/frontend/src/views/container/container/reName/index.vue index ba1403ee1..4a39c5ae8 100644 --- a/frontend/src/views/container/container/reName/index.vue +++ b/frontend/src/views/container/container/reName/index.vue @@ -1,17 +1,9 @@ - + diff --git a/frontend/src/views/setting/about/index.vue b/frontend/src/views/setting/about/index.vue index ef2c1f4c8..8ad13a368 100644 --- a/frontend/src/views/setting/about/index.vue +++ b/frontend/src/views/setting/about/index.vue @@ -35,7 +35,7 @@ - + @@ -49,16 +49,13 @@ - - - Gitee - GitHub - - - - {{ $t('setting.upgradeNow') }} - + @@ -75,7 +72,6 @@ import DrawerHeader from '@/components/drawer-header/index.vue'; const version = ref(); const upgradeInfo = ref(); -const Source = ref('gitee'); const drawerVisiable = ref(); const refresh = ref(); @@ -103,13 +99,20 @@ const handleClose = () => { }; const onLoadUpgradeInfo = async () => { - const res = await loadUpgradeInfo(); - if (!res.data) { - ElMessage.info(i18n.global.t('setting.noUpgrade')); - return; - } - upgradeInfo.value = res.data; - drawerVisiable.value = true; + loading.value = true; + await loadUpgradeInfo() + .then((res) => { + loading.value = false; + if (!res.data) { + ElMessage.info(i18n.global.t('setting.noUpgrade')); + return; + } + upgradeInfo.value = res.data; + drawerVisiable.value = true; + }) + .catch(() => { + loading.value = false; + }); }; const onUpgrade = async () => { ElMessageBox.confirm(i18n.global.t('setting.upgradeHelper', i18n.global.t('setting.upgrade')), { @@ -118,11 +121,7 @@ const onUpgrade = async () => { type: 'info', }).then(() => { loading.value = true; - let param = { - version: upgradeInfo.value.newVersion, - source: Source.value, - }; - upgrade(param) + upgrade(upgradeInfo.value.newVersion) .then(() => { loading.value = false; drawerVisiable.value = false; diff --git a/frontend/src/views/website/website/status/index.vue b/frontend/src/views/website/website/status/index.vue index 95418c0e6..16d8fd857 100644 --- a/frontend/src/views/website/website/status/index.vue +++ b/frontend/src/views/website/website/status/index.vue @@ -13,7 +13,7 @@
- + {{ $t('website.expireDate') }}: {{ $t('website.neverExpire') }}