mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added quick vote for user feedback
This commit is contained in:
parent
f482c65f3c
commit
d55115f353
1 changed files with 51 additions and 0 deletions
|
@ -39,6 +39,7 @@ const passwordFile = 'data/dataEditorPasswords.json'
|
||||||
const dataEditsLog = 'stats/dataEdits'
|
const dataEditsLog = 'stats/dataEdits'
|
||||||
const dailyDataCountFile = 'stats/dailyDataCount'
|
const dailyDataCountFile = 'stats/dailyDataCount'
|
||||||
const usersDbBackupPath = 'data/dbs/backup'
|
const usersDbBackupPath = 'data/dbs/backup'
|
||||||
|
const quickVoteResultsDir = 'stats/qvote'
|
||||||
|
|
||||||
// other constants
|
// other constants
|
||||||
const maxVeteranPwGetCount = 10
|
const maxVeteranPwGetCount = 10
|
||||||
|
@ -129,6 +130,56 @@ function GetApp () {
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
app.get('/quickvote', (req, res) => {
|
||||||
|
const key = req.query.key
|
||||||
|
const val = req.query.val
|
||||||
|
|
||||||
|
if (!key || !val) {
|
||||||
|
res.json({
|
||||||
|
results: 'error',
|
||||||
|
msg: 'no key or val query param!'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const voteFile = quickVoteResultsDir + '/' + key + '.json'
|
||||||
|
const user = req.session.user
|
||||||
|
|
||||||
|
let voteData = {
|
||||||
|
votes: {},
|
||||||
|
users: []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils.FileExists(voteFile)) {
|
||||||
|
voteData = utils.ReadJSON(voteFile)
|
||||||
|
} else {
|
||||||
|
utils.CreatePath(quickVoteResultsDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!voteData.users.includes(user.id)) {
|
||||||
|
if (voteData[val]) {
|
||||||
|
voteData.votes[val]++
|
||||||
|
} else {
|
||||||
|
voteData.votes[val] = 1
|
||||||
|
}
|
||||||
|
voteData.users.push(user.id)
|
||||||
|
|
||||||
|
logger.Log(`Vote from #${user.id}: ${key}: ${val}`, logger.GetColor('blue'))
|
||||||
|
res.json({
|
||||||
|
result: 'success',
|
||||||
|
msg: 'vote added'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
logger.Log(`#${user.id} already voted for: ${key}: ${val}`, logger.GetColor('blue'))
|
||||||
|
res.json({
|
||||||
|
result: 'success',
|
||||||
|
msg: 'already voted'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.WriteFile(JSON.stringify(voteData), voteFile)
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/avaiblePWS', (req, res) => {
|
app.get('/avaiblePWS', (req, res) => {
|
||||||
logger.LogReq(req)
|
logger.LogReq(req)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue