mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Empty question fix
This commit is contained in:
parent
09a04c4ae7
commit
b5d5f20b79
6 changed files with 284 additions and 31 deletions
|
@ -97,7 +97,7 @@ export function processIncomingRequest(
|
|||
dryRun: boolean,
|
||||
user: User
|
||||
): Promise<Array<Result>> {
|
||||
logger.DebugLog('Processing incoming request', 'actions', 1)
|
||||
logger.DebugLog('Processing incoming request', 'isadding', 1)
|
||||
|
||||
if (recievedData === undefined) {
|
||||
logger.Log('\tRecieved data is undefined!', logger.GetColor('redbg'))
|
||||
|
@ -116,7 +116,7 @@ export function processIncomingRequest(
|
|||
towrite +=
|
||||
'\n------------------------------------------------------------------------------\n'
|
||||
utils.AppendToFile(towrite, recDataFile)
|
||||
logger.DebugLog('recDataFile written', 'actions', 1)
|
||||
logger.DebugLog('recDataFile written', 'isadding', 1)
|
||||
} catch (err) {
|
||||
logger.Log('Error writing recieved data.')
|
||||
}
|
||||
|
@ -147,13 +147,13 @@ function processIncomingRequestUsingDb(
|
|||
try {
|
||||
const recievedQuestions = []
|
||||
|
||||
logger.DebugLog('recievedData JSON parsed', 'actions', 1)
|
||||
logger.DebugLog(recievedData, 'actions', 3)
|
||||
logger.DebugLog('recievedData JSON parsed', 'isadding', 1)
|
||||
logger.DebugLog(recievedData, 'isadding', 3)
|
||||
const allQLength = recievedData.quiz.length
|
||||
const questionSearchPromises = []
|
||||
recievedData.quiz.forEach((question) => {
|
||||
logger.DebugLog('Question:', 'actions', 2)
|
||||
logger.DebugLog(question, 'actions', 2)
|
||||
logger.DebugLog('Question:', 'isadding', 2)
|
||||
logger.DebugLog(question, 'isadding', 2)
|
||||
const currentQuestion = createQuestion(
|
||||
question.Q,
|
||||
question.A,
|
||||
|
@ -161,24 +161,29 @@ function processIncomingRequestUsingDb(
|
|||
)
|
||||
logger.DebugLog(
|
||||
'Searching for question in subj ' + recievedData.subj,
|
||||
'actions',
|
||||
'isadding',
|
||||
3
|
||||
)
|
||||
logger.DebugLog(currentQuestion, 'actions', 3)
|
||||
recievedQuestions.push(currentQuestion)
|
||||
// This here searches only in relevant subjects, and not all subjects
|
||||
questionSearchPromises.push(
|
||||
doALongTask({
|
||||
type: 'work',
|
||||
data: {
|
||||
searchIn: [qdb.index],
|
||||
qdb: qdb.data,
|
||||
question: currentQuestion,
|
||||
subjName: recievedData.subj,
|
||||
searchTillMatchPercent: minMatchAmmountToAdd,
|
||||
},
|
||||
})
|
||||
)
|
||||
logger.DebugLog(currentQuestion, 'isadding', 3)
|
||||
if (isQuestionValid(currentQuestion)) {
|
||||
recievedQuestions.push(currentQuestion)
|
||||
// This here searches only in relevant subjects, and not all subjects
|
||||
questionSearchPromises.push(
|
||||
doALongTask({
|
||||
type: 'work',
|
||||
data: {
|
||||
searchIn: [qdb.index],
|
||||
qdb: qdb.data,
|
||||
question: currentQuestion,
|
||||
subjName: recievedData.subj,
|
||||
searchTillMatchPercent: minMatchAmmountToAdd,
|
||||
},
|
||||
})
|
||||
)
|
||||
} else {
|
||||
logger.DebugLog('Question isnt valid', 'isadding', 1)
|
||||
logger.DebugLog(currentQuestion, 'isadding', 1)
|
||||
}
|
||||
})
|
||||
|
||||
Promise.all(questionSearchPromises)
|
||||
|
@ -199,22 +204,22 @@ function processIncomingRequestUsingDb(
|
|||
const sName = getSubjNameWithoutYear(recievedData.subj)
|
||||
logger.DebugLog(
|
||||
'Adding question with subjName: ' + sName + ' :',
|
||||
'actions',
|
||||
'isadding',
|
||||
3
|
||||
)
|
||||
logger.DebugLog(currentQuestion, 'actions', 3)
|
||||
logger.DebugLog(currentQuestion, 'isadding', 3)
|
||||
addQuestion(qdb.data, sName, currentQuestion)
|
||||
})
|
||||
|
||||
currWrites++
|
||||
logger.DebugLog(
|
||||
'currWrites for data.json: ' + currWrites,
|
||||
'actions',
|
||||
'isadding',
|
||||
1
|
||||
)
|
||||
if (currWrites >= writeAfter && !dryRun) {
|
||||
currWrites = 0
|
||||
logger.DebugLog('Writing data.json', 'actions', 1)
|
||||
logger.DebugLog('Writing data.json', 'isadding', 1)
|
||||
utils.WriteFile(JSON.stringify(qdb.data), qdb.path)
|
||||
}
|
||||
}
|
||||
|
@ -226,10 +231,10 @@ function processIncomingRequestUsingDb(
|
|||
allQLength
|
||||
)
|
||||
|
||||
logger.DebugLog('New Questions:', 'actions', 2)
|
||||
logger.DebugLog(allQuestions, 'actions', 2)
|
||||
logger.DebugLog('New Questions:', 'isadding', 2)
|
||||
logger.DebugLog(allQuestions, 'isadding', 2)
|
||||
|
||||
logger.DebugLog('ProcessIncomingRequest done', 'actions', 1)
|
||||
logger.DebugLog('ProcessIncomingRequest done', 'isadding', 1)
|
||||
resolve({
|
||||
newQuestions: allQuestions.length,
|
||||
qdbName: qdb.name,
|
||||
|
@ -263,6 +268,16 @@ function processIncomingRequestUsingDb(
|
|||
})
|
||||
}
|
||||
|
||||
function isQuestionValid(question: Question) {
|
||||
if (!question.Q) {
|
||||
return false
|
||||
}
|
||||
if (!question.Q && question.data.type !== 'image') {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function shouldSearchDataFile(df: DataFile, testUrl: string): Boolean {
|
||||
if (typeof df.shouldSearch === 'string' && df.shouldSearch === 'always') {
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue