js: Default to linux-amd64 and fix split() call on platform (#187)

In certain cases where the platform cannot be automatically determined, we should at least populate a default so that the download page doesn't break.
This commit is contained in:
Francis Lavoie 2021-08-13 16:59:45 -04:00 committed by GitHub
parent 5f09f05e08
commit a7861e98f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View file

@ -23,8 +23,7 @@
<div> <div>
<div> <div>
<b>Platform:</b> <b>Platform:</b>
<select size="1" id="platform"> <select size="1" id="platform" selected="linux-amd64">
<option></option>
<option value="dragonfly-amd64">Dragonfly amd64</option> <option value="dragonfly-amd64">Dragonfly amd64</option>
<option value="freebsd-amd64">FreeBSD amd64</option> <option value="freebsd-amd64">FreeBSD amd64</option>
<option value="freebsd-arm-6">FreeBSD arm 6</option> <option value="freebsd-arm-6">FreeBSD arm 6</option>

View file

@ -169,11 +169,11 @@ $(function() {
}); });
}) })
// autoPlatform choooses the platform in the list that best // autoPlatform chooses the platform in the list that best
// matches the user's browser, if it's available. // matches the user's browser, if it's available.
function autoPlatform() { function autoPlatform() {
// assume 32-bit linux, then change OS and architecture if justified // assume 32-bit linux, then change OS and architecture if justified
var os = "linux", arch = "386", arm = ""; var os = "linux", arch = "amd64", arm = "";
// change os // change os
if (/Macintosh/i.test(navigator.userAgent)) { if (/Macintosh/i.test(navigator.userAgent)) {
@ -215,11 +215,15 @@ function autoPlatform() {
} }
function getDownloadLink() { function getDownloadLink() {
// make sure we at least have a default,
// in the case that autoPlatform() failed
var platformString = $('#platform').val();
if (!platformString) {
platformString = "linux-amd64"
}
// get platform components // get platform components
var platformParts = $('#platform').val().split("-"); var [os, arch, arm = ""] = platformString.split("-");
var os = platformParts[0];
var arch = platformParts[1];
var arm = platformParts.length > 2 ? platformParts[2] : "";
var qs = new URLSearchParams(); var qs = new URLSearchParams();
if (os) qs.set("os", os); if (os) qs.set("os", os);