Skip to content

Commit

Permalink
Add vencord.dev/releases fallback for github release data
Browse files Browse the repository at this point in the history
  • Loading branch information
Vendicated committed May 17, 2023
1 parent a551bdf commit 784a9dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ var InstallerGitHash = "Unknown"
var InstallerTag = "Unknown"

const ReleaseUrl = "https://api.github.com/repos/Vendicated/Vencord/releases/latest"
const ReleaseUrlFallback = "https://vencord.dev/releases/vencord"
const InstallerReleaseUrl = "https://api.github.com/repos/Vencord/Installer/releases/latest"
const InstallerReleaseUrlFallback = "https://vencord.dev/releases/installer"

var UserAgent = "VencordInstaller/" + InstallerGitHash + " (https://github.com/Vencord/Installer)"

Expand Down
16 changes: 13 additions & 3 deletions github_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var InstalledHash = "None"
var LatestHash = "Unknown"
var IsDevInstall bool

func GetGithubRelease(url string) (*GithubRelease, error) {
func GetGithubRelease(url, fallbackUrl string) (*GithubRelease, error) {
fmt.Println("Fetching", url)

req, err := http.NewRequest("GET", url, nil)
Expand All @@ -57,8 +57,18 @@ func GetGithubRelease(url string) (*GithubRelease, error) {
defer res.Body.Close()

if res.StatusCode >= 300 {
isRateLimitedOrBlocked := res.StatusCode == 401 || res.StatusCode == 403 || res.StatusCode == 429
triedFallback := url == fallbackUrl

// GitHub has a very strict 60 req/h rate limit and some (mostly indian) isps block github for some reason.
// If that is the case, try our fallback at https://vencord.dev/releases/project
if isRateLimitedOrBlocked && !triedFallback {
fmt.Println("Failed to fetch " + url + ". Trying fallback url " + fallbackUrl)
return GetGithubRelease(fallbackUrl, fallbackUrl)
}

err = errors.New(res.Status)
fmt.Println("Github returned Non-OK status", GithubError)
fmt.Println("GitHub Api returned Non-OK status", GithubError)
return nil, err
}

Expand Down Expand Up @@ -88,7 +98,7 @@ func InitGithubDownloader() {
GithubDoneChan <- GithubError == nil
}()

data, err := GetGithubRelease(ReleaseUrl)
data, err := GetGithubRelease(ReleaseUrl, ReleaseUrlFallback)
if err != nil {
GithubError = err
return
Expand Down
2 changes: 1 addition & 1 deletion self_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var IsInstallerOutdated = false
func CheckSelfUpdate() {
fmt.Println("Checking for Installer Updates...")

res, err := GetGithubRelease(InstallerReleaseUrl)
res, err := GetGithubRelease(InstallerReleaseUrl, InstallerReleaseUrlFallback)
if err == nil {
IsInstallerOutdated = res.TagName != InstallerTag
}
Expand Down

0 comments on commit 784a9dd

Please sign in to comment.