Skip to content

Commit

Permalink
added /downloadTotals so i can see the downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
NSPC911 committed Oct 14, 2024
1 parent 0ca072b commit eb4e226
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ certificate.crt
private.key
node_modules
makePacks
downloadTotals.json
downloadTotalscrafting.json
downloadTotalsresource.json
downloadTotalsbehaviour.json
Expand Down
92 changes: 51 additions & 41 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,25 @@ try {
httpsApp.use(cors());
httpsApp.use(bodyParser.json());

httpsApp.post('/exportResourcePack', (req, res) => {
makePackRequest(req, res, 'resource')
});
httpsApp.post('/exportBehaviourPack', (req, res) => {
makePackRequest(req, res, 'behaviour')
});
httpsApp.post('/exportCraftingTweak', (req, res) => {
makePackRequest(req, res, 'crafting')
});
httpsApp.get('/checkOnline', (req, res) => { res.status(200).send('Online') })
httpsApp.get('*', (req, res) => {
res.redirect(funnyurl);
console.log("Someone accesssed the IP. Rickrolled them instead.")
});
httpsApp.post('', (req, res) => {
res.redirect(funnyurl);
console.log("Rick Roll attempt, but POST request meant they know what they are doing.")
httpsApp.post('/exportResourcePack', (req, res) => {makePackRequest(req, res, 'resource')});
httpsApp.post('/exportBehaviourPack', (req, res) => {makePackRequest(req, res, 'behaviour')});
httpsApp.post('/exportCraftingTweak', (req, res) => {makePackRequest(req, res, 'crafting')});
httpsApp.get('/downloadTotals', (req, res) => {
const type = req.query.type;
if (!type) {
res.redirect(funnyurl);
} else {
if (fs.existsSync(`${cdir('base')}/downloadTotals${type}.json`)) {
res.sendFile(`${cdir('base')}/downloadTotals${type}.json`);
} else {
res.redirect(funnyurl);
}
}
});
httpsApp.post('/update', (req, res) => {
const key = req.query.key;
if (!key) {
return res.status(400).send('Missing key parameter.');
res.redirect(funnyurl);
}
if (!fs.existsSync(secretStuffPath)) {
const newkey = uuidv4();
Expand All @@ -92,10 +89,18 @@ try {
return res.status(200).send('Pulled from git.');
} else {
console.log("Someone tried to bruteforce the key.");
console.log(storedkey, secretStuffPath);
return res.status(401).send("Invalid key. Don't try to bruteforce it.");
res.redirect(funnyurl);
}
});
httpsApp.get('/checkOnline', (req, res) => { res.status(200).send('Online') })
httpsApp.get('*', (req, res) => {
res.redirect(funnyurl);
console.log("Someone accesssed the IP. Rickrolled them instead.")
});
httpsApp.post('*', (req, res) => {
res.redirect(funnyurl);
console.log("Rick Roll attempt.")
});
}
catch (e) {
console.log(`error with https\n ${e}`);
Expand All @@ -110,7 +115,8 @@ let currentdir = process.cwd();
function cdir(type) {
if (type == 'resource') return currentdir + '/resource-packs';
else if (type == 'behaviour') return currentdir + '/behaviour-packs';
else if (type == 'crafting') return currentdir + '/crafting-tweaks'
else if (type == 'crafting') return currentdir + '/crafting-tweaks';
else if (type == 'base') return currentdir;
else return currentdir + '/makePacks'
}

Expand Down Expand Up @@ -295,34 +301,38 @@ httpApp.listen(httpPort, () => {
console.log(`Http server is running at http://localhost:${httpPort}`);
});

httpApp.post('/exportResourcePack', (req, res) => {
makePackRequest(req, res, 'resource')
httpApp.post('/exportResourcePack', (req, res) => {makePackRequest(req, res, 'resource')});

});
httpApp.post('/exportBehaviourPack', (req, res) => {
makePackRequest(req, res, 'behaviour')
httpApp.post('/exportBehaviourPack', (req, res) => {makePackRequest(req, res, 'behaviour')});

});
httpApp.post('/exportCraftingTweak', (req, res) => {
makePackRequest(req, res, 'crafting')
});
httpApp.post('/exportCraftingTweak', (req, res) => {makePackRequest(req, res, 'crafting')});

httpApp.get('/checkOnline', (req, res) => { res.status(200).send('Online') })
httpApp.get('*', (req, res) => {
res.redirect(funnyurl);
console.log("Someone accesssed the IP. Rickrolled them instead.")
});

httpApp.post('', (req, res) => {
res.redirect(funnyurl);
console.log("Rick Roll attempt, but POST request meant they know what they are doing.")
httpApp.get('/downloadTotals', (req, res) => {
const type = req.query.type;
if (!type) {
res.send("You need a specified query. The only query available is `type`.");
} else {
if (fs.existsSync(`${cdir('base')}/downloadTotals${type}.json`)) {
res.sendFile(`${cdir('base')}/downloadTotals${type}.json`);
} else {
res.send(`There is no such file called downloadTotals${type}.json at the root directory`);
}
}
});

httpApp.post('/update', (req, res) => {
res.send("Lazy ass, just do it yourself");
console.log("Hey lazy ass, over here, just press `Ctrl + C` then `git pull`, why the extra steps?")
});

httpApp.get('*', (req, res) => {
res.send("There's nothing here, you should probably enter into the submodules to find the website.")
});

httpApp.post('*', (req, res) => {
res.send("There's nothing here, you should probably enter into the submodules to find the website.")
});

function makePackRequest(req, res, type) {
const packName = req.headers.packname
const selectedPacks = req.body;
Expand Down Expand Up @@ -354,5 +364,5 @@ function makePackRequest(req, res, type) {
const sortedDownloadTotals = Object.entries(downloadTotals);
sortedDownloadTotals.sort((a, b) => b[1] - a[1]);
const sortedData = Object.fromEntries(sortedDownloadTotals);
dumpJson(`downloadTotals${type}.json`, sortedData)
}
dumpJson(`downloadTotals${type}.json`, sortedData);
}

0 comments on commit eb4e226

Please sign in to comment.