mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-12-23 02:13:46 +03:00
fix: 1/2 axios migration
This commit is contained in:
parent
f760263f7f
commit
6cce71b998
1 changed files with 25 additions and 13 deletions
|
@ -4,15 +4,21 @@ const request = require("request");
|
|||
const checksum = require("checksum");
|
||||
const Zip = require("adm-zip");
|
||||
const child = require("child_process");
|
||||
const axios = require("axios");
|
||||
const { Agent } = require("https");
|
||||
|
||||
let counter = 0;
|
||||
|
||||
class Handler {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.options = client.options;
|
||||
this.baseRequest = request.defaults({
|
||||
pool: { maxSockets: this.options.overrides.maxSockets || 2 },
|
||||
|
||||
this.baseRequest = axios.create({
|
||||
timeout: this.options.timeout || 10000,
|
||||
httpsAgent: new Agent({
|
||||
maxSockets: 8,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -40,10 +46,14 @@ class Handler {
|
|||
}
|
||||
|
||||
downloadAsync(url, directory, name, retry, type) {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise(async (resolve) => {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
|
||||
const _request = this.baseRequest(url);
|
||||
const _request = (
|
||||
await this.baseRequest.get(url, {
|
||||
responseType: "stream",
|
||||
})
|
||||
).data;
|
||||
|
||||
let receivedBytes = 0;
|
||||
let totalBytes = 0;
|
||||
|
@ -636,17 +646,19 @@ class Handler {
|
|||
}/${name}`;
|
||||
// Checking if the file still exists on Forge's server, if not, replace it with the fallback.
|
||||
// Not checking for sucess, only if it 404s.
|
||||
this.baseRequest(downloadLink, (error, response, body) => {
|
||||
if (error) {
|
||||
this.client.emit(
|
||||
"debug",
|
||||
`[PiMi]: Failed checking request for ${downloadLink}`
|
||||
);
|
||||
} else {
|
||||
if (response.statusCode === 404)
|
||||
try {
|
||||
await this.baseRequest.get(downloadLink);
|
||||
} catch (error) {
|
||||
if (error.response) {
|
||||
if (error.response.status === 404)
|
||||
library.url = this.options.overrides.url.fallbackMaven;
|
||||
else
|
||||
this.client.emit(
|
||||
"debug",
|
||||
`[PiMi]: Failed checking request for ${downloadLink}`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue