2019-10-02 19:20:37 +02:00
|
|
|
async function getTextFromFileUrlAsync(url) {
|
2019-09-09 15:15:39 +02:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
var req = new XMLHttpRequest();
|
2020-03-20 11:10:56 +01:00
|
|
|
req.setRequestHeader("Cache-Control: no-cache, no-store, must-revalidate")
|
2019-10-02 19:20:37 +02:00
|
|
|
req.open("GET",url, true);
|
2019-09-09 15:15:39 +02:00
|
|
|
req.onreadystatechange = function() {
|
|
|
|
if (req.readyState == 4) {
|
|
|
|
if (req.status == 200) {//when a good response is given do this
|
|
|
|
var text = req.responseText;
|
|
|
|
resolve(text);
|
|
|
|
} else {
|
|
|
|
reject({
|
|
|
|
status: req.status,
|
|
|
|
statusText: req.statusText
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.send();
|
|
|
|
});
|
2019-10-02 19:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getTextFromUploadedFileAsync(inputFile){
|
|
|
|
const temporaryFileReader = new FileReader();
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
temporaryFileReader.onerror = () => {
|
|
|
|
temporaryFileReader.abort();
|
|
|
|
reject(new DOMException("Problem parsing input file."));
|
|
|
|
};
|
|
|
|
|
|
|
|
temporaryFileReader.onload = () => {
|
|
|
|
resolve(temporaryFileReader.result);
|
|
|
|
};
|
|
|
|
temporaryFileReader.readAsText(inputFile);
|
|
|
|
});
|
|
|
|
};
|