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:
		@@ -73,6 +73,7 @@ const rootRedirectToFile = 'data/apiRootRedirectTo'
 | 
				
			|||||||
const recievedQuestionFile = 'stats/recievedQuestions'
 | 
					const recievedQuestionFile = 'stats/recievedQuestions'
 | 
				
			||||||
const registeredScriptsFile = 'stats/registeredScripts.json'
 | 
					const registeredScriptsFile = 'stats/registeredScripts.json'
 | 
				
			||||||
const savedQuestionsFileName = 'savedQuestions.json'
 | 
					const savedQuestionsFileName = 'savedQuestions.json'
 | 
				
			||||||
 | 
					const oldMotdFile = 'publicDirs/qminingPublic/oldMotd'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// other constants
 | 
					// other constants
 | 
				
			||||||
const line = '====================================================' // lol
 | 
					const line = '====================================================' // lol
 | 
				
			||||||
@@ -204,7 +205,9 @@ function GetApp(): ModuleType {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function reloadRootRedirectURL() {
 | 
					  function reloadRootRedirectURL() {
 | 
				
			||||||
    rootRedirectURL = utils.ReadFile(rootRedirectToFile)
 | 
					    if (utils.FileExists(rootRedirectToFile)) {
 | 
				
			||||||
 | 
					      rootRedirectURL = utils.ReadFile(rootRedirectToFile)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const filesToWatch = [
 | 
					  const filesToWatch = [
 | 
				
			||||||
@@ -239,11 +242,18 @@ function GetApp(): ModuleType {
 | 
				
			|||||||
    backupData(questionDbs)
 | 
					    backupData(questionDbs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    filesToWatch.forEach((ftw) => {
 | 
					    filesToWatch.forEach((ftw) => {
 | 
				
			||||||
      utils.WatchFile(ftw.fname, () => {
 | 
					      if (utils.FileExists(ftw.fname)) {
 | 
				
			||||||
        logger.Log(ftw.logMsg)
 | 
					        utils.WatchFile(ftw.fname, () => {
 | 
				
			||||||
 | 
					          logger.Log(ftw.logMsg)
 | 
				
			||||||
 | 
					          ftw.action()
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
        ftw.action()
 | 
					        ftw.action()
 | 
				
			||||||
      })
 | 
					      } else {
 | 
				
			||||||
      ftw.action()
 | 
					        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) {
 | 
					  app.get('/', function(req: Request, res: any) {
 | 
				
			||||||
    logger.LogReq(req)
 | 
					    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) {
 | 
					  app.post('/postfeedbackfile', function(req: Request, res: any) {
 | 
				
			||||||
@@ -962,9 +976,6 @@ function GetApp(): ModuleType {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const location = req.body.location.split('/')[2]
 | 
					    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 {
 | 
					    try {
 | 
				
			||||||
      let maxIndex = -1
 | 
					      let maxIndex = -1
 | 
				
			||||||
      const suitedQuestionDbs = questionDbs.filter((qdb) => {
 | 
					      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) {
 | 
					  app.get('/infos', function(req: Request, res) {
 | 
				
			||||||
    const user: User = req.session.user
 | 
					    const user: User = req.session.user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1275,7 +1297,7 @@ function GetApp(): ModuleType {
 | 
				
			|||||||
      result.version = version
 | 
					      result.version = version
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (req.query.motd) {
 | 
					    if (req.query.motd) {
 | 
				
			||||||
      result.motd = motd
 | 
					      result.motd = getMotd(req.query.cversion)
 | 
				
			||||||
      if (userSpecificMotd[user.id]) {
 | 
					      if (userSpecificMotd[user.id]) {
 | 
				
			||||||
        result.userSpecificMotd = {
 | 
					        result.userSpecificMotd = {
 | 
				
			||||||
          msg: userSpecificMotd[user.id].msg,
 | 
					          msg: userSpecificMotd[user.id].msg,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -134,6 +134,10 @@ function GetApp(): ModuleType {
 | 
				
			|||||||
      from: '/classesgit',
 | 
					      from: '/classesgit',
 | 
				
			||||||
      to: 'https://gitlab.com/MrFry/question-classes',
 | 
					      to: 'https://gitlab.com/MrFry/question-classes',
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      from: '/addQuestion',
 | 
				
			||||||
 | 
					      to: 'https://dataeditor.frylabs.net',
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      from: '/donate',
 | 
					      from: '/donate',
 | 
				
			||||||
      to: donateURL,
 | 
					      to: donateURL,
 | 
				
			||||||
 
 | 
				
			|||||||
 Submodule submodules/qmining-page updated: 7d5b14456f...0f3841a2b4
									
								
							
		Reference in New Issue
	
	Block a user