mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-05 04:47:54 +00:00
Use axios instead of request
This commit is contained in:
parent
d2ed86e62c
commit
9a9a63c15a
@ -1,29 +1,25 @@
|
||||
import request from 'request';
|
||||
import axios from 'axios';
|
||||
import _ from 'lodash';
|
||||
|
||||
const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json';
|
||||
|
||||
function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request(url, (error, response, body) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
|
||||
return axios.get(url)
|
||||
.then(response => {
|
||||
if (response.status !== 200) {
|
||||
throw `Bad request: Status code ${response.status}`;
|
||||
}
|
||||
if (response.statusCode === 200) {
|
||||
const data = JSON.parse(body);
|
||||
const electronVersionToChromeVersion = _.zipObject(data.map(d => d.version), data.map(d => d.chrome));
|
||||
if (!(electronVersion in electronVersionToChromeVersion)) {
|
||||
reject(`Electron version '${ electronVersion }' not found in retrieved version list!`);
|
||||
return;
|
||||
}
|
||||
resolve(electronVersionToChromeVersion[electronVersion]);
|
||||
return;
|
||||
|
||||
const data = response.data;
|
||||
const electronVersionToChromeVersion = _.zipObject(data.map(d => d.version), data.map(d => d.chrome));
|
||||
|
||||
if (!(electronVersion in electronVersionToChromeVersion)) {
|
||||
throw `Electron version '${ electronVersion }' not found in retrieved version list!`;
|
||||
}
|
||||
reject('Bad request: ' + response.statusCode);
|
||||
return;
|
||||
|
||||
return electronVersionToChromeVersion[electronVersion];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function getUserAgentString(chromeVersion, platform) {
|
||||
|
Loading…
Reference in New Issue
Block a user