Merge branch 'master' of gitlab.com:MrFry/mrfrys-node-server

This commit is contained in:
MrFry 2020-05-10 21:29:08 +02:00
commit fe8503a43e
4 changed files with 26 additions and 4 deletions

View file

@ -41,6 +41,7 @@ const dailyDataCountFile = 'stats/dailyDataCount'
const usersDbBackupPath = 'data/dbs/backup'
const quickVoteResultsDir = 'stats/qvote'
const quickVotes = 'stats/qvote/votes.json'
const testUsersFile = 'data/testUsers.json'
// other constants
const maxVeteranPwGetCount = 10
@ -104,6 +105,7 @@ function GetApp () {
var data = actions.LoadJSON(dataFile)
var version = ''
var motd = ''
var testUsers = []
function LoadVersion () {
version = utils.ReadFile(versionFile)
@ -113,6 +115,13 @@ function GetApp () {
motd = utils.ReadFile(motdFile)
}
function LoadTestUsers () {
testUsers = utils.ReadJSON(testUsersFile)
if (testUsers) {
testUsers = testUsers.userIds
}
}
function Load () {
utils.WatchFile(motdFile, (newData) => {
logger.Log(`Motd changed: ${newData.replace(/\/n/g, '')}`)
@ -122,7 +131,12 @@ function GetApp () {
logger.Log(`Version changed: ${newData.replace(/\/n/g, '')}`)
LoadVersion()
})
utils.WatchFile(testUsersFile, (newData) => {
logger.Log(`Test Users file changed: ${newData.replace(/\/n/g, '')}`)
LoadTestUsers()
})
LoadTestUsers()
LoadVersion()
LoadMOTD()
}
@ -566,12 +580,17 @@ function GetApp () {
app.post('/isAdding', function (req, res) {
logger.LogReq(req)
const user = req.session.user
const dryRun = testUsers.includes(user.id)
// automatically saves to dataFile every n write
// FIXME: req.body.datatoadd is for backwards compatibility, remove this sometime in the future
let result = actions.ProcessIncomingRequest(
req.body.datatoadd || req.body,
data,
{ motd, version }
{ motd, version },
dryRun
)
res.json({