mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added debug logging
This commit is contained in:
parent
72aefca297
commit
a7a75bd9d4
4 changed files with 62 additions and 6 deletions
|
@ -37,6 +37,7 @@ const writeAfter = 1 // write after # of adds FIXME: set reasonable save rate
|
|||
var currWrites = 0
|
||||
|
||||
function ProcessIncomingRequest (recievedData, qdb, infos) {
|
||||
logger.DebugLog('Processing incoming request', 1)
|
||||
if (recievedData === undefined) {
|
||||
logger.Log('\tRecieved data is undefined!', logger.GetColor('redbg'))
|
||||
return
|
||||
|
@ -48,6 +49,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
|
|||
towrite += recievedData
|
||||
towrite += '\n------------------------------------------------------------------------------\n'
|
||||
utils.AppendToFile(towrite, recDataFile)
|
||||
logger.DebugLog('recDataFile written', 1)
|
||||
} catch (e) {
|
||||
logger.log('Error writing recieved data.')
|
||||
}
|
||||
|
@ -55,20 +57,29 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
|
|||
try {
|
||||
// recievedData: { version: "", id: "", subj: "" quiz: {} }
|
||||
let d = JSON.parse(recievedData)
|
||||
logger.DebugLog('recievedData JSON parsed', 1)
|
||||
let allQLength = d.quiz.length
|
||||
let allQuestions = []
|
||||
|
||||
logger.DebugLog(logger.hr, 2)
|
||||
d.quiz.forEach((question) => {
|
||||
logger.DebugLog('Question:', 2)
|
||||
logger.DebugLog(question, 2)
|
||||
let q = new classes.Question(question.Q, question.A, question.data)
|
||||
let sames = qdb.Search(q, d.subj)
|
||||
logger.DebugLog('Same questions:', 2)
|
||||
logger.DebugLog('Length: ' + sames.length, 2)
|
||||
logger.DebugLog(sames, 3)
|
||||
// if it didnt find any question, or every found questions match is lower thatn 80
|
||||
let isNew = sames.length === 0 || sames.every(searchResItem => {
|
||||
return searchResItem.match < classes.minMatchAmmount
|
||||
})
|
||||
logger.DebugLog('isNew: ' + isNew, 2)
|
||||
if (isNew) {
|
||||
allQuestions.push(q)
|
||||
}
|
||||
})
|
||||
logger.DebugLog(logger.hr, 2)
|
||||
|
||||
let color = logger.GetColor('green')
|
||||
let msg = ''
|
||||
|
@ -81,15 +92,17 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
|
|||
})
|
||||
|
||||
currWrites++
|
||||
console.log(currWrites)
|
||||
logger.DebugLog('currWrites for data.json: ' + currWrites, 1)
|
||||
if (currWrites >= writeAfter) {
|
||||
currWrites = 0
|
||||
try {
|
||||
qdb.version = infos.version
|
||||
qdb.motd = infos.motd
|
||||
logger.DebugLog('version and motd set for data.json', 3)
|
||||
} catch (e) {
|
||||
logger.Log('MOTD/Version writing/reading error!')
|
||||
}
|
||||
logger.DebugLog('Writing data.json', 1)
|
||||
utils.WriteFile(JSON.stringify(qdb), dataFile)
|
||||
logger.Log('\tData file written', color)
|
||||
}
|
||||
|
@ -106,6 +119,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos) {
|
|||
if (d.version !== undefined) { msg += '. Version: ' + d.version }
|
||||
|
||||
logger.Log('\t' + msg, color)
|
||||
logger.DebugLog('ProcessIncomingRequest done', 1)
|
||||
return allQuestions.length
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue