Socket
Socket
Sign inDemoInstall

altv-pkg

Package Overview
Dependencies
8
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.4 to 2.0.5

127

bin/altv-pkg.js

@@ -6,2 +6,3 @@ #!/usr/bin/env node

const chalk = require('chalk');
const crypto = require('crypto');

@@ -14,4 +15,2 @@ const args = process.argv

for (let i = 0; i < args.length; i++) {

@@ -37,3 +36,3 @@ if (args[i] === 'release') {

console.log(chalk.green('npx altv-pkg release'));
process.exit(0)
process.exit(0);
}

@@ -46,6 +45,10 @@

const linuxFiles = {
const sharedFiles = {
'data/vehmodels.bin': `https://cdn.altv.mp/data/${branch}/data/vehmodels.bin`,
'data/vehmods.bin': `https://cdn.altv.mp/data/${branch}/data/vehmods.bin`,
'data/clothes.bin': `https://cdn.altv.mp/data/${branch}/data/clothes.bin`,
};
const linuxFiles = {
...sharedFiles,
'modules/libjs-module.so': `https://cdn.altv.mp/js-module/${branch}/${platform}/modules/js-module/libjs-module.so`,

@@ -55,8 +58,6 @@ 'libnode.so.102': `https://cdn.altv.mp/js-module/${branch}/${platform}/modules/js-module/libnode.so.102`,

'altv-server': `https://cdn.altv.mp/server/${branch}/x64_linux/altv-server`,
}
};
const windowsFiles = {
'data/vehmodels.bin': `https://cdn.altv.mp/data/${branch}/data/vehmodels.bin`,
'data/vehmods.bin': `https://cdn.altv.mp/data/${branch}/data/vehmods.bin`,
'data/clothes.bin': `https://cdn.altv.mp/data/${branch}/data/clothes.bin`,
...sharedFiles,
'modules/js-module.dll': `https://cdn.altv.mp/js-module/${branch}/${platform}/modules/js-module/js-module.dll`,

@@ -67,4 +68,22 @@ 'libnode.dll': `https://cdn.altv.mp/js-module/${branch}/${platform}/modules/js-module/libnode.dll`,

const filesToUse = platform == 'x64_win32' ? windowsFiles : linuxFiles;
const sharedUpdates = [
`https://cdn.altv.mp/data/${branch}/update.json`,
];
const linuxUpdates = [
...sharedUpdates,
`https://cdn.altv.mp/server/${branch}/x64_linux/update.json`,
`https://cdn.altv.mp/js-module/${branch}/x64_linux/update.json`,
];
const windowsUpdates = [
...sharedUpdates,
`https://cdn.altv.mp/server/${branch}/x64_win32/update.json`,
`https://cdn.altv.mp/js-module/${branch}/x64_win32/update.json`,
];
const [filesUpdate, filesToUse] = (platform == 'x64_win32')
? [windowsUpdates, windowsFiles]
: [linuxUpdates, linuxFiles];
if (!fs.existsSync(path.join(rootPath, 'data'))) {

@@ -78,13 +97,34 @@ fs.mkdirSync(path.join(rootPath, 'data'));

console.log(chalk.greenBright('===== Checking file hashes ====='));
let filesToDownload = {};
let promises = [];
console.log(chalk.greenBright('===== Download ====='));
for (const [file, url] of Object.entries(filesToUse)) {
console.log(chalk.whiteBright(`${file}`))
const promise = new Promise((resolve) => {
axios.get(url, { responseType: 'arraybuffer' }).then(response => {
fs.writeFileSync(path.join(rootPath, file), response.data);
let anyHashRejected = false;
for (const url of filesUpdate) {
const promise = new Promise((resolve, reject) => {
axios.get(url, { responseType: 'json' }).then(({ data: {
hashList
}}) => {
for (let [file, hash] of Object.entries(hashList)) {
file = correctPathIfNecessary(file);
if (getLocalFileHash(file) === hash) {
console.log(chalk.cyanBright('✓'), chalk.whiteBright(file));
continue;
}
console.log(chalk.redBright('x'), chalk.whiteBright(file));
if (anyHashRejected) return;
filesToDownload[file] = filesToUse[file];
}
resolve();
}).catch(error => {
console.error(`Failed to download ${file}: ${error}`);
resolve();
reject();
if (anyHashRejected) return;
anyHashRejected = true;
console.error(chalk.redBright(`Failed to check hash ${url}: ${error}`));
});

@@ -96,6 +136,57 @@ });

await Promise.all(promises);
try {
await Promise.all(promises);
console.log(chalk.greenBright('===== File hash check complete ====='));
}
catch {
console.log(chalk.redBright('===== File hash check corrupted -> download all ====='));
filesToDownload = filesToUse;
}
if (Object.keys(filesToDownload).length) {
promises = [];
console.log(chalk.greenBright('===== Download ====='));
for (const [file, url] of Object.entries(filesToDownload)) {
console.log(chalk.whiteBright(`${file}`));
const promise = new Promise((resolve) => {
axios.get(url, { responseType: 'arraybuffer' }).then(response => {
fs.writeFileSync(path.join(rootPath, file), response.data);
resolve();
}).catch(error => {
console.error(chalk.redBright(`Failed to download ${file}: ${error}`));
resolve();
});
});
promises.push(promise);
}
await Promise.all(promises);
}
console.log(chalk.greenBright('===== Complete ====='));
}
function getLocalFileHash(file) {
let fileBuffer;
try {
fileBuffer = fs.readFileSync(path.join(rootPath, file));
} catch {
return '_';
}
return crypto.createHash('sha1').update(fileBuffer).digest('hex');
}
// I dont't know why altv-pkg has different file paths than alt:V cdn
const pathsCorrects = {
'modules/js-module/js-module.dll': 'modules/js-module.dll',
'modules/js-module/libnode.dll': 'libnode.dll',
'modules/js-module/libjs-module.so': 'modules/libjs-module.so',
'modules/js-module/libnode.so.102': 'libnode.so.102',
};
function correctPathIfNecessary(file) {
return pathsCorrects[file] ?? file;
}
start();

4

package.json
{
"name": "altv-pkg",
"version": "2.0.4",
"version": "2.0.5",
"description": "Install alt:V Binaries Quickly",

@@ -31,2 +31,2 @@ "main": "bin/index.js",

]
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc