Skip to content

Commit

Permalink
Check if recent player files exist before reading it & correct elide …
Browse files Browse the repository at this point in the history
…syntax to fetch game ID in report submission (#379)

Co-authored-by: Louvenarde <louve@louve.systems>
  • Loading branch information
Rackover and Louvenarde committed Apr 7, 2022
1 parent 1ad6abc commit 8b003c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions routes/views/accounts/get/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,24 @@ exports = module.exports = function (req, res) {
});
}

fs.readFile('members/recent.json', 'utf8', function (err, data) {
try {
locals.reportable_members = JSON.parse(data);
} catch (e) {
const moment = require('moment');
console.log(moment().format("DD-MM-YYYY - HH:mm:ss") + "The list of reportable members could not be read from the disk: " + e.toString());
}
locals.reportable_members = {};
const recentMembersPath = 'members/recent.json';
if (fs.existsSync(recentMembersPath)){
fs.readFile(recentMembersPath, 'utf8', function (err, data) {
try {
locals.reportable_members = JSON.parse(data);
} catch (e) {
const moment = require('moment');
console.log(moment().format("DD-MM-YYYY - HH:mm:ss") + " - The list of reportable members could not be read from the disk: " + e.toString());
}

res.render('account/report', {flash: flash});
});
res.render('account/report', {flash: flash});
});
}
else
{
res.render('account/report', {flash: flash});
}
}
)
};
2 changes: 1 addition & 1 deletion routes/views/accounts/post/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ exports = module.exports = async function (req, res) {

// Checking the game exists
if (isGameReport){
const gameFetchRoute = process.env.API_URL+'/data/game?filter=id=='+req.body.game_id+'&fields[game]=id';
const gameFetchRoute = process.env.API_URL+'/data/game?filter=id=='+req.body.game_id+'&fields[game]='; /* empty field here to fetch nothing but ID */
try {
const gameFetch = await promiseRequest(gameFetchRoute);
const gameData = JSON.parse(gameFetch);
Expand Down

0 comments on commit 8b003c3

Please sign in to comment.