modified doDownloadLanguages to use XMLHttpRequest instead of http.request

This commit is contained in:
Akinwale Ariwodola 2017-08-21 16:03:51 +01:00
parent cefc882474
commit efd2b99cda

View file

@ -104,29 +104,30 @@ export function doDownloadLanguages() {
fs.mkdirSync(app.i18n.directory); fs.mkdirSync(app.i18n.directory);
} }
const req = http.request({ host: "i18n.lbry.io", path: "/" }, response => { const xhr = new XMLHttpRequest();
let str = ""; xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
response.on("data", chunk => { if (xhr.status === 200) {
str += chunk; try {
}); const files = JSON.parse(xhr.responseText);
response.on("end", () => {
const files = JSON.parse(str);
const actions = []; const actions = [];
files.forEach(file => { files.forEach(file => {
actions.push(doDownloadLanguage(file)); actions.push(doDownloadLanguage(file));
}); });
dispatch(batchActions(...actions)); dispatch(batchActions(...actions));
}); } catch (err) {
}); throw err;
}
req.on("error", err => { } else {
throw err; //this ought to be cleanly handled throw new Error(
}); __("The list of available languages could not be retrieved.")
);
req.end(); }
}
};
xhr.open("get", "http://i18n.lbry.io");
xhr.send();
}; };
} }