mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Actions rewrite to handle multiple data
This commit is contained in:
parent
677c320e90
commit
1acc122e26
5 changed files with 116 additions and 83 deletions
|
@ -68,7 +68,10 @@ function GetApp() {
|
|||
// files in public dirs
|
||||
const recivedFiles = publicDir + 'recivedfiles'
|
||||
const uloadFiles = publicDir + 'f'
|
||||
const dataFile = publicDir + 'data.json'
|
||||
const dataFiles = [
|
||||
{ path: `${publicDir}oldData.json`, name: 'oldData' },
|
||||
{ path: `${publicDir}data.json`, name: 'newData' },
|
||||
]
|
||||
const motdFile = publicDir + 'motd'
|
||||
const userSpecificMotdFile = publicDir + 'userSpecificMotd.json'
|
||||
const versionFile = publicDir + 'version'
|
||||
|
@ -113,7 +116,7 @@ function GetApp() {
|
|||
})
|
||||
)
|
||||
|
||||
var data = actions.LoadJSON(dataFile)
|
||||
var questionDbs = actions.LoadJSON(dataFiles)
|
||||
var version = ''
|
||||
var motd = ''
|
||||
var userSpecificMotd = {}
|
||||
|
@ -187,7 +190,7 @@ function GetApp() {
|
|||
}
|
||||
|
||||
function Load() {
|
||||
actions.backupData(data)
|
||||
actions.backupData(questionDbs)
|
||||
|
||||
utils.WatchFile(userSpecificMotdFile, () => {
|
||||
logger.Log(`User Specific Motd updated`, logger.GetColor('green'))
|
||||
|
@ -800,7 +803,11 @@ function GetApp() {
|
|||
|
||||
app.get('/allqr.txt', function(req, res) {
|
||||
res.set('Content-Type', 'text/plain')
|
||||
res.send(dataToString(data))
|
||||
const stringifiedData = questionDbs.map((qdb) => {
|
||||
return dataToString(qdb.data)
|
||||
})
|
||||
// TODO: test this
|
||||
res.send(stringifiedData.join('\n\n'))
|
||||
res.end()
|
||||
logger.LogReq(req)
|
||||
})
|
||||
|
@ -881,18 +888,19 @@ function GetApp() {
|
|||
)
|
||||
|
||||
// making backup
|
||||
utils.CopyFile(
|
||||
'./' + dataFile,
|
||||
`./publicDirs/qminingPublic/backs/data_before_${
|
||||
user.name
|
||||
}_${utils.GetDateString().replace(/ /g, '_')}`
|
||||
) // TODO: rewrite to dinamyc public!!!
|
||||
logger.Log('Backup made')
|
||||
// writing data
|
||||
utils.WriteFile(JSON.stringify(newData), dataFile)
|
||||
logger.Log('New data file written')
|
||||
// reloading data file
|
||||
data = [...newData]
|
||||
// TODO
|
||||
// utils.CopyFile(
|
||||
// './' + dataFile,
|
||||
// `./publicDirs/qminingPublic/backs/data_before_${
|
||||
// user.name
|
||||
// }_${utils.GetDateString().replace(/ /g, '_')}`
|
||||
// ) // TODO: rewrite to dinamyc public!!!
|
||||
// logger.Log('Backup made')
|
||||
// // writing data
|
||||
// utils.WriteFile(JSON.stringify(newData), dataFile)
|
||||
// logger.Log('New data file written')
|
||||
// // reloading data file
|
||||
// data = [...newData]
|
||||
// data = newData
|
||||
logger.Log('Data set to newData')
|
||||
|
||||
|
@ -920,7 +928,7 @@ function GetApp() {
|
|||
actions
|
||||
.ProcessIncomingRequest(
|
||||
req.body.datatoadd || req.body,
|
||||
data,
|
||||
questionDbs,
|
||||
dryRun,
|
||||
user
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue