etwas besser geschrieben + href added

This commit is contained in:
PaulaBras 2022-11-06 21:19:00 +01:00
parent 5a71d336fb
commit cc300769b4
6 changed files with 97 additions and 18 deletions

View File

@ -13,6 +13,7 @@
"decompress-zip": "^0.3.3", "decompress-zip": "^0.3.3",
"electron-dl": "^3.3.1", "electron-dl": "^3.3.1",
"electron-squirrel-startup": "^1.0.0", "electron-squirrel-startup": "^1.0.0",
"http": "^0.0.1-security",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"superagent": "^8.0.3" "superagent": "^8.0.3"
}, },
@ -3597,6 +3598,11 @@
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true "dev": true
}, },
"node_modules/http": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
"integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g=="
},
"node_modules/http-cache-semantics": { "node_modules/http-cache-semantics": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
@ -9216,6 +9222,11 @@
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
"dev": true "dev": true
}, },
"http": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz",
"integrity": "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g=="
},
"http-cache-semantics": { "http-cache-semantics": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",

View File

@ -49,6 +49,7 @@
"decompress-zip": "^0.3.3", "decompress-zip": "^0.3.3",
"electron-dl": "^3.3.1", "electron-dl": "^3.3.1",
"electron-squirrel-startup": "^1.0.0", "electron-squirrel-startup": "^1.0.0",
"http": "^0.0.1-security",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"superagent": "^8.0.3" "superagent": "^8.0.3"
}, },

View File

@ -12,9 +12,9 @@
<p id="ouput">Output Test here</p> <p id="ouput">Output Test here</p>
<p>Input URL</p> <p>Input URL</p>
<input type="text" id="urlBox" name="name" size="80"> <input type="text" id="urlBox" name="name" size="80" readonly>
<p>Input Directory</p> <p>Input Directory</p>
<input type="text" id="dirBox" name="name" size="80"> <input type="text" id="dirBox" name="name" size="80" readonly>
<progress id="progressbar" max="100" value="0"></progress> <progress id="progressbar" max="100" value="0"></progress>

View File

@ -5,6 +5,9 @@ const path = require('path');
var fs = require('fs'); var fs = require('fs');
const yaml = require('js-yaml'); const yaml = require('js-yaml');
var DecompressZip = require('decompress-zip'); var DecompressZip = require('decompress-zip');
const { Http2ServerRequest } = require('http2');
const superagent = require('superagent').agent();
const http = require('node:http');
// Handle creating/removing shortcuts on Windows when installing/uninstalling. // Handle creating/removing shortcuts on Windows when installing/uninstalling.
// eslint-disable-next-line global-require // eslint-disable-next-line global-require
@ -75,8 +78,23 @@ const createWindow = () => {
ipcMain.on("download", (event, info) => { ipcMain.on("download", (event, info) => {
// https://dms.pabr.de/s/SpBiQYADTNak7R5/download // https://dms.pabr.de/s/SpBiQYADTNak7R5/download
info.properties.onProgress = status => mainWindow.webContents.send("download progress", status); info.properties.onProgress = status => mainWindow.webContents.send("download progress", status);
download(BrowserWindow.getFocusedWindow(), info.url, info.properties) // http.request
.then(dl => mainWindow.webContents.send("download complete", dl.getSavePath())); let file = superagent.get('https://files.aero-nav.com/EDGG/Full_Package_20221104183433-221101-3.zip')
.set('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0')
.set('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8')
.set('Accept-Language', 'en-US,en;q=0.5')
.set('Accept-Encoding', 'gzip, deflate, br')
.set('DNT', '1')
.set('Connection', 'keep-alive')
.set('Referer', 'http://files.aero-nav.com/')
.set('Upgrade-Insecure-Requests', '1')
.set('Sec-Fetch-Dest', 'document')
.set('Sec-Fetch-Mode', 'navigate')
.set('Sec-Fetch-Site', 'cross-site')
.set('Sec-Fetch-User', '?1');
// Working Download
// download(BrowserWindow.getFocusedWindow(), info.url, info.properties)
// .then(dl => mainWindow.webContents.send("download complete", dl.getSavePath()));
}); });

View File

@ -1,6 +1,10 @@
const { ipcRenderer, dialog } = require('electron'); const { ipcRenderer, dialog } = require('electron');
const superagent = require('superagent').agent(); const superagent = require('superagent').agent();
// Global Variabels
let hrefLinks = "";
ipcRenderer.on("download complete", (event, file) => { ipcRenderer.on("download complete", (event, file) => {
console.log(file); // Full file path console.log(file); // Full file path
// Datei entpacken // Datei entpacken
@ -11,13 +15,17 @@ ipcRenderer.on("download progress", (event, progress) => {
document.getElementById('progressbar').value = cleanProgressInPercentages; document.getElementById('progressbar').value = cleanProgressInPercentages;
}); });
let fileSelect = document.getElementById('files');
let donwloadBtn = document.getElementById('download'); let donwloadBtn = document.getElementById('download');
donwloadBtn.addEventListener('click', (e) => { donwloadBtn.addEventListener('click', (e) => {
let directoryPath = document.getElementById('dirBox'); let directoryPath = document.getElementById('dirBox');
let urlPath = document.getElementById('urlBox'); let urlPath = document.getElementById('urlBox');
console.log(hrefLinks[fileSelect.options.selectedIndex]);
ipcRenderer.send("download", { ipcRenderer.send("download", {
url: urlPath.value, url: hrefLinks[fileSelect.options.selectedIndex],
properties: { directory: directoryPath.value } properties: {
directory: directoryPath.value
}
}); });
}); });
@ -51,20 +59,22 @@ const removeFileItems = async() => {
const getUpdates = async() => { const getUpdates = async() => {
// Get all GNG Options // Get all GNG Options
let courses = await superagent.get('https://files.aero-nav.com/'); let courses = await superagent.get('https://files.aero-nav.com/');
let text = courses.text.split("Download Pages").pop(); let text = courses.text.split("Download Pages").pop();
let textArray = text.split("\n");
let liste = ""; let liste = "";
for (var i = 0; i < text.length; i++) { let firstElement = "<b>";
if (text[i] === ">" && text[i - 1] === "b" && text[i - 2] === "<") { let lastElement = "</b>";
let i2 = i + 1; textArray.forEach(element => {
while (text[i2] !== "<") { if (element.includes(firstElement)) {
liste += text[i2]; liste += element.substring(
i2++; element.indexOf(firstElement) + firstElement.length,
} element.indexOf(lastElement, element.indexOf(firstElement))) +
liste += "\n"; "\n";
} }
} });
const listeArray = liste.split("\n"); const listeArray = liste.split("\n");
// Add to html selector // Add to html selector
@ -82,7 +92,8 @@ const getUpdates = async() => {
// Check Files // Check Files
let getFilesBtn = document.getElementById('getFiles'); let getFilesBtn = document.getElementById('getFiles');
getFilesBtn.addEventListener('click', (e) => { getFilesBtn.addEventListener('click', (e) => {
getFiles(); hrefLinks = getFiles();
console.log("leaveme alone " + hrefLinks);
}); });
const getFiles = async() => { const getFiles = async() => {
@ -92,8 +103,27 @@ const getFiles = async() => {
let courses = await superagent.get(region); let courses = await superagent.get(region);
let text = courses.text.split("Released</th><th colspan='2'>Download</th></tr>").pop(); let text = courses.text.split("Released</th><th colspan='2'>Download</th></tr>").pop();
text = text.split("<h1>AIRAC <small>News</small></h1>")[0] text = text.split("<h1>AIRAC <small>News</small></h1>")[0]
console.log(text); //console.log(text);
let rows = ""; let rows = "";
// As an idea
// textArray = text.split("\n");
// let liste = "";
// let firstElement = "<td>";
// let lastElement = "</td>";
// textArray.forEach(element => {
// if (element.includes(firstElement)) {
// liste += element.substring(
// element.indexOf(firstElement) + firstElement.length,
// element.indexOf(lastElement, element.indexOf(firstElement))) +
// "\n";
// }
// });
// let outArray2 = liste.split("\n");
// outArray2.pop();
// console.log(outArray2);
for (var i = 0; i < text.length; i++) { for (var i = 0; i < text.length; i++) {
if (text[i] + text[i + 1] + text[i + 2] + text[i + 3] === "<td>") { if (text[i] + text[i + 1] + text[i + 2] + text[i + 3] === "<td>") {
let i2 = i + 4; let i2 = i + 4;
@ -104,7 +134,7 @@ const getFiles = async() => {
rows += "\n"; rows += "\n";
} }
} }
// console.log(rows); // For debugging only //console.log(rows); // For debugging only
// All Rows in Table // All Rows in Table
const listeArray = rows.split("\n"); const listeArray = rows.split("\n");
@ -124,4 +154,18 @@ const getFiles = async() => {
option.text = item; option.text = item;
dropDownFiles.add(option); dropDownFiles.add(option);
} }
let firstElement = "href=";
let lastElement = "class=";
let hrefLinksList = "";
for (var i = 4; i < listeArray.length; i = i + 5) {
hrefLinksList += listeArray[i].substring(
listeArray[i].indexOf(firstElement) + firstElement.length + 1,
listeArray[i].indexOf(lastElement) - 2) + "\n";
}
const hrefLinksArray = hrefLinksList.split("\n");
hrefLinksArray.pop();
console.log(hrefLinksArray);
return hrefLinksArray;
} }

View File

@ -1828,6 +1828,11 @@
"agent-base" "6" "agent-base" "6"
"debug" "4" "debug" "4"
"http@^0.0.1-security":
"integrity" "sha512-RnDvP10Ty9FxqOtPZuxtebw1j4L/WiqNMDtuc1YMH1XQm5TgDRaR1G9u8upL6KD1bXHSp9eSXo/ED+8Q7FAr+g=="
"resolved" "https://registry.npmjs.org/http/-/http-0.0.1-security.tgz"
"version" "0.0.1-security"
"http2-wrapper@^1.0.0-beta.5.2": "http2-wrapper@^1.0.0-beta.5.2":
"integrity" "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==" "integrity" "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg=="
"resolved" "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz" "resolved" "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz"