From 0a32249782d1d5089d16a73faee1e4d195677512 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 30 Mar 2022 17:50:40 +0200 Subject: [PATCH] removed axios in favor to node-fetch --- package-lock.json | 42 +------------------------------- package.json | 2 +- src/client/assets/js/index.js | 7 +++--- src/client/assets/js/login.js | 2 -- src/server/main.js | 1 + src/server/minecraft.js | 46 ++++++++++++++++++++++------------- 6 files changed, 35 insertions(+), 65 deletions(-) diff --git a/package-lock.json b/package-lock.json index f009fed..1ca762e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "win32" ], "dependencies": { - "axios": "^0.26.0", "electron-is-dev": "^2.0.0", "electron-log": "^4.4.6", "electron-squirrel-startup": "^1.0.0", @@ -21,6 +20,7 @@ "izitoast": "^1.4.0", "minecraft-launcher-core": "^3.16.12", "msmc": "^3.0.6", + "node-fetch": "^2.6.7", "vue": "^3.2.31" }, "devDependencies": { @@ -1337,14 +1337,6 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, - "node_modules/axios": { - "version": "0.26.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", - "integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==", - "dependencies": { - "follow-redirects": "^1.14.8" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -3137,25 +3129,6 @@ "node": ">=6 <7 || >=8" } }, - "node_modules/follow-redirects": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -7981,14 +7954,6 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, - "axios": { - "version": "0.26.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", - "integrity": "sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og==", - "requires": { - "follow-redirects": "^1.14.8" - } - }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -9368,11 +9333,6 @@ } } }, - "follow-redirects": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" - }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", diff --git a/package.json b/package.json index f7f1414..fcceaf8 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "electron": "^18.0.0" }, "dependencies": { - "axios": "^0.26.0", "electron-is-dev": "^2.0.0", "electron-log": "^4.4.6", "electron-squirrel-startup": "^1.0.0", @@ -41,6 +40,7 @@ "izitoast": "^1.4.0", "minecraft-launcher-core": "^3.16.12", "msmc": "^3.0.6", + "node-fetch": "^2.6.7", "vue": "^3.2.31" }, "config": { diff --git a/src/client/assets/js/index.js b/src/client/assets/js/index.js index 9aca749..803f86f 100644 --- a/src/client/assets/js/index.js +++ b/src/client/assets/js/index.js @@ -35,6 +35,9 @@ app = vue.createApp({ position: 'topRight', resetOnHover: true, }) + setInterval(() => { + ipcRenderer.send("pageReady") + }, 500) }, methods: { invalidateData () { @@ -150,10 +153,6 @@ ipcRenderer.on('launch', (_e, _args) => { root.loadingMessageHidden = true }) -setInterval(() => { - ipcRenderer.send("pageReady") -}, 500) - ipcRenderer.on("modsInformations", (_e, args) => { if(args === null) { root.modsInformationsLoaded = false diff --git a/src/client/assets/js/login.js b/src/client/assets/js/login.js index 9c185b8..8715678 100644 --- a/src/client/assets/js/login.js +++ b/src/client/assets/js/login.js @@ -1,5 +1,3 @@ -// const {default: iziToast } = require('izitoast') - app = vue.createApp({ data() { return { diff --git a/src/server/main.js b/src/server/main.js index 5c73576..15ddea5 100644 --- a/src/server/main.js +++ b/src/server/main.js @@ -1,6 +1,7 @@ const { app, BrowserWindow, Menu, ipcMain, autoUpdater, dialog } = require('electron') const logger = require('electron-log') const { join } = require('path') + if (require('electron-squirrel-startup')) { require("./install.js").handleSquirrelEvent(app) app.quit() diff --git a/src/server/minecraft.js b/src/server/minecraft.js index b541410..5f957e1 100644 --- a/src/server/minecraft.js +++ b/src/server/minecraft.js @@ -1,7 +1,7 @@ const isDev = require('electron-is-dev') const { Client, Authenticator } = require('minecraft-launcher-core') -const axios = require('axios').default -const hasha = require('hasha'); +const fetch = require('node-fetch').default +const hasha = require('hasha') const fs = require('fs') const { join } = require('path') const constants = require("constants") @@ -128,17 +128,25 @@ class Minecraft { } getModsInformations(event) { - axios.get("https://altarik.fr/launcher.json").then(o => { - if(o.status === 200 && o.headers["content-type"] === "application/json") { - let folder = join(process.env.LOCALAPPDATA, "altarik-launcher", "data") - if(!fs.existsSync(folder)) - fs.mkdirSync(folder, {recursive: true}) - let file = join(folder, "launcher.json") - if(fs.existsSync(file)) - fs.rmSync(file) - fs.writeFileSync(file, JSON.stringify(o.data)) - event.sender.send('modsInformations', this.extractModsInformations(o.data)) + fetch("https://altarik.fr/launcher.json").then(response => { + if(response.ok) { + response.json().then(data => { + let folder = join(process.env.LOCALAPPDATA, "altarik-launcher", "data") + if(!fs.existsSync(folder)) + fs.mkdirSync(folder, {recursive: true}) + let file = join(folder, "launcher.json") + if(fs.existsSync(file)) + fs.rmSync(file) + fs.writeFileSync(file, JSON.stringify(data)) + event.sender.send('modsInformations', this.extractModsInformations(data)) + }).catch(err => { + event.sender.send('modsInformations', this.extractModsFromFileSystem()) + logger.warn(err) + logger.warn("An error occured while trying to connect to server") + }) } else { + logger.warn("Unable to connect to server") + logger.warn(err) event.sender.send('modsInformations', this.extractModsFromFileSystem()) } }).catch(err => { @@ -222,17 +230,21 @@ class Minecraft { downloadMods(link, path) { return new Promise((resolve, reject) => { - axios.get(link, {responseType: "stream"}).then(res => { - if(res.status === 200) { + fetch(link).then(response => { + if(response.ok) { if(fs.existsSync(path)) fs.rmSync(path) - res.data.pipe(fs.createWriteStream(path)); - res.data.on("end", () => { + const dest = fs.createWriteStream(path) + response.body.pipe(dest) + response.body.on("end", () => { logger.log("download completed"); resolve("download completed") }) + dest.on("error", () => { + reject("An error appenned when using stream") + }); } else { - reject(res.status) + reject(response.status) } }).catch(err => { reject(err)