Commit 799203d6 authored by Matthieu - Greep's avatar Matthieu - Greep

Add tmio API player check

parent 09f1927e
Pipeline #458 passed with stage
in 1 minute and 22 seconds
This diff is collapsed.
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"express": "^4.17.1", "express": "^4.17.1",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"mysql": "^2.18.1" "mysql": "^2.18.1",
"trackmania.io": "^2.4.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.32.0", "eslint": "^7.32.0",
......
const path = require('path'), const path = require('path'),
scriptName = path.basename(__filename).replace(/\.js$/i,''); scriptName = path.basename(__filename).replace(/\.js$/i,''),
tmio = require('trackmania.io'),
tmioPlayer = new tmio.Players();
/** /**
* @param {import('express').Express} app * @param {import('express').Express} app
...@@ -17,9 +19,15 @@ module.exports = function(app, sql, tokenCheck, errorHandler) { ...@@ -17,9 +19,15 @@ module.exports = function(app, sql, tokenCheck, errorHandler) {
if (isNaN(vote)) return errorHandler(res, 400, 'Invalid vote'); if (isNaN(vote)) return errorHandler(res, 400, 'Invalid vote');
if (vote < 0 || vote > 100) return errorHandler(res, 400, 'Vote must be between 0 and 100'); if (vote < 0 || vote > 100) return errorHandler(res, 400, 'Vote must be between 0 and 100');
//TODO: check if player exists (tmio API check) // check if player exists (tmio API check)
tmioPlayer.player(player).then((playerData)=>{
if (playerData.error) return errorHandler(res, 400, playerData.error);
});
//TODO: check if map exists (tmio API check) // check if map exists (tmio API check)
tmio.map(mapId).then((mapData)=>{
if (mapData.error) return errorHandler(res, 400, mapData.error);
});
sql.query('SELECT * FROM votes WHERE map = ? AND player = ?', [mapId,player], (err, sqlRes)=>{ sql.query('SELECT * FROM votes WHERE map = ? AND player = ?', [mapId,player], (err, sqlRes)=>{
if (err) { if (err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment