4
0
mirror of https://github.com/AltarikMC/Launcher synced 2024-11-25 06:49:51 +01:00

removed axios in favor to node-fetch

This commit is contained in:
Quentin Legot 2022-03-30 17:50:40 +02:00
parent cb37aa7eee
commit 0a32249782
6 changed files with 35 additions and 65 deletions

42
package-lock.json generated
View File

@ -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",

View File

@ -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": {

View File

@ -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

View File

@ -1,5 +1,3 @@
// const {default: iziToast } = require('izitoast')
app = vue.createApp({
data() {
return {

View File

@ -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()

View File

@ -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)