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