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) {
if (xhr.status === 200) {
try {
const files = JSON.parse(xhr.responseText);
const actions = [];
files.forEach(file => {
actions.push(doDownloadLanguage(file));
});
response.on("data", chunk => { dispatch(batchActions(...actions));
str += chunk; } catch (err) {
}); throw err;
}
response.on("end", () => { } else {
const files = JSON.parse(str); throw new Error(
const actions = []; __("The list of available languages could not be retrieved.")
files.forEach(file => { );
actions.push(doDownloadLanguage(file)); }
}); }
};
dispatch(batchActions(...actions)); xhr.open("get", "http://i18n.lbry.io");
}); xhr.send();
});
req.on("error", err => {
throw err; //this ought to be cleanly handled
});
req.end();
}; };
} }