Files
Verso/services/web/app/src/Features/StaticPages/HomeController.js
T
Alasdair Smith 5636386c54 Merge pull request #2944 from overleaf/as-clean-up-home-controller
Remove unnecessary check for SL homepage

GitOrigin-RevId: 3173ddd682458f36e11c77d8644500b8ce8af1cb
2020-06-24 02:10:23 +00:00

69 lines
1.9 KiB
JavaScript

/* eslint-disable
handle-callback-err,
max-len,
no-path-concat,
no-unused-vars,
node/no-deprecated-api,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let HomeController
const Features = require('../../infrastructure/Features')
const Path = require('path')
const fs = require('fs')
const ErrorController = require('../Errors/ErrorController')
const AuthenticationController = require('../Authentication/AuthenticationController')
const homepageExists = fs.existsSync(
Path.resolve(__dirname + '/../../../views/external/home/v2.pug')
)
module.exports = HomeController = {
index(req, res) {
if (AuthenticationController.isUserLoggedIn(req)) {
if (req.query.scribtex_path != null) {
return res.redirect(`/project?scribtex_path=${req.query.scribtex_path}`)
} else {
return res.redirect('/project')
}
} else {
return HomeController.home(req, res)
}
},
home(req, res, next) {
if (Features.hasFeature('homepage') && homepageExists) {
return res.render('external/home/v2')
} else {
return res.redirect('/login')
}
},
externalPage(page, title) {
return function(req, res, next) {
if (next == null) {
next = function(error) {}
}
const path = Path.resolve(
__dirname + `/../../../views/external/${page}.pug`
)
return fs.exists(path, function(exists) {
// No error in this callback - old method in Node.js!
if (exists) {
return res.render(`external/${page}.pug`, { title })
} else {
return ErrorController.notFound(req, res, next)
}
})
}
}
}