| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /* eslint-disable
- n/handle-callback-err,
- max-len,
- no-unused-vars,
- n/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 SessionManager = require('../Authentication/SessionManager')
- const SplitTestHandler = require('../SplitTests/SplitTestHandler')
- const logger = require('@overleaf/logger')
- const homepageExists = fs.existsSync(
- Path.join(__dirname, '/../../../views/external/home/v2.pug')
- )
- module.exports = HomeController = {
- index(req, res) {
- if (SessionManager.isUserLoggedIn(req.session)) {
- 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)
- }
- },
- async home(req, res) {
- if (Features.hasFeature('homepage') && homepageExists) {
- let designSystemUpdatesAssignment = { variant: 'default' }
- try {
- designSystemUpdatesAssignment =
- await SplitTestHandler.promises.getAssignment(
- req,
- res,
- 'design-system-updates'
- )
- } catch (error) {
- logger.error(
- { err: error },
- 'failed to get "design-system-updates" split test assignment'
- )
- }
- return res.render('external/home/v2', {
- designSystemUpdatesVariant: designSystemUpdatesAssignment.variant,
- })
- } else {
- return res.redirect('/login')
- }
- },
- externalPage(page, title) {
- return function (req, res, next) {
- if (next == null) {
- next = function () {}
- }
- const path = Path.join(__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)
- }
- })
- }
- },
- }
|