2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-11 07:41:04 +00:00

Use axios instead of request

This commit is contained in:
Jia Hao 2016-03-25 19:58:03 +08:00
parent d2ed86e62c
commit 9a9a63c15a

View File

@ -1,28 +1,24 @@
import request from 'request'; import axios from 'axios';
import _ from 'lodash'; import _ from 'lodash';
const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json'; const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json';
function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) { function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) {
return new Promise((resolve, reject) => {
request(url, (error, response, body) => { return axios.get(url)
if (error) { .then(response => {
reject(error); if (response.status !== 200) {
return; throw `Bad request: Status code ${response.status}`;
} }
if (response.statusCode === 200) {
const data = JSON.parse(body); const data = response.data;
const electronVersionToChromeVersion = _.zipObject(data.map(d => d.version), data.map(d => d.chrome)); const electronVersionToChromeVersion = _.zipObject(data.map(d => d.version), data.map(d => d.chrome));
if (!(electronVersion in electronVersionToChromeVersion)) { if (!(electronVersion in electronVersionToChromeVersion)) {
reject(`Electron version '${ electronVersion }' not found in retrieved version list!`); throw `Electron version '${ electronVersion }' not found in retrieved version list!`;
return;
} }
resolve(electronVersionToChromeVersion[electronVersion]);
return; return electronVersionToChromeVersion[electronVersion];
}
reject('Bad request: ' + response.statusCode);
return;
});
}); });
} }