Skip to content

Commit

Permalink
Make downloading js-module configurable via config
Browse files Browse the repository at this point in the history
commit b7e0c27
Author: xLuxy <[email protected]>
Date:   Wed Oct 25 14:07:14 2023 +0200

    Bump version to 2.6.0

commit 50c6ea3
Author: xLuxy <[email protected]>
Date:   Wed Oct 25 14:06:48 2023 +0200

    Update README.md

commit 50d5af3
Author: xLuxy <[email protected]>
Date:   Wed Oct 25 14:03:05 2023 +0200

    Make downloading js-module optional via config
  • Loading branch information
xLuxy committed Oct 25, 2023
1 parent 8c45af7 commit 8b8192a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ Create a `.altvpkgrc.json` file in your root directory and add the following JSO

**Note:** The `loadVoiceServer` configuration allows you to include [external voice server](https://docs.altv.mp/articles/external_voice_server.html) when downloading binaries.

Below you'll find all available options for the `.altvpkgrc.json` file with their default values:

```
{
"loadBytecodeModule": true,
"loadCSharpModule": true,
"loadJSV2Module": true,
"loadVoiceServer": true
"loadJSModule": true,
"loadBytecodeModule": false,
"loadCSharpModule": false,
"loadJSV2Module": false,
"loadVoiceServer": false
}
```
50 changes: 32 additions & 18 deletions bin/altv-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const rootPath = process.cwd();
let platform = process.platform == 'win32' ? 'x64_win32' : 'x64_linux';
let branch = null;

const { loadBytecodeModule, loadCSharpModule, loadJSV2Module, loadVoiceServer } = loadRuntimeConfig();
const { loadJSModule, loadBytecodeModule, loadCSharpModule, loadJSV2Module, loadVoiceServer } = loadRuntimeConfig();

function authorizeDiscord() {
console.log(chalk.greenBright('===== Authorizing via Discord ====='));
Expand Down Expand Up @@ -128,8 +128,6 @@ async function start() {

const linuxFiles = {
...sharedFiles,
'modules/libjs-module.so': `https://${CDN_ADDRESS}/js-module/${branch}/${platform}/modules/js-module/libjs-module.so`,
'libnode.so.108': `https://${CDN_ADDRESS}/js-module/${branch}/${platform}/modules/js-module/libnode.so.108`,
'start.sh': `https://${CDN_ADDRESS}/others/start.sh`,
};

Expand All @@ -138,11 +136,7 @@ async function start() {
linuxFiles[file] = `https://${SERVER_CDN_ADDRESS}/server/${serverBranch}/x64_linux/${file}`;
}

const windowsFiles = {
...sharedFiles,
'modules/js-module.dll': `https://${CDN_ADDRESS}/js-module/${branch}/${platform}/modules/js-module/js-module.dll`,
'libnode.dll': `https://${CDN_ADDRESS}/js-module/${branch}/${platform}/modules/js-module/libnode.dll`,
};
const windowsFiles = { ...sharedFiles };

res = await axios.get(`https://${SERVER_CDN_ADDRESS}/server/${serverBranch}/x64_win32/update.json`, { responseType: 'json', headers });
for ([file, hash] of Object.entries(res.data.hashList)) {
Expand All @@ -155,16 +149,29 @@ async function start() {

const linuxUpdates = [
...sharedUpdates,
`https://${SERVER_CDN_ADDRESS}/server/${serverBranch}/x64_linux/update.json`,
`https://${CDN_ADDRESS}/js-module/${branch}/x64_linux/update.json`,
`https://${SERVER_CDN_ADDRESS}/server/${serverBranch}/x64_linux/update.json`
];

const windowsUpdates = [
...sharedUpdates,
`https://${SERVER_CDN_ADDRESS}/server/${serverBranch}/x64_win32/update.json`,
`https://${CDN_ADDRESS}/js-module/${branch}/x64_win32/update.json`,
`https://${SERVER_CDN_ADDRESS}/server/${serverBranch}/x64_win32/update.json`
];

if (loadJSModule) {
res = await axios.get(`https://${CDN_ADDRESS}/js-module/${branch}/x64_linux/update.json`, { responseType: 'json', headers });
for ([file, hash] of Object.entries(res.data.hashList)) {
linuxFiles[file] = `https://${CDN_ADDRESS}/js-module/${branch}/x64_linux/${file}`;
}

res = await axios.get(`https://${CDN_ADDRESS}/js-module/${branch}/x64_win32/update.json`, { responseType: 'json', headers });
for ([file, hash] of Object.entries(res.data.hashList)) {
windowsFiles[file] = `https://${CDN_ADDRESS}/js-module/${branch}/x64_win32/${file}`;
}

linuxUpdates.push(`https://${CDN_ADDRESS}/js-module/${branch}/x64_linux/update.json`)
windowsUpdates.push(`https://${CDN_ADDRESS}/js-module/${branch}/x64_win32/update.json`);
}

if (loadBytecodeModule) {
res = await axios.get(`https://${CDN_ADDRESS}/js-bytecode-module/${branch}/x64_linux/update.json`, { responseType: 'json', headers });
for ([file, hash] of Object.entries(res.data.hashList)) {
Expand Down Expand Up @@ -247,23 +254,25 @@ async function start() {

let promises = [];
let anyHashRejected = false;

console.log(filesToUse[file])
for (const url of filesUpdate) {
const promise = new Promise((resolve, reject) => {
axios.get(url, { responseType: 'json', headers }).then(({ data: {
hashList
} }) => {
for (let [file, hash] of Object.entries(hashList)) {
file = correctPathIfNecessary(file);
const correctedFileName = correctPathIfNecessary(file);

if (getLocalFileHash(file) === hash) {
console.log(chalk.cyanBright('✓'), chalk.whiteBright(file));
if (getLocalFileHash(correctedFileName) === hash) {
console.log(chalk.cyanBright('✓'), chalk.whiteBright(correctedFileName));
continue;
}

console.log(chalk.redBright('x'), chalk.whiteBright(file));
console.log(chalk.redBright('x'), chalk.whiteBright(correctedFileName));

if (anyHashRejected) return;
filesToDownload[file] = filesToUse[file];
filesToDownload[correctedFileName] = filesToUse[file];
}

resolve();
Expand Down Expand Up @@ -344,6 +353,8 @@ function correctPathIfNecessary(file) {
}

function loadRuntimeConfig() {
let loadJSModule = true;

let loadBytecodeModule = false;
let loadCSharpModule = false;
let loadJSV2Module = false;
Expand All @@ -353,6 +364,9 @@ function loadRuntimeConfig() {
const data = fs.readFileSync(`./${RC_FILE_NAME}`, { encoding: 'utf8' });
const parsedData = JSON.parse(data);

if (typeof parsedData.loadJSModule !== 'undefined')
loadJSModule = !!parsedData.loadJSModule;

loadBytecodeModule = !!parsedData.loadBytecodeModule;
loadCSharpModule = !!parsedData.loadCSharpModule;
loadJSV2Module = !!parsedData.loadJSV2Module;
Expand All @@ -361,7 +375,7 @@ function loadRuntimeConfig() {
console.log(chalk.gray(`Configuration file '${RC_FILE_NAME}' could not be read. Continuing without...`));
}

return { loadBytecodeModule, loadCSharpModule, loadJSV2Module, loadVoiceServer };
return { loadJSModule, loadBytecodeModule, loadCSharpModule, loadJSV2Module, loadVoiceServer };
}

start();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altv-pkg",
"version": "2.5.0",
"version": "2.6.0",
"description": "Install alt:V Binaries Quickly",
"main": "bin/index.js",
"author": "stuyk",
Expand Down

0 comments on commit 8b8192a

Please sign in to comment.