Added "test" user checking, unathorized http return code

This commit is contained in:
MrFry 2020-05-10 21:28:10 +02:00
parent 1b078f88b0
commit 2beef493ba
5 changed files with 27 additions and 5 deletions

View file

@ -6,6 +6,7 @@ module.exports = function (options) {
const { userDB, jsonResponse, exceptions } = options
const renderLogin = (req, res) => {
res.status('401') // Unauthorized
if (jsonResponse) {
res.json({
result: 'nouser',

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({

@ -1 +1 @@
Subproject commit d7fffa50d013f97898dbde212c401a647f2cf999
Subproject commit ada93f0bb9b87863e04130e2db77ca52e8087058

@ -1 +1 @@
Subproject commit 2c815c8d20b6c25a4214d6118760d993f2287f36
Subproject commit f8d4bf2a414d2973582c08bfa8b8b8f19389b2e9

View file

@ -38,7 +38,7 @@ const minMatchAmmountToAdd = 90 // FIXME: test this value
const writeAfter = 1 // write after # of adds FIXME: set reasonable save rate
var currWrites = 0
function ProcessIncomingRequest (recievedData, qdb, infos) {
function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
logger.DebugLog('Processing incoming request', 'actions', 1)
if (recievedData === undefined) {
logger.Log('\tRecieved data is undefined!', logger.GetColor('redbg'))
@ -108,7 +108,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
currWrites++
logger.DebugLog('currWrites for data.json: ' + currWrites, 'actions', 1)
if (currWrites >= writeAfter) {
if (currWrites >= writeAfter && !dryRun) {
currWrites = 0
try {
qdb.version = infos.version
@ -120,6 +120,8 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
logger.DebugLog('Writing data.json', 'actions', 1)
utils.WriteFile(JSON.stringify(qdb), dataFile)
logger.Log('\tData file written', color)
} else if (dryRun) {
logger.Log('\tDry run')
}
} else {
msg += `No new data ( ${allQLength} )`