Skip to content

Commit

Permalink
fix(download): download failed when using ELECTRON_MIRROR (#74)
Browse files Browse the repository at this point in the history
* feat: update electron download url join

* chore: change func name

Update pkg/electron/electronDownloader.go

Co-authored-by: Black-Hole <[email protected]>

chore: change func name
  • Loading branch information
bytemain authored Mar 9, 2022
1 parent 2ac6d52 commit 7e5f330
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/electron/electronDownloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,32 @@ func getBaseUrl(config *ElectronDownloadOptions) string {
}
if len(v) == 0 {
if strings.Contains(config.Version, "-nightly.") {
return "https://github.com/electron/nightlies/releases/download/v"
v = "https://github.com/electron/nightlies/releases/download/"
} else {
return "https://github.com/electron/electron/releases/download/v"
v = "https://github.com/electron/electron/releases/download/"
}
}
// Compatibility with previous code caused user who need to set mirror with a suffix `/v`
if strings.HasSuffix(v, "/v") {
v = v[:len(v)-1]
}
return v
}

func normalizeVersion(version string) string {
if strings.HasPrefix(version, "v") {
return version
}
return "v" + version
}

func getMiddleUrl(config *ElectronDownloadOptions) string {
v := os.Getenv("ELECTRON_CUSTOM_DIR")
if len(v) == 0 {
v = config.CustomDir
}
if len(v) == 0 {
v = config.Version
v = normalizeVersion(config.Version)
}
return v
}
Expand All @@ -126,7 +137,7 @@ func getUrlSuffix(config *ElectronDownloadOptions) string {
}

func getFilename(config *ElectronDownloadOptions) string {
return "electron-v" + config.Version + "-" + config.Platform + "-" + config.Arch + ".zip"
return "electron-" + normalizeVersion(config.Version) + "-" + config.Platform + "-" + config.Arch + ".zip"
}

type ElectronDownloader struct {
Expand Down

0 comments on commit 7e5f330

Please sign in to comment.