fix(upgrader): use cloud.nginxui.com as proxy by default

This commit is contained in:
Jacky 2025-05-05 05:47:40 +00:00
parent 3d886fded6
commit 5a34d5ca9a
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
5 changed files with 50 additions and 30 deletions

View file

@ -22,7 +22,6 @@ func BinaryUpgrade(ws *websocket.Conn, control *Control) {
}) })
u, err := NewUpgrader(control.Channel) u, err := NewUpgrader(control.Channel)
if err != nil { if err != nil {
_ = ws.WriteJSON(CoreUpgradeResp{ _ = ws.WriteJSON(CoreUpgradeResp{
Status: UpgradeStatusError, Status: UpgradeStatusError,

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -36,6 +35,7 @@ type CoreUpgradeResp struct {
} }
type Upgrader struct { type Upgrader struct {
Channel string
Release version.TRelease Release version.TRelease
version.RuntimeInfo version.RuntimeInfo
} }
@ -50,6 +50,7 @@ func NewUpgrader(channel string) (u *Upgrader, err error) {
return return
} }
u = &Upgrader{ u = &Upgrader{
Channel: channel,
Release: data, Release: data,
RuntimeInfo: runtimeInfo, RuntimeInfo: runtimeInfo,
} }
@ -153,12 +154,8 @@ func (u *Upgrader) DownloadLatestRelease(progressChan chan float64) (tarName str
} }
githubProxy := settings.HTTPSettings.GithubProxy githubProxy := settings.HTTPSettings.GithubProxy
if githubProxy != "" { if githubProxy != "" && u.Channel != string(version.ReleaseTypeDev) {
digest.BrowserDownloadUrl, err = url.JoinPath(githubProxy, digest.BrowserDownloadUrl) digest.BrowserDownloadUrl = version.GetUrl(digest.BrowserDownloadUrl)
if err != nil {
err = errors.Wrap(err, "service.DownloadLatestRelease url.JoinPath error")
return
}
} }
resp, err := http.Get(digest.BrowserDownloadUrl) resp, err := http.Get(digest.BrowserDownloadUrl)
@ -171,12 +168,8 @@ func (u *Upgrader) DownloadLatestRelease(progressChan chan float64) (tarName str
dir := filepath.Dir(u.ExPath) dir := filepath.Dir(u.ExPath)
if githubProxy != "" { if githubProxy != "" && u.Channel != string(version.ReleaseTypeDev) {
downloadUrl, err = url.JoinPath(githubProxy, downloadUrl) downloadUrl = version.GetUrl(downloadUrl)
if err != nil {
err = errors.Wrap(err, "service.DownloadLatestRelease url.JoinPath error")
return
}
} }
tarName, err = downloadRelease(downloadUrl, dir, progressChan) tarName, err = downloadRelease(downloadUrl, dir, progressChan)

View file

@ -10,11 +10,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const (
GithubDevCommitAPI = "https://cloud.nginxui.com/https://api.github.com/repos/0xJacky/nginx-ui/commits/dev?per_page=1"
CloudflareWorkerAPI = "https://cloud.nginxui.com"
)
type TCommit struct { type TCommit struct {
SHA string `json:"sha"` SHA string `json:"sha"`
Commit struct { Commit struct {
@ -26,7 +21,7 @@ type TCommit struct {
} }
func getDevBuild() (data TRelease, err error) { func getDevBuild() (data TRelease, err error) {
resp, err := http.Get(GithubDevCommitAPI) resp, err := http.Get(GetGithubDevCommitAPIUrl())
if err != nil { if err != nil {
return return
} }
@ -47,7 +42,7 @@ func getDevBuild() (data TRelease, err error) {
} }
shortSHA := commit.SHA[:7] shortSHA := commit.SHA[:7]
resp, err = http.Get(fmt.Sprintf("%s/dev-builds", CloudflareWorkerAPI)) resp, err = http.Get(fmt.Sprintf("%sdev-builds", CloudflareWorkerAPI))
if err != nil { if err != nil {
return return
} }

View file

@ -9,11 +9,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
const (
GithubLatestReleaseAPI = "https://cloud.nginxui.com/https://api.github.com/repos/0xJacky/nginx-ui/releases/latest"
GithubReleasesListAPI = "https://cloud.nginxui.com/https://api.github.com/repos/0xJacky/nginx-ui/releases"
)
type ReleaseType string type ReleaseType string
const ( const (
@ -47,10 +42,8 @@ func (t *TRelease) GetAssetsMap() (m map[string]TReleaseAsset) {
} }
func getLatestRelease() (data TRelease, err error) { func getLatestRelease() (data TRelease, err error) {
resp, err := http.Get(GithubLatestReleaseAPI) resp, err := http.Get(GetGithubLatestReleaseAPIUrl())
if err != nil { if err != nil {
err = errors.Wrap(err, "service.getLatestRelease http.Get err")
return
} }
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
@ -72,7 +65,7 @@ func getLatestRelease() (data TRelease, err error) {
} }
func getLatestPrerelease() (data TRelease, err error) { func getLatestPrerelease() (data TRelease, err error) {
resp, err := http.Get(GithubReleasesListAPI) resp, err := http.Get(GetGithubReleasesListAPIUrl())
if err != nil { if err != nil {
err = errors.Wrap(err, "service.getLatestPrerelease http.Get err") err = errors.Wrap(err, "service.getLatestPrerelease http.Get err")
return return

40
internal/version/url.go Normal file
View file

@ -0,0 +1,40 @@
package version
import (
"strings"
"github.com/0xJacky/Nginx-UI/settings"
)
const (
GithubDevCommitAPI = "https://api.github.com/repos/0xJacky/nginx-ui/commits/dev?per_page=1"
CloudflareWorkerAPI = "https://cloud.nginxui.com/"
GithubLatestReleaseAPI = "https://api.github.com/repos/0xJacky/nginx-ui/releases/latest"
GithubReleasesListAPI = "https://api.github.com/repos/0xJacky/nginx-ui/releases"
)
func GetGithubDevCommitAPIUrl() string {
return GetUrl(GithubDevCommitAPI)
}
func GetGithubLatestReleaseAPIUrl() string {
return GetUrl(GithubLatestReleaseAPI)
}
func GetGithubReleasesListAPIUrl() string {
return GetUrl(GithubReleasesListAPI)
}
func GetCloudflareWorkerAPIUrl() string {
return GetUrl(CloudflareWorkerAPI)
}
func GetUrl(path string) string {
githubProxy := settings.HTTPSettings.GithubProxy
if githubProxy == "" {
githubProxy = CloudflareWorkerAPI
}
githubProxy = strings.TrimSuffix(githubProxy, "/")
return githubProxy + "/" + path
}