fix: getLatestVersion()
This commit is contained in:
parent
457d23d414
commit
c697c41ad2
|
@ -1,32 +1,24 @@
|
|||
let getLatestVersion = function() {
|
||||
function getLatestVersion() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// if (typeof milliseconds !== "number") {
|
||||
// throw new Error("milleseconds not a number");
|
||||
// }
|
||||
|
||||
const xmlHttpRequest = new XMLHttpRequest();
|
||||
xmlHttpRequest.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
if (this.response) {
|
||||
const latestURL = this.response["assets"][0].browser_download_url;
|
||||
console.log(latestURL);
|
||||
const latestVersion = latestURL.match(/(\d+).(\d+).(\d+)/g)[0];
|
||||
console.log(latestVersion);
|
||||
return latestVersion;
|
||||
}
|
||||
const xhr = new XMLHttpRequest();
|
||||
const url = "https://api.github.com/repos/gohugoio/hugo/releases/latest";
|
||||
xhr.open("GET", url);
|
||||
xhr.send();
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
const result = JSON.parse(xhr.responseText);
|
||||
const latestURL = result["assets"][0].browser_download_url;
|
||||
const latestVersion = latestURL.match(/(\d+).(\d+).(\d+)/g)[0];
|
||||
|
||||
resolve(latestVersion);
|
||||
}
|
||||
};
|
||||
|
||||
xmlHttpRequest.open(
|
||||
"GET",
|
||||
"https://api.github.com/repos/gohugoio/hugo/releases/latest",
|
||||
true
|
||||
);
|
||||
xmlHttpRequest.responseType = "json";
|
||||
xmlHttpRequest.send(null);
|
||||
|
||||
resolve(version);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = getLatestVersion;
|
||||
|
|
Loading…
Reference in New Issue