Procházet zdrojové kódy

cmd/stupgrades: Serve friendlier URLs for upgrade assets (fixes #9033)

Jakob Borg před 2 roky
rodič
revize
462389934b
2 změnil soubory, kde provedl 11 přidání a 1 odebrání
  1. 10 0
      cmd/stupgrades/main.go
  2. 1 1
      lib/upgrade/upgrade_common.go

+ 10 - 0
cmd/stupgrades/main.go

@@ -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)
 

+ 1 - 1
lib/upgrade/upgrade_common.go

@@ -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 (