mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
motd and version file watching and loading
This commit is contained in:
parent
a1e99c53ae
commit
7c7ed47455
2 changed files with 36 additions and 17 deletions
|
@ -66,6 +66,30 @@ app.use(bodyParser.json({
|
|||
}))
|
||||
|
||||
var data = actions.LoadJSON(dataFile)
|
||||
var version = ''
|
||||
var motd = ''
|
||||
|
||||
function LoadVersion () {
|
||||
version = utils.ReadFile(versionFile)
|
||||
}
|
||||
|
||||
function LoadMOTD () {
|
||||
motd = utils.ReadFile(motdFile)
|
||||
}
|
||||
|
||||
function Load () {
|
||||
utils.WatchFile(motdFile, (newData) => {
|
||||
LoadMOTD()
|
||||
})
|
||||
utils.WatchFile(versionFile, (newData) => {
|
||||
LoadVersion()
|
||||
})
|
||||
|
||||
LoadVersion()
|
||||
LoadMOTD()
|
||||
}
|
||||
|
||||
Load()
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
|
@ -248,8 +272,13 @@ app.route('/badtestsender').post(function (req, res, next) {
|
|||
|
||||
app.post('/isAdding', function (req, res) {
|
||||
logger.LogReq(req)
|
||||
|
||||
// automatically saves to dataFile every n write
|
||||
let result = actions.ProcessIncomingRequest(req.body.datatoadd, data)
|
||||
let result = actions.ProcessIncomingRequest(
|
||||
req.body.datatoadd,
|
||||
data,
|
||||
{ motd, version })
|
||||
|
||||
res.json({
|
||||
success: result !== -1,
|
||||
newQuestions: result
|
||||
|
@ -328,12 +357,11 @@ app.get('/infos', function (req, res) {
|
|||
if (req.query.subjinfo) {
|
||||
result.subjinfo = getSimplreRes()
|
||||
}
|
||||
// TODO: watch file, and global variable for motd version
|
||||
if (req.query.version) {
|
||||
result.version = utils.ReadFile(versionFile)
|
||||
result.version = version
|
||||
}
|
||||
if (req.query.motd) {
|
||||
result.motd = utils.ReadFile(motdFile)
|
||||
result.motd = motd
|
||||
}
|
||||
logger.LogReq(req)
|
||||
res.json(result)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue