rename files to be more consistent and handle multiple versions

This commit is contained in:
oatmealine 2020-01-27 19:50:19 +03:00
parent fce8db2c3e
commit 1f3b624608
No known key found for this signature in database
GPG Key ID: C4CB49CFAD721145
7 changed files with 63 additions and 33 deletions

View File

@ -1,8 +1,10 @@
import * as xor from './xor';
import * as hashes from './hash';
const handleRequestsAt = ['downloadGJLevel22', 'downloadGJLevel21', 'downloadGJLevel20', 'downloadGJLevel19', 'downloadGJLevel'];
module.exports = (app) : void => {
app.post('/' + app.get('config').addtopath + 'database/downloadGJLevel22.php', async (req, res) => {
let downloadLevel = async (req, res) => {
let level = await app.get('db').collection('levels').findOneAndUpdate({
id: Number(req.body.levelID)
}, {
@ -34,5 +36,8 @@ module.exports = (app) : void => {
response += `${hashes.hashSolo2(extraData)}#${extraData}`;
res.status(200).send(response);
});
};
for (let i in handleRequestsAt)
app.post('/' + app.get('config').addtopath + 'database/' + handleRequestsAt[i] + '.php', downloadLevel);
};

View File

@ -1,5 +1,9 @@
export{}; // fuck you ts, i have to do this to prevent "cannot redeclare block scoped variable"
const handleRequestsAt = ['getGJComments21', 'getGJComments20', 'getGJComments19', 'getDJCommentHistory'];
module.exports = (app) : void => {
app.post('/' + app.get('config').addtopath + 'database/getGJComments21.php', async (req, res) => {
let getComments = async (req, res) => {
let comments = await app.get('db').collection('comments').find({
levelID: Number(req.body.levelID)
}).toArray();
@ -46,5 +50,8 @@ module.exports = (app) : void => {
.join('|');
res.status(200).send(`${commentString}#${count}:${offset}:10`);
});
};
for (let i in handleRequestsAt)
app.post('/' + app.get('config').addtopath + 'database/' + handleRequestsAt[i] + '.php', getComments);
};

View File

@ -1,9 +1,10 @@
import * as hash from './hash';
const levelsPerPage = 10; // should be kept at 10, increasing/decreasing may lead to unforseeable consequences
const handleRequestsAt = ['getGJLevels21', 'getGJLevels20', 'getGJLevels19', 'getGJLevels'];
module.exports = (app) : void => {
app.post('/' + app.get('config').addtopath + 'database/getGJLevels21.php', async (req, res) => {
let getLevels = async (req, res) => {
let levelsString = '';
let searchQuery: any = {}; // fuck you typescript, i have to use any or else it screams
@ -127,5 +128,8 @@ module.exports = (app) : void => {
hash.hashLevels(foundLevels);
res.status(200).send(levelsString);
});
};
for (let i in handleRequestsAt)
app.post('/' + app.get('config').addtopath + 'database/' + handleRequestsAt[i] + '.php', getLevels);
};

View File

@ -25,11 +25,11 @@ dbClient.connect((err) => {
res.send(`${config.name} homepage - unfinished`);
});
require('./getGJLevels21')(app);
require('./uploadGJLevel21')(app);
require('./downloadGJLevel22')(app);
require('./getGJComments21')(app);
require('./updateGJUserScore22')(app);
require('./getGJLevels')(app);
require('./uploadGJLevel')(app);
require('./downloadGJLevel')(app);
require('./getGJComments')(app);
require('./updateGJUserScore')(app);
app.get('*', (req, res) => {
console.log('got 404 for ' + req.url);

12
src/updateGJUserScore.ts Normal file
View File

@ -0,0 +1,12 @@
export{}; // fuck you ts, i have to do this to prevent "cannot redeclare block scoped variable"
const handleRequestsAt = ['updateGJUserScore22', 'updateGJUserScore21', 'updateGJUserScore20', 'updateGJUserScore19', 'updateGJUserScore'];
module.exports = (app): void => {
let updateUserScore = async (req, res) => {
res.status(200).send('0'); // temporary
};
for (let i in handleRequestsAt)
app.post('/' + app.get('config').addtopath + 'database/' + handleRequestsAt[i] + '.php', updateUserScore);
};

View File

@ -1,5 +0,0 @@
module.exports = (app): void => {
app.post('/' + app.get('config').addtopath + 'database/updateGJUserScore22.php', async (req, res) => {
res.status(200).send('0'); // temporary
});
};

View File

@ -1,5 +1,9 @@
export{}; // fuck you ts, i have to do this to prevent "cannot redeclare block scoped variable"
const handleRequestsAt = ['uploadGJLevel21', 'uploadGJLevel20', 'uploadGJLevel19', 'uploadGJLevel'];
module.exports = (app): void => {
app.post('/' + app.get('config').addtopath + 'database/uploadGJLevel21.php', async (req, res) => {
let uploadLevel = async (req, res) => {
let levels = await app.get('db').collection('levels')
.find({})
.toArray();
@ -61,5 +65,8 @@ module.exports = (app): void => {
});
res.status(200).send(String(levelID));
});
};
for (let i in handleRequestsAt)
app.post('/' + app.get('config').addtopath + 'database/' + handleRequestsAt[i] + '.php', uploadLevel);
};