mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added daily action to api, that logs the subj/question count
This commit is contained in:
parent
d37538afb3
commit
52778532dc
2 changed files with 19 additions and 2 deletions
|
@ -38,6 +38,7 @@ const motdFile = 'public/motd'
|
|||
const versionFile = 'public/version'
|
||||
const passwordFile = 'data/dataEditorPasswords.json'
|
||||
const dataEditsLog = 'stats/dataEdits'
|
||||
const dailyDataCountFile = 'stats/dailyDataCount'
|
||||
|
||||
app.set('view engine', 'ejs')
|
||||
app.set('views', [
|
||||
|
@ -338,5 +339,14 @@ app.post('*', function (req, res) {
|
|||
})
|
||||
|
||||
exports.app = app
|
||||
exports.dailyAction = () => {
|
||||
utils.AppendToFile(JSON.stringify({
|
||||
date: new Date(),
|
||||
subjectCount: data.Subjects.length,
|
||||
questionCOunt: data.Subjects.reduce((acc, subj) => {
|
||||
return acc + subj.Questions.length
|
||||
}, 0)
|
||||
}), dailyDataCountFile)
|
||||
}
|
||||
|
||||
logger.Log('API module started', logger.GetColor('yellow'))
|
||||
|
|
11
server.js
11
server.js
|
@ -98,6 +98,7 @@ Object.keys(modules).forEach(function (k, i) {
|
|||
})
|
||||
}
|
||||
x.app = mod.app
|
||||
x.dailyAction = mod.dailyAction
|
||||
x.urls.forEach((url) => {
|
||||
app.use(vhost(url, x.app))
|
||||
})
|
||||
|
@ -149,11 +150,17 @@ function setLogTimer () {
|
|||
if (e > 100) {
|
||||
setTimeout(setLogTimer, e)
|
||||
} else {
|
||||
logger.Log('Log timer malfunction :/')
|
||||
logger.Log('Log timer malfunction :/', logger.GetColor('redbg'))
|
||||
}
|
||||
|
||||
const line = '-------------------------------------------------------------------------------'
|
||||
Object.keys(modules).forEach((k, i) => {
|
||||
const x = modules[k]
|
||||
if (x.dailyAction) {
|
||||
x.dailyAction()
|
||||
}
|
||||
})
|
||||
|
||||
const line = '==================================================================================================================================================='
|
||||
logger.Log(line)
|
||||
utils.AppendToFile(line, locLogFile)
|
||||
utils.AppendToFile(line, allLogFile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue