diff --git a/server.js b/server.js index 26fc07d..df745af 100644 --- a/server.js +++ b/server.js @@ -25,6 +25,7 @@ const httpsport = 8443 const express = require('express') const vhost = require('vhost') const logger = require('./utils/logger.js') +logger.setNoLogReadInterval() const utils = require('./utils/utils.js') const fs = require('fs') const http = require('http') diff --git a/utils/actions.js b/utils/actions.js index f7237a4..7557c4b 100644 --- a/utils/actions.js +++ b/utils/actions.js @@ -19,8 +19,6 @@ Question Server module.exports = { ProcessIncomingRequest: ProcessIncomingRequest, - CheckData: CheckData, - NLoad: NLoad, LoadJSON: LoadJSON, ProcessQA: ProcessQA } @@ -61,6 +59,11 @@ function ProcessIncomingRequest (data) { let color = logger.GetColor('green') let questions = [] let msg = '' + if (d.data.length > 0) { + msg += `New questions: ${d.data.length} ( All: ${allQuestions.length} )` + } else { + msg += `No new data ( ${allQuestions.length} )` + } if (d.data.length > 0) { let qdb = LoadJSON(utils.ReadFile(dataFile)) d.data.forEach((x) => { @@ -76,7 +79,6 @@ function ProcessIncomingRequest (data) { logger.Log('MOTD/Version writing/reading error!') } - msg += 'All / new count: ' + allQuestions.length + ' / ' + questions.length if (qdb !== undefined && d.data.length > 0) { utils.WriteBackup() utils.WriteFile(JSON.stringify(qdb), dataFile) @@ -94,97 +96,6 @@ function ProcessIncomingRequest (data) { } } -function CheckData (data) { - try { - var presult = NLoad(data) - return presult - } catch (e) { - logger.Log('Load error, ' + e.toString(), logger.GetColor('redbg'), true) - return { - count: -1, - log: [e.toString()] - } - } -} - -function NLoad (resource) { - var resultLog = [] - var allCount = 0 - if (resource === undefined) { throw new Error('A megadott adat undefined!') } - resource = resource.split('\n') // splitting by enters - if (resource.length === 1) { throw new Error('A megadott adat nem sorokból áll!') } - var data = [] // initializing data declared at the begining - - function AddNewSubj (name) { - data.push({ - 'questions': [] - }) // ads aa new object, with an empty array in it - GetCurrSubj().name = name // sets the name for it - GetCurrSubj().count = 0 // setting count to default - // setting if its active only if its undefined, otherwise previous user setting shouldt be overwritten - } - - function AddItem () { // adds an item to the last subjects questions - GetCurrSubj().count++ - allCount++ // incrementing all count - GetCurrSubj().questions.push({}) // adding a new empty object to the last item in the data - } - - function GetLastItem () { // returns the last item of the last item of data - var q = GetCurrSubj().questions.length // questions length - return GetCurrSubj().questions[q - 1] - } - - function GetCurrSubj () { - return data[data.length - 1] - } - - // ? : question - // ! : answer - // > : image JSON data - // + : subject name - - // checking for name - for (var j = 0; j < resource.length; j++) { // goes through resources - if (resource[j][0] === '+') { // if there is a name identifier - break // breaks, couse there will be a name - } - if (resource[j][0] === '?' || resource[j][0] === '!' || resource[j][0] === '>') { // if it begins with another identifier: - AddNewSubj('NONAME') // there is no name (for the first question at least), so setting it noname. - break - } - // else it does nothing, continues to check - } - var jumped = 0 // the amount of lines it processed - for (var i = 0; i < resource.length; i += jumped) { // gouing through the resource - jumped = 0 // resetting it to 0 - var currRawDataQ = resource[i] // current question - var currRawDataA = resource[i + 1] // current answer - var currRawDataI = resource[i + 2] // current image - if (currRawDataQ !== undefined && currRawDataQ[0] === '?' && currRawDataA !== undefined && currRawDataA[0] === '!') { // if the current line is ? and the next is ! its a data - AddItem() - GetLastItem().q = currRawDataQ.substr(1) - GetLastItem().a = currRawDataA.substr(1) - jumped += 2 - if (currRawDataI !== undefined && currRawDataI[0] === '>') { - GetLastItem().i = currRawDataI.substr(1) - jumped++ - } - } else if (currRawDataQ[0] === '+') { // if its a new subject - AddNewSubj(currRawDataQ.substr(1)) - jumped++ - } else { - // this should be invalid question order - resultLog.push('Warning @ line ' + i + ':' + currRawDataQ + ' ' + currRawDataA + ' ' + currRawDataI) - jumped++ - } - } // end of parsing all data - return { - count: allCount, - log: resultLog - } -} - // loading stuff function LoadJSON (resource) { try { diff --git a/utils/logger.js b/utils/logger.js index 45e224b..098264a 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -22,7 +22,8 @@ module.exports = { GetDateString: GetDateString, Log: Log, GetColor: GetColor, - LogReq: LogReq + LogReq: LogReq, + setNoLogReadInterval: setNoLogReadInterval } const DELIM = C('green') + '|' + C() @@ -41,10 +42,14 @@ const colors = [ 'cyan' ] -let noLogips = utils.ReadFile('./nolog').split('\n') -setInterval(() => { +let noLogips = [] + +function setNoLogReadInterval () { noLogips = utils.ReadFile('./nolog').split('\n') -}, 1000 * 60 * 30) + setInterval(() => { + noLogips = utils.ReadFile('./nolog').split('\n') + }, 1000 * 60 * 30) +} function GetDateString () { const m = new Date()