diff --git a/modules/api/api.js b/modules/api/api.js index 027a9a9..c4b22bf 100644 --- a/modules/api/api.js +++ b/modules/api/api.js @@ -40,6 +40,7 @@ const dataEditsLog = 'stats/dataEdits' const dailyDataCountFile = 'stats/dailyDataCount' const usersDbBackupPath = 'data/dbs/backup' const quickVoteResultsDir = 'stats/qvote' +const quickVotes = 'stats/qvote/votes.json' // other constants const maxVeteranPwGetCount = 10 @@ -135,13 +136,30 @@ function GetApp () { const val = req.query.val if (!key || !val) { - res.json({ + res.render('votethank', { results: 'error', msg: 'no key or val query param!' }) return } + let votes = {} + if (utils.FileExists(quickVotes)) { + votes = utils.ReadJSON(quickVotes) + } else { + res.render('votethank', { + result: 'no such pool' + }) + return + } + + if (!votes.voteNames.includes(key)) { + res.render('votethank', { + result: 'no such pool' + }) + return + } + const voteFile = quickVoteResultsDir + '/' + key + '.json' const user = req.session.user @@ -165,14 +183,14 @@ function GetApp () { voteData.users.push(user.id) logger.Log(`Vote from #${user.id}: ${key}: ${val}`, logger.GetColor('blue')) - res.json({ + res.render('votethank', { result: 'success', msg: 'vote added' }) } else { logger.Log(`#${user.id} already voted for: ${key}: ${val}`, logger.GetColor('blue')) - res.json({ - result: 'success', + res.render('votethank', { + result: 'already voted', msg: 'already voted' }) } diff --git a/modules/api/views/votethank.ejs b/modules/api/views/votethank.ejs new file mode 100755 index 0000000..bf1d266 --- /dev/null +++ b/modules/api/views/votethank.ejs @@ -0,0 +1,31 @@ + + + + Shit uploader + + + +
+ <% + if (result == 'success') { + %> ty a szavazásért c: <% + } else if (result == 'no such pool') { + %> Ilyen nevű szavazás nincs :c <% + } else if (result == 'already voted') { + %> Már szavaztál, de azért ty c: <% + } else if (result == 'error') { + %> Helytelen url paraméterek :c <% + } else { + %> bit of a fuckup here <% + } + %> + ty c: +
+ +