mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Removed even more unused stuff, nolog intervel function, minor logging cleanup
This commit is contained in:
parent
19246d6931
commit
ea31d5c0f1
3 changed files with 15 additions and 98 deletions
|
@ -25,6 +25,7 @@ const httpsport = 8443
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const vhost = require('vhost')
|
const vhost = require('vhost')
|
||||||
const logger = require('./utils/logger.js')
|
const logger = require('./utils/logger.js')
|
||||||
|
logger.setNoLogReadInterval()
|
||||||
const utils = require('./utils/utils.js')
|
const utils = require('./utils/utils.js')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const http = require('http')
|
const http = require('http')
|
||||||
|
|
|
@ -19,8 +19,6 @@ Question Server
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
ProcessIncomingRequest: ProcessIncomingRequest,
|
ProcessIncomingRequest: ProcessIncomingRequest,
|
||||||
CheckData: CheckData,
|
|
||||||
NLoad: NLoad,
|
|
||||||
LoadJSON: LoadJSON,
|
LoadJSON: LoadJSON,
|
||||||
ProcessQA: ProcessQA
|
ProcessQA: ProcessQA
|
||||||
}
|
}
|
||||||
|
@ -61,6 +59,11 @@ function ProcessIncomingRequest (data) {
|
||||||
let color = logger.GetColor('green')
|
let color = logger.GetColor('green')
|
||||||
let questions = []
|
let questions = []
|
||||||
let msg = ''
|
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) {
|
if (d.data.length > 0) {
|
||||||
let qdb = LoadJSON(utils.ReadFile(dataFile))
|
let qdb = LoadJSON(utils.ReadFile(dataFile))
|
||||||
d.data.forEach((x) => {
|
d.data.forEach((x) => {
|
||||||
|
@ -76,7 +79,6 @@ function ProcessIncomingRequest (data) {
|
||||||
logger.Log('MOTD/Version writing/reading error!')
|
logger.Log('MOTD/Version writing/reading error!')
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += 'All / new count: ' + allQuestions.length + ' / ' + questions.length
|
|
||||||
if (qdb !== undefined && d.data.length > 0) {
|
if (qdb !== undefined && d.data.length > 0) {
|
||||||
utils.WriteBackup()
|
utils.WriteBackup()
|
||||||
utils.WriteFile(JSON.stringify(qdb), dataFile)
|
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
|
// loading stuff
|
||||||
function LoadJSON (resource) {
|
function LoadJSON (resource) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -22,7 +22,8 @@ module.exports = {
|
||||||
GetDateString: GetDateString,
|
GetDateString: GetDateString,
|
||||||
Log: Log,
|
Log: Log,
|
||||||
GetColor: GetColor,
|
GetColor: GetColor,
|
||||||
LogReq: LogReq
|
LogReq: LogReq,
|
||||||
|
setNoLogReadInterval: setNoLogReadInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
const DELIM = C('green') + '|' + C()
|
const DELIM = C('green') + '|' + C()
|
||||||
|
@ -41,10 +42,14 @@ const colors = [
|
||||||
'cyan'
|
'cyan'
|
||||||
]
|
]
|
||||||
|
|
||||||
let noLogips = utils.ReadFile('./nolog').split('\n')
|
let noLogips = []
|
||||||
setInterval(() => {
|
|
||||||
|
function setNoLogReadInterval () {
|
||||||
noLogips = utils.ReadFile('./nolog').split('\n')
|
noLogips = utils.ReadFile('./nolog').split('\n')
|
||||||
}, 1000 * 60 * 30)
|
setInterval(() => {
|
||||||
|
noLogips = utils.ReadFile('./nolog').split('\n')
|
||||||
|
}, 1000 * 60 * 30)
|
||||||
|
}
|
||||||
|
|
||||||
function GetDateString () {
|
function GetDateString () {
|
||||||
const m = new Date()
|
const m = new Date()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue