Skip to content

Commit

Permalink
cmd/stupgrades: Serve friendlier URLs for upgrade assets (fixes #9033)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Aug 9, 2023
1 parent b347c14 commit 4623899
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/stupgrades/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func (p *githubReleases) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
sort.Sort(upgrade.SortByRelease(rels))
rels = filterForLatest(rels)

// Move the URL used for browser downloads to the URL field, and remove
// the browser URL field. This avoids going via the GitHub API for
// downloads, since Syncthing uses the URL field.
for _, rel := range rels {
for j, asset := range rel.Assets {
rel.Assets[j].URL = asset.BrowserURL
rel.Assets[j].BrowserURL = ""
}
}

buf := new(bytes.Buffer)
_ = json.NewEncoder(buf).Encode(rels)

Expand Down
2 changes: 1 addition & 1 deletion lib/upgrade/upgrade_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Asset struct {

// The browser URL is needed for human readable links in the output created
// by cmd/stupgrades.
BrowserURL string `json:"browser_download_url"`
BrowserURL string `json:"browser_download_url,omitempty"`
}

var (
Expand Down

0 comments on commit 4623899

Please sign in to comment.