HomeController.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* eslint-disable
  2. n/handle-callback-err,
  3. max-len,
  4. no-unused-vars,
  5. n/no-deprecated-api,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. let HomeController
  16. const Features = require('../../infrastructure/Features')
  17. const Path = require('path')
  18. const fs = require('fs')
  19. const ErrorController = require('../Errors/ErrorController')
  20. const SessionManager = require('../Authentication/SessionManager')
  21. const SplitTestHandler = require('../SplitTests/SplitTestHandler')
  22. const logger = require('@overleaf/logger')
  23. const homepageExists = fs.existsSync(
  24. Path.join(__dirname, '/../../../views/external/home/v2.pug')
  25. )
  26. module.exports = HomeController = {
  27. index(req, res) {
  28. if (SessionManager.isUserLoggedIn(req.session)) {
  29. if (req.query.scribtex_path != null) {
  30. return res.redirect(`/project?scribtex_path=${req.query.scribtex_path}`)
  31. } else {
  32. return res.redirect('/project')
  33. }
  34. } else {
  35. return HomeController.home(req, res)
  36. }
  37. },
  38. async home(req, res) {
  39. if (Features.hasFeature('homepage') && homepageExists) {
  40. let designSystemUpdatesAssignment = { variant: 'default' }
  41. try {
  42. designSystemUpdatesAssignment =
  43. await SplitTestHandler.promises.getAssignment(
  44. req,
  45. res,
  46. 'design-system-updates'
  47. )
  48. } catch (error) {
  49. logger.error(
  50. { err: error },
  51. 'failed to get "design-system-updates" split test assignment'
  52. )
  53. }
  54. const onboardingFlowAssignment =
  55. await SplitTestHandler.promises.getAssignment(
  56. req,
  57. res,
  58. 'onboarding-flow'
  59. )
  60. return res.render('external/home/v2', {
  61. designSystemUpdatesVariant: designSystemUpdatesAssignment.variant,
  62. hideNewsletterCheckbox:
  63. onboardingFlowAssignment?.variant === 'token-confirmation-odc',
  64. })
  65. } else {
  66. return res.redirect('/login')
  67. }
  68. },
  69. externalPage(page, title) {
  70. return function (req, res, next) {
  71. if (next == null) {
  72. next = function () {}
  73. }
  74. const path = Path.join(__dirname, `/../../../views/external/${page}.pug`)
  75. return fs.exists(path, function (exists) {
  76. // No error in this callback - old method in Node.js!
  77. if (exists) {
  78. return res.render(`external/${page}.pug`, { title })
  79. } else {
  80. return ErrorController.notFound(req, res, next)
  81. }
  82. })
  83. }
  84. },
  85. }