use mirror for asset download in update command (#1035)

This commit is contained in:
henrygd
2025-08-25 20:18:31 -04:00
parent 6e9dbf863f
commit 1990f8c6df
2 changed files with 10 additions and 1 deletions

View File

@@ -108,6 +108,8 @@ func (p *plugin) update() (updated bool, err error) {
}
var latest *release
var useMirror bool
latest, err = fetchLatestRelease(
p.config.Context,
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 err != nil {
ColorPrint(ColorYellow, "Failed to fetch release. Trying beszel.dev mirror...")
useMirror = true
latest, err = fetchLatestRelease(
p.config.Context,
p.config.HttpClient,
@@ -147,7 +150,7 @@ func (p *plugin) update() (updated bool, err error) {
// download the release asset
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
}
@@ -275,7 +278,11 @@ func downloadFile(
client HttpClient,
url string,
destPath string,
useMirror bool,
) error {
if useMirror {
url = strings.Replace(url, "github.com", "gh.beszel.dev", 1)
}
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return err

View File

@@ -2,6 +2,8 @@
- Add battery charge monitoring.
- Add fallback mirror to the `update` commands. (#1035)
- Fix blank token field in insecure contexts.
- Allow opening internal router links in new tab.