mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
use mirror for asset download in update command (#1035)
This commit is contained in:
@@ -108,6 +108,8 @@ func (p *plugin) update() (updated bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var latest *release
|
var latest *release
|
||||||
|
var useMirror bool
|
||||||
|
|
||||||
latest, err = fetchLatestRelease(
|
latest, err = fetchLatestRelease(
|
||||||
p.config.Context,
|
p.config.Context,
|
||||||
p.config.HttpClient,
|
p.config.HttpClient,
|
||||||
@@ -116,6 +118,7 @@ func (p *plugin) update() (updated bool, err error) {
|
|||||||
// if the first fetch fails, try the beszel.dev API (fallback for China)
|
// if the first fetch fails, try the beszel.dev API (fallback for China)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ColorPrint(ColorYellow, "Failed to fetch release. Trying beszel.dev mirror...")
|
ColorPrint(ColorYellow, "Failed to fetch release. Trying beszel.dev mirror...")
|
||||||
|
useMirror = true
|
||||||
latest, err = fetchLatestRelease(
|
latest, err = fetchLatestRelease(
|
||||||
p.config.Context,
|
p.config.Context,
|
||||||
p.config.HttpClient,
|
p.config.HttpClient,
|
||||||
@@ -147,7 +150,7 @@ func (p *plugin) update() (updated bool, err error) {
|
|||||||
|
|
||||||
// download the release asset
|
// download the release asset
|
||||||
assetPath := filepath.Join(releaseDir, asset.Name)
|
assetPath := filepath.Join(releaseDir, asset.Name)
|
||||||
if err := downloadFile(p.config.Context, p.config.HttpClient, asset.DownloadUrl, assetPath); err != nil {
|
if err := downloadFile(p.config.Context, p.config.HttpClient, asset.DownloadUrl, assetPath, useMirror); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +278,11 @@ func downloadFile(
|
|||||||
client HttpClient,
|
client HttpClient,
|
||||||
url string,
|
url string,
|
||||||
destPath string,
|
destPath string,
|
||||||
|
useMirror bool,
|
||||||
) error {
|
) error {
|
||||||
|
if useMirror {
|
||||||
|
url = strings.Replace(url, "github.com", "gh.beszel.dev", 1)
|
||||||
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
- Add battery charge monitoring.
|
- Add battery charge monitoring.
|
||||||
|
|
||||||
|
- Add fallback mirror to the `update` commands. (#1035)
|
||||||
|
|
||||||
- Fix blank token field in insecure contexts.
|
- Fix blank token field in insecure contexts.
|
||||||
|
|
||||||
- Allow opening internal router links in new tab.
|
- Allow opening internal router links in new tab.
|
||||||
|
Reference in New Issue
Block a user