mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Added old motd, and hadling if no root redirect url file is present
This commit is contained in:
parent
1f355309fd
commit
61cfa4099a
3 changed files with 37 additions and 11 deletions
|
@ -73,6 +73,7 @@ const rootRedirectToFile = 'data/apiRootRedirectTo'
|
|||
const recievedQuestionFile = 'stats/recievedQuestions'
|
||||
const registeredScriptsFile = 'stats/registeredScripts.json'
|
||||
const savedQuestionsFileName = 'savedQuestions.json'
|
||||
const oldMotdFile = 'publicDirs/qminingPublic/oldMotd'
|
||||
|
||||
// other constants
|
||||
const line = '====================================================' // lol
|
||||
|
@ -204,7 +205,9 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
|
||||
function reloadRootRedirectURL() {
|
||||
rootRedirectURL = utils.ReadFile(rootRedirectToFile)
|
||||
if (utils.FileExists(rootRedirectToFile)) {
|
||||
rootRedirectURL = utils.ReadFile(rootRedirectToFile)
|
||||
}
|
||||
}
|
||||
|
||||
const filesToWatch = [
|
||||
|
@ -239,11 +242,18 @@ function GetApp(): ModuleType {
|
|||
backupData(questionDbs)
|
||||
|
||||
filesToWatch.forEach((ftw) => {
|
||||
utils.WatchFile(ftw.fname, () => {
|
||||
logger.Log(ftw.logMsg)
|
||||
if (utils.FileExists(ftw.fname)) {
|
||||
utils.WatchFile(ftw.fname, () => {
|
||||
logger.Log(ftw.logMsg)
|
||||
ftw.action()
|
||||
})
|
||||
ftw.action()
|
||||
})
|
||||
ftw.action()
|
||||
} else {
|
||||
logger.Log(
|
||||
`File ${ftw.fname} does not exists to watch!`,
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -660,7 +670,11 @@ function GetApp(): ModuleType {
|
|||
|
||||
app.get('/', function(req: Request, res: any) {
|
||||
logger.LogReq(req)
|
||||
res.redirect(rootRedirectURL)
|
||||
if (reloadRootRedirectURL) {
|
||||
res.redirect(rootRedirectURL)
|
||||
} else {
|
||||
res.json({ msg: 'hi c:' })
|
||||
}
|
||||
})
|
||||
|
||||
app.post('/postfeedbackfile', function(req: Request, res: any) {
|
||||
|
@ -962,9 +976,6 @@ function GetApp(): ModuleType {
|
|||
|
||||
const location = req.body.location.split('/')[2]
|
||||
|
||||
// TODO: handle undefined location
|
||||
// * if location is undefined still try to get suited question dbs
|
||||
// * if there isnt one dont create one, just resp.json(gebasz)
|
||||
try {
|
||||
let maxIndex = -1
|
||||
const suitedQuestionDbs = questionDbs.filter((qdb) => {
|
||||
|
@ -1260,6 +1271,17 @@ function GetApp(): ModuleType {
|
|||
}
|
||||
})
|
||||
|
||||
function getMotd(version) {
|
||||
if (version) {
|
||||
if (version.startsWith('2.0.')) {
|
||||
if (utils.FileExists(oldMotdFile)) {
|
||||
return utils.ReadFile(oldMotdFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
return motd
|
||||
}
|
||||
|
||||
app.get('/infos', function(req: Request, res) {
|
||||
const user: User = req.session.user
|
||||
|
||||
|
@ -1275,7 +1297,7 @@ function GetApp(): ModuleType {
|
|||
result.version = version
|
||||
}
|
||||
if (req.query.motd) {
|
||||
result.motd = motd
|
||||
result.motd = getMotd(req.query.cversion)
|
||||
if (userSpecificMotd[user.id]) {
|
||||
result.userSpecificMotd = {
|
||||
msg: userSpecificMotd[user.id].msg,
|
||||
|
|
|
@ -134,6 +134,10 @@ function GetApp(): ModuleType {
|
|||
from: '/classesgit',
|
||||
to: 'https://gitlab.com/MrFry/question-classes',
|
||||
},
|
||||
{
|
||||
from: '/addQuestion',
|
||||
to: 'https://dataeditor.frylabs.net',
|
||||
},
|
||||
{
|
||||
from: '/donate',
|
||||
to: donateURL,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7d5b14456f8666e52df19206ece84f6068049c26
|
||||
Subproject commit 0f3841a2b4bd4d7a32fb3f75555b8d54b6772538
|
Loading…
Add table
Add a link
Reference in a new issue