-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
133 lines (115 loc) · 5.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//Using CJS because pkg still doesn't support ESM... isn't javascript development so fun?
const axios = require('axios');
const cheerio = require('cheerio');
const inquirer = require('inquirer');
const ora = require('ora');
var file_id;
const regex = /(?<=(\.(?:7z)|\.(?:zip)|\.(?:rar)))\(.*\)folder/; //Removes folder and mod name after filename.
async function checkFile(game, mod, i, spinner) {
file_id = await axios.get('https://www.nexusmods.com/'+game+'/mods/'+mod+'?tab=files&file_id='+i).catch(err => console.error('Axios error: ' +err));
let $ = cheerio.load(file_id.data);
if($('div.header').text() != '') {
spinner.succeed($('div.header').text().replace(regex, '') + ' | This file exists! id: '+i)
spinner.start('Checking files...');
return i;
}
else {
//console.log('file ID ' + i + ' does not exist!');
if(i % 10 === 0) { //Update the user every 10 files to show progress is being made.
spinner.start('Checking files (Reached file id ' + i + ')...');
}
return null;
}
}
async function exitPrompt() {
return await inquirer.prompt([{
name: 'exit',
type: 'confirm',
message: 'The process will exit after this prompt.'
}]);
}
async function main() {
try {
console.log('Welcome to Nexus File Finder!\nThis program will do a brute force search for hidden files in Nexus Mods.\nPlease ensure you\'ve read the readme on the GitHub page. (https://github.com/MrFastZombie/NexusFileFinder)');
let game = await inquirer.prompt([{
name: 'game',
type: 'list',
message: 'Select the game identifer (select \'other\' if not listed)',
choices: ['skyrimspecialedition', 'skyrim', 'oblivion', 'fallout4', 'fallout3', 'newvegas', 'morrowind', 'mountandblade2bannerlord', 'cyberpunk2077', 'witcher3', 'starfield', 'other'],
default: 'skyrimspecialedition' //skyrim modders are the spiciest imo
}])
if(game.game === 'other') {
game = await inquirer.prompt([{
name: 'game',
type: 'input',
message: 'Enter the game identifer'
}]);
}
//Input validation for game ID
const check = await axios.get('https://www.nexusmods.com/'+ game.game).catch(err => console.error('Axios error: ' +err));
if(check === undefined) {
console.log('Game does not exist!');
await exitPrompt();
process.exit(0);
}
const modID = await inquirer.prompt([{
name: 'modID',
type: 'number',
message: 'Enter the mod ID'
}]);
const startingID = await inquirer.prompt([{
name: 'startingID',
type: 'number',
message: 'Enter the starting ID'
}])
const checkAmount = await inquirer.prompt([{
name: 'checkAmount',
type: 'number',
message: 'Enter the amount of files to check',
}])
//Input validation for mod ID & starting ID & check amount
if(isNaN(modID.modID) || isNaN(startingID.startingID) || isNaN(checkAmount.checkAmount)) {
console.log('invalid input!');
await exitPrompt();
process.exit(0);
}
const direction = await inquirer.prompt([{
name: 'direction',
type: 'list',
message: 'Which direction should files be checked?',
choices: ['up', 'down'],
default: 'down'
}])
//Input validation for direction
if(direction.direction == 'down') {
if(startingID.startingID - checkAmount.checkAmount < 0) {
console.log('Amount of files to check is too high for downwards search!');
await exitPrompt();
process.exit(0);
}
}
let ids = [];
const spinner = ora('Checking files...').start();
if(direction.direction === 'up') {
for(let i = startingID.startingID; i <= startingID.startingID+checkAmount.checkAmount; i++) {
let checkedFile = await checkFile(game.game, modID.modID, i, spinner);
if(checkedFile != null) {
ids.push(checkedFile);
}
} //end of for
} else if(direction.direction === 'down') {
for(let i = startingID.startingID; i >= startingID.startingID-checkAmount.checkAmount; i--) {
let checkedFile = await checkFile(game.game, modID.modID, i, spinner);
if(checkedFile != null) {
ids.push(checkedFile);
}
} //end of for
} //end of if
spinner.info('Found the following file IDs: ' + ids);
spinner.succeed('Search complete!');
await exitPrompt();
} catch (error) {
console.error(error);
}
}
main();