mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Prettied all js in src/
This commit is contained in:
parent
3f081d8dff
commit
ee0f0a9f3b
17 changed files with 1012 additions and 688 deletions
|
@ -19,7 +19,7 @@ Question Server
|
|||
|
||||
module.exports = {
|
||||
ProcessIncomingRequest: ProcessIncomingRequest,
|
||||
LoadJSON: LoadJSON
|
||||
LoadJSON: LoadJSON,
|
||||
}
|
||||
|
||||
const dataFile = './qminingPublic/data.json'
|
||||
|
@ -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, dryRun) {
|
||||
function ProcessIncomingRequest(recievedData, qdb, infos, dryRun) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logger.DebugLog('Processing incoming request', 'actions', 1)
|
||||
if (recievedData === undefined) {
|
||||
|
@ -48,13 +48,15 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
|
||||
try {
|
||||
let towrite = logger.GetDateString() + '\n'
|
||||
towrite += '------------------------------------------------------------------------------\n'
|
||||
towrite +=
|
||||
'------------------------------------------------------------------------------\n'
|
||||
if (typeof recievedData === 'object') {
|
||||
towrite += JSON.stringify(recievedData)
|
||||
} else {
|
||||
towrite += recievedData
|
||||
}
|
||||
towrite += '\n------------------------------------------------------------------------------\n'
|
||||
towrite +=
|
||||
'\n------------------------------------------------------------------------------\n'
|
||||
utils.AppendToFile(towrite, recDataFile)
|
||||
logger.DebugLog('recDataFile written', 'actions', 1)
|
||||
} catch (e) {
|
||||
|
@ -62,7 +64,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
}
|
||||
|
||||
try {
|
||||
// recievedData: { version: "", id: "", subj: "" quiz: {} }
|
||||
// recievedData: { version: "", id: "", subj: "" quiz: {} }
|
||||
let d = recievedData
|
||||
// FIXME: if is for backwards compatibility, remove this sometime in the future
|
||||
if (typeof d !== 'object') {
|
||||
|
@ -78,7 +80,11 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
logger.DebugLog('Question:', 'actions', 2)
|
||||
logger.DebugLog(question, 'actions', 2)
|
||||
let q = new classes.Question(question.Q, question.A, question.data)
|
||||
logger.DebugLog('Searching for question in subj ' + d.subj, 'actions', 3)
|
||||
logger.DebugLog(
|
||||
'Searching for question in subj ' + d.subj,
|
||||
'actions',
|
||||
3
|
||||
)
|
||||
logger.DebugLog(q, 'actions', 3)
|
||||
|
||||
let sames = qdb.Search(q, d.subj)
|
||||
|
@ -86,9 +92,11 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
logger.DebugLog('Length: ' + sames.length, 'actions', 2)
|
||||
logger.DebugLog(sames, 'actions', 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 < minMatchAmmountToAdd
|
||||
})
|
||||
let isNew =
|
||||
sames.length === 0 ||
|
||||
sames.every((searchResItem) => {
|
||||
return searchResItem.match < minMatchAmmountToAdd
|
||||
})
|
||||
logger.DebugLog('isNew: ' + isNew, 'actions', 2)
|
||||
if (isNew) {
|
||||
allQuestions.push(q)
|
||||
|
@ -102,7 +110,11 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
msg += `New questions: ${allQuestions.length} ( All: ${allQLength} )`
|
||||
allQuestions.forEach((q) => {
|
||||
const sName = classes.SUtils.GetSubjNameWithoutYear(d.subj)
|
||||
logger.DebugLog('Adding question with subjName: ' + sName + ' :', 'actions', 3)
|
||||
logger.DebugLog(
|
||||
'Adding question with subjName: ' + sName + ' :',
|
||||
'actions',
|
||||
3
|
||||
)
|
||||
logger.DebugLog(q, 'actions', 3)
|
||||
qdb.AddQuestion(sName, q)
|
||||
})
|
||||
|
@ -134,7 +146,9 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
idStats.LogId(d.id, d.subj)
|
||||
}
|
||||
logger.Log(subjRow)
|
||||
if (d.version !== undefined) { msg += '. Version: ' + d.version }
|
||||
if (d.version !== undefined) {
|
||||
msg += '. Version: ' + d.version
|
||||
}
|
||||
|
||||
logger.Log('\t' + msg, color)
|
||||
logger.DebugLog('New Questions:', 'actions', 2)
|
||||
|
@ -151,7 +165,7 @@ function ProcessIncomingRequest (recievedData, qdb, infos, dryRun) {
|
|||
}
|
||||
|
||||
// loading stuff
|
||||
function LoadJSON (dataFile) {
|
||||
function LoadJSON(dataFile) {
|
||||
try {
|
||||
var d = JSON.parse(utils.ReadFile(dataFile))
|
||||
var r = new classes.QuestionDB()
|
||||
|
@ -166,7 +180,7 @@ function LoadJSON (dataFile) {
|
|||
}
|
||||
rt.push({
|
||||
name: d.Subjects[i].Name,
|
||||
count: j
|
||||
count: j,
|
||||
})
|
||||
r.AddSubject(s)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue