SectorFileUpdater/src/getFiles.js

50 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-01-14 01:26:26 +01:00
async function getUpdates() {
const courses = await superagent.get('https://files.aero-nav.com/');
let text = courses.text.match(/Download Pages([^]*?)<\/body>/g);
let liste = text[0].match(/<b>(.*?)<\/b>/g).map(item => item.replace(/<\/?b>/g, ""));
liste.forEach(item => {
var option = document.createElement("option");
option.text = item;
dropDownGNG.add(option);
});
getFiles();
}
async function getFiles() {
2023-01-16 01:18:52 +01:00
await delay(300)
2023-01-14 01:26:26 +01:00
await removeFileItems();
let region = "https://files.aero-nav.com/" + dropDownGNG.options[dropDownGNG.selectedIndex].text;
let courses = await superagent.get(region);
let text = courses.text.split("Released</th><th colspan='2'>Download</th></tr>").pop();
text = text.split("<h1>AIRAC <small>News</small></h1>")[0];
let rows = text.match(/<td>(.*?)<\/td>/g).map(row => row.replace(/<\/?td>/g, ""));
let fileNames = rows.filter((row, index) => index % 5 === 1);
2023-01-16 01:18:52 +01:00
let versionNumbers = rows.filter((row, index) => index % 5 === 2).map(versionNumber => versionNumber.split('/').map(e => e.trim()));
2023-01-14 01:26:26 +01:00
let hrefLinks = rows.filter((row, index) => index % 5 === 4).map(row => row.match(/href="(.*?)"/)[1]);
2023-01-16 01:18:52 +01:00
let data = fileNames.map((fileName, index) => [fileName, versionNumbers[index], hrefLinks[index]]);
2023-01-14 01:26:26 +01:00
removeFileItems();
2023-01-16 01:18:52 +01:00
data.forEach(row => {
2023-01-14 01:26:26 +01:00
let option = document.createElement("option");
2023-01-16 01:18:52 +01:00
option.text = row[0];
option.version = row[1];
option.href = row[2];
2023-01-14 01:26:26 +01:00
dropDownFiles.add(option);
});
2023-01-16 01:18:52 +01:00
2023-01-14 01:26:26 +01:00
if (structure.file != -1) {
dropDownFiles.selectedIndex = structure.file;
}
2023-01-16 01:18:52 +01:00
if (structure.currentInstalledAirac !== dropDownFiles.options[dropDownFiles.selectedIndex].version[0] ||
structure.version !== dropDownFiles.options[dropDownFiles.selectedIndex].version[1]) {
document.getElementById("download").style.display = "block";
}
save();
2023-01-14 01:26:26 +01:00
return hrefLinks;
}