Migrate Features to ES modules

GitOrigin-RevId: 4e9d3176b4b5a5504afc102e569a27d7788864a3
This commit is contained in:
Andrew Rumble 2024-10-10 11:15:51 +01:00 committed by Copybot
parent fac23dbbdc
commit c6c62088cc
70 changed files with 622 additions and 612 deletions

View file

@ -6,12 +6,12 @@ import metrics from '@overleaf/metrics'
import Settings from '@overleaf/settings' import Settings from '@overleaf/settings'
import logger from '@overleaf/logger' import logger from '@overleaf/logger'
import PlansLocator from './app/src/Features/Subscription/PlansLocator.js' import PlansLocator from './app/src/Features/Subscription/PlansLocator.js'
import SiteAdminHandler from './app/src/infrastructure/SiteAdminHandler.js' import SiteAdminHandler from './app/src/infrastructure/SiteAdminHandler.mjs'
import http from 'node:http' import http from 'node:http'
import https from 'node:https' import https from 'node:https'
import * as Serializers from './app/src/infrastructure/LoggerSerializers.js' import * as Serializers from './app/src/infrastructure/LoggerSerializers.mjs'
import Server from './app/src/infrastructure/Server.mjs' import Server from './app/src/infrastructure/Server.mjs'
import QueueWorkers from './app/src/infrastructure/QueueWorkers.js' import QueueWorkers from './app/src/infrastructure/QueueWorkers.js'

View file

@ -1,9 +1,9 @@
const metrics = require('@overleaf/metrics') import metrics from '@overleaf/metrics'
const AnalyticsManager = require('./AnalyticsManager') import AnalyticsManager from './AnalyticsManager.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const GeoIpLookup = require('../../infrastructure/GeoIpLookup') import GeoIpLookup from '../../infrastructure/GeoIpLookup.js'
const Features = require('../../infrastructure/Features') import Features from '../../infrastructure/Features.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function updateEditingSession(req, res, next) { async function updateEditingSession(req, res, next) {
if (!Features.hasFeature('analytics')) { if (!Features.hasFeature('analytics')) {
@ -46,7 +46,7 @@ function recordEvent(req, res, next) {
res.sendStatus(202) res.sendStatus(202)
} }
module.exports = { export default {
updateEditingSession: expressify(updateEditingSession), updateEditingSession: expressify(updateEditingSession),
recordEvent, recordEvent,
} }

View file

@ -1,8 +1,8 @@
const settings = require('@overleaf/settings') import settings from '@overleaf/settings'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const httpProxy = require('express-http-proxy') import httpProxy from 'express-http-proxy'
module.exports = { export default {
call(basePath) { call(basePath) {
if (!settings.apis.analytics) { if (!settings.apis.analytics) {
return (req, res, next) => return (req, res, next) =>

View file

@ -1,8 +1,8 @@
const AuthenticationController = require('./../Authentication/AuthenticationController') import AuthenticationController from './../Authentication/AuthenticationController.js'
const AnalyticsController = require('./AnalyticsController') import AnalyticsController from './AnalyticsController.mjs'
const AnalyticsProxy = require('./AnalyticsProxy') import AnalyticsProxy from './AnalyticsProxy.mjs'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const rateLimiters = { const rateLimiters = {
recordEvent: new RateLimiter('analytics-record-event', { recordEvent: new RateLimiter('analytics-record-event', {
@ -19,7 +19,7 @@ const rateLimiters = {
), ),
} }
module.exports = { export default {
apply(webRouter, privateApiRouter, publicApiRouter) { apply(webRouter, privateApiRouter, publicApiRouter) {
webRouter.post( webRouter.post(
'/event/:event([a-z0-9-_]+)', '/event/:event([a-z0-9-_]+)',

View file

@ -1,11 +1,11 @@
const _ = require('lodash') import _ from 'lodash'
const RequestHelper = require('./RequestHelper') import RequestHelper from './RequestHelper.js'
const AnalyticsManager = require('./AnalyticsManager') import AnalyticsManager from './AnalyticsManager.js'
const querystring = require('querystring') import querystring from 'querystring'
const { URL } = require('url') import { URL } from 'url'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
function recordUTMTags() { function recordUTMTags() {
return function (req, res, next) { return function (req, res, next) {
@ -53,6 +53,6 @@ function recordUTMTags() {
} }
} }
module.exports = { export default {
recordUTMTags, recordUTMTags,
} }

View file

@ -1,10 +1,10 @@
const BetaProgramHandler = require('./BetaProgramHandler') import BetaProgramHandler from './BetaProgramHandler.mjs'
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const SplitTestSessionHandler = require('../SplitTests/SplitTestSessionHandler') import SplitTestSessionHandler from '../SplitTests/SplitTestSessionHandler.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function optIn(req, res) { async function optIn(req, res) {
const userId = SessionManager.getLoggedInUserId(req.session) const userId = SessionManager.getLoggedInUserId(req.session)
@ -50,7 +50,7 @@ async function optInPage(req, res) {
}) })
} }
module.exports = { export default {
optIn: expressify(optIn), optIn: expressify(optIn),
optOut: expressify(optOut), optOut: expressify(optOut),
optInPage: expressify(optInPage), optInPage: expressify(optInPage),

View file

@ -1,7 +1,7 @@
const { callbackify } = require('util') import { callbackify } from 'util'
const metrics = require('@overleaf/metrics') import metrics from '@overleaf/metrics'
const UserUpdater = require('../User/UserUpdater') import UserUpdater from '../User/UserUpdater.js'
const AnalyticsManager = require('../Analytics/AnalyticsManager') import AnalyticsManager from '../Analytics/AnalyticsManager.js'
async function optIn(userId) { async function optIn(userId) {
await UserUpdater.promises.updateUser(userId, { $set: { betaProgram: true } }) await UserUpdater.promises.updateUser(userId, { $set: { betaProgram: true } })
@ -25,7 +25,7 @@ async function optOut(userId) {
) )
} }
module.exports = { export default {
optIn: callbackify(optIn), optIn: callbackify(optIn),
optOut: callbackify(optOut), optOut: callbackify(optOut),
promises: { promises: {

View file

@ -1,24 +1,26 @@
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const HttpErrorHandler = require('../../Features/Errors/HttpErrorHandler') import HttpErrorHandler from '../../Features/Errors/HttpErrorHandler.js'
const { ObjectId } = require('mongodb-legacy') import mongodb from 'mongodb-legacy'
const CollaboratorsHandler = require('./CollaboratorsHandler') import CollaboratorsHandler from './CollaboratorsHandler.js'
const CollaboratorsGetter = require('./CollaboratorsGetter') import CollaboratorsGetter from './CollaboratorsGetter.js'
const OwnershipTransferHandler = require('./OwnershipTransferHandler') import OwnershipTransferHandler from './OwnershipTransferHandler.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const EditorRealTimeController = require('../Editor/EditorRealTimeController') import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
const TagsHandler = require('../Tags/TagsHandler') import TagsHandler from '../Tags/TagsHandler.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const { hasAdminAccess } = require('../Helpers/AdminAuthorizationHelper') import { hasAdminAccess } from '../Helpers/AdminAuthorizationHelper.js'
const TokenAccessHandler = require('../TokenAccess/TokenAccessHandler') import TokenAccessHandler from '../TokenAccess/TokenAccessHandler.js'
const ProjectAuditLogHandler = require('../Project/ProjectAuditLogHandler') import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.js'
const ProjectGetter = require('../Project/ProjectGetter') import ProjectGetter from '../Project/ProjectGetter.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const LimitationsManager = require('../Subscription/LimitationsManager') import LimitationsManager from '../Subscription/LimitationsManager.js'
const PrivilegeLevels = require('../Authorization/PrivilegeLevels') import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
module.exports = { const ObjectId = mongodb.ObjectId
export default {
removeUserFromProject: expressify(removeUserFromProject), removeUserFromProject: expressify(removeUserFromProject),
removeSelfFromProject: expressify(removeSelfFromProject), removeSelfFromProject: expressify(removeSelfFromProject),
getAllMembers: expressify(getAllMembers), getAllMembers: expressify(getAllMembers),

View file

@ -1,7 +1,7 @@
const { callbackify } = require('util') import { callbackify } from 'util'
const { Project } = require('../../models/Project') import { Project } from '../../models/Project.js'
const EmailHandler = require('../Email/EmailHandler') import EmailHandler from '../Email/EmailHandler.js'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const CollaboratorsEmailHandler = { const CollaboratorsEmailHandler = {
_buildInviteUrl(project, invite) { _buildInviteUrl(project, invite) {
@ -28,7 +28,7 @@ const CollaboratorsEmailHandler = {
}, },
} }
module.exports = { export default {
promises: CollaboratorsEmailHandler, promises: CollaboratorsEmailHandler,
notifyUserOfProjectInvite: callbackify( notifyUserOfProjectInvite: callbackify(
CollaboratorsEmailHandler.notifyUserOfProjectInvite CollaboratorsEmailHandler.notifyUserOfProjectInvite

View file

@ -1,23 +1,23 @@
const { callbackify } = require('util') import { callbackify } from 'util'
const ProjectGetter = require('../Project/ProjectGetter') import ProjectGetter from '../Project/ProjectGetter.js'
const LimitationsManager = require('../Subscription/LimitationsManager') import LimitationsManager from '../Subscription/LimitationsManager.js'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const CollaboratorsGetter = require('./CollaboratorsGetter') import CollaboratorsGetter from './CollaboratorsGetter.js'
const CollaboratorsInviteHandler = require('./CollaboratorsInviteHandler') import CollaboratorsInviteHandler from './CollaboratorsInviteHandler.mjs'
const CollaboratorsInviteGetter = require('./CollaboratorsInviteGetter') import CollaboratorsInviteGetter from './CollaboratorsInviteGetter.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const EmailHelper = require('../Helpers/EmailHelper') import EmailHelper from '../Helpers/EmailHelper.js'
const EditorRealTimeController = require('../Editor/EditorRealTimeController') import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
const AnalyticsManager = require('../Analytics/AnalyticsManager') import AnalyticsManager from '../Analytics/AnalyticsManager.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const ProjectAuditLogHandler = require('../Project/ProjectAuditLogHandler') import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const PrivilegeLevels = require('../Authorization/PrivilegeLevels') import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
// This rate limiter allows a different number of requests depending on the // This rate limiter allows a different number of requests depending on the
// number of callaborators a user is allowed. This is implemented by providing // number of callaborators a user is allowed. This is implemented by providing
@ -398,7 +398,7 @@ const CollaboratorsInviteController = {
}, },
} }
module.exports = { export default {
promises: CollaboratorsInviteController, promises: CollaboratorsInviteController,
getAllInvites: expressify(CollaboratorsInviteController.getAllInvites), getAllInvites: expressify(CollaboratorsInviteController.getAllInvites),
inviteToProject: expressify(CollaboratorsInviteController.inviteToProject), inviteToProject: expressify(CollaboratorsInviteController.inviteToProject),

View file

@ -1,18 +1,18 @@
const { callbackify } = require('util') import { callbackify } from 'util'
const { ProjectInvite } = require('../../models/ProjectInvite') import { ProjectInvite } from '../../models/ProjectInvite.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const CollaboratorsEmailHandler = require('./CollaboratorsEmailHandler') import CollaboratorsEmailHandler from './CollaboratorsEmailHandler.mjs'
const CollaboratorsHandler = require('./CollaboratorsHandler') import CollaboratorsHandler from './CollaboratorsHandler.js'
const CollaboratorsInviteGetter = require('./CollaboratorsInviteGetter') import CollaboratorsInviteGetter from './CollaboratorsInviteGetter.js'
const CollaboratorsInviteHelper = require('./CollaboratorsInviteHelper') import CollaboratorsInviteHelper from './CollaboratorsInviteHelper.js'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const ProjectGetter = require('../Project/ProjectGetter') import ProjectGetter from '../Project/ProjectGetter.js'
const NotificationsBuilder = require('../Notifications/NotificationsBuilder') import NotificationsBuilder from '../Notifications/NotificationsBuilder.js'
const PrivilegeLevels = require('../Authorization/PrivilegeLevels') import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const LimitationsManager = require('../Subscription/LimitationsManager') import LimitationsManager from '../Subscription/LimitationsManager.js'
const ProjectAuditLogHandler = require('../Project/ProjectAuditLogHandler') import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.js'
const _ = require('lodash') import _ from 'lodash'
const CollaboratorsInviteHandler = { const CollaboratorsInviteHandler = {
async _trySendInviteNotification(projectId, sendingUser, invite) { async _trySendInviteNotification(projectId, sendingUser, invite) {
@ -198,7 +198,7 @@ const CollaboratorsInviteHandler = {
}, },
} }
module.exports = { export default {
promises: CollaboratorsInviteHandler, promises: CollaboratorsInviteHandler,
inviteToProject: callbackify(CollaboratorsInviteHandler.inviteToProject), inviteToProject: callbackify(CollaboratorsInviteHandler.inviteToProject),
revokeInviteForUser: callbackify( revokeInviteForUser: callbackify(

View file

@ -1,13 +1,13 @@
const CollaboratorsController = require('./CollaboratorsController') import CollaboratorsController from './CollaboratorsController.mjs'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware') import AuthorizationMiddleware from '../Authorization/AuthorizationMiddleware.js'
const PrivilegeLevels = require('../Authorization/PrivilegeLevels') import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
const CollaboratorsInviteController = require('./CollaboratorsInviteController') import CollaboratorsInviteController from './CollaboratorsInviteController.mjs'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const CaptchaMiddleware = require('../Captcha/CaptchaMiddleware') import CaptchaMiddleware from '../Captcha/CaptchaMiddleware.js'
const AnalyticsRegistrationSourceMiddleware = require('../Analytics/AnalyticsRegistrationSourceMiddleware') import AnalyticsRegistrationSourceMiddleware from '../Analytics/AnalyticsRegistrationSourceMiddleware.js'
const { Joi, validate } = require('../../infrastructure/Validation') import { Joi, validate } from '../../infrastructure/Validation.js'
const rateLimiters = { const rateLimiters = {
inviteToProjectByProjectId: new RateLimiter( inviteToProjectByProjectId: new RateLimiter(
@ -32,7 +32,7 @@ const rateLimiters = {
}), }),
} }
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
webRouter.post( webRouter.post(
'/project/:Project_id/leave', '/project/:Project_id/leave',

View file

@ -1,8 +1,8 @@
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const ContactManager = require('./ContactManager') import ContactManager from './ContactManager.js'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const Modules = require('../../infrastructure/Modules') import Modules from '../../infrastructure/Modules.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
function _formatContact(contact) { function _formatContact(contact) {
return { return {
@ -55,6 +55,6 @@ async function getContacts(req, res) {
}) })
} }
module.exports = { export default {
getContacts: expressify(getContacts), getContacts: expressify(getContacts),
} }

View file

@ -1,7 +1,7 @@
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const ContactController = require('./ContactController') import ContactController from './ContactController.mjs'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
function contactsAuthenticationMiddleware() { function contactsAuthenticationMiddleware() {
if (!Settings.allowAnonymousReadAndWriteSharing) { if (!Settings.allowAnonymousReadAndWriteSharing) {
@ -17,7 +17,7 @@ function contactsAuthenticationMiddleware() {
} }
} }
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
webRouter.get( webRouter.get(
'/user/contacts', '/user/contacts',

View file

@ -10,11 +10,12 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let CooldownMiddleware import CooldownManager from './CooldownManager.js'
const CooldownManager = require('./CooldownManager') import logger from '@overleaf/logger'
const logger = require('@overleaf/logger')
module.exports = CooldownMiddleware = { let CooldownMiddleware
export default CooldownMiddleware = {
freezeProject(req, res, next) { freezeProject(req, res, next) {
const projectId = req.params.Project_id const projectId = req.params.Project_id
if (projectId == null) { if (projectId == null) {

View file

@ -1,8 +1,8 @@
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const DocumentUpdaterHandler = require('./DocumentUpdaterHandler') import DocumentUpdaterHandler from './DocumentUpdaterHandler.js'
const ProjectLocator = require('../Project/ProjectLocator') import ProjectLocator from '../Project/ProjectLocator.js'
const { plainTextResponse } = require('../../infrastructure/Response') import { plainTextResponse } from '../../infrastructure/Response.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function getDoc(req, res) { async function getDoc(req, res) {
const projectId = req.params.Project_id const projectId = req.params.Project_id
@ -42,7 +42,7 @@ async function getDoc(req, res) {
} }
} }
module.exports = { export default {
getDoc: expressify(getDoc), getDoc: expressify(getDoc),
promises: { promises: {
getDoc, getDoc,

View file

@ -1,12 +1,12 @@
const ChatApiHandler = require('../Chat/ChatApiHandler') import ChatApiHandler from '../Chat/ChatApiHandler.js'
const ProjectGetter = require('../Project/ProjectGetter') import ProjectGetter from '../Project/ProjectGetter.js'
const ProjectLocator = require('../Project/ProjectLocator') import ProjectLocator from '../Project/ProjectLocator.js'
const ProjectEntityHandler = require('../Project/ProjectEntityHandler') import ProjectEntityHandler from '../Project/ProjectEntityHandler.js'
const ProjectEntityUpdateHandler = require('../Project/ProjectEntityUpdateHandler') import ProjectEntityUpdateHandler from '../Project/ProjectEntityUpdateHandler.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const _ = require('lodash') import _ from 'lodash'
const { plainTextResponse } = require('../../infrastructure/Response') import { plainTextResponse } from '../../infrastructure/Response.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function getDocument(req, res) { async function getDocument(req, res) {
const { Project_id: projectId, doc_id: docId } = req.params const { Project_id: projectId, doc_id: docId } = req.params
@ -89,7 +89,7 @@ async function setDocument(req, res) {
res.json(result) res.json(result)
} }
module.exports = { export default {
getDocument: expressify(getDocument), getDocument: expressify(getDocument),
setDocument: expressify(setDocument), setDocument: expressify(setDocument),
} }

View file

@ -10,15 +10,15 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let ProjectDownloadsController import Metrics from '@overleaf/metrics'
const logger = require('@overleaf/logger') import ProjectGetter from '../Project/ProjectGetter.js'
const Metrics = require('@overleaf/metrics') import ProjectZipStreamManager from './ProjectZipStreamManager.mjs'
const ProjectGetter = require('../Project/ProjectGetter') import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.js'
const ProjectZipStreamManager = require('./ProjectZipStreamManager') import { prepareZipAttachment } from '../../infrastructure/Response.js'
const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
const { prepareZipAttachment } = require('../../infrastructure/Response')
module.exports = ProjectDownloadsController = { let ProjectDownloadsController
export default ProjectDownloadsController = {
downloadProject(req, res, next) { downloadProject(req, res, next) {
const projectId = req.params.Project_id const projectId = req.params.Project_id
Metrics.inc('zip-downloads') Metrics.inc('zip-downloads')

View file

@ -1,12 +1,12 @@
import archiver from 'archiver'
import async from 'async'
import logger from '@overleaf/logger'
import ProjectEntityHandler from '../Project/ProjectEntityHandler.js'
import ProjectGetter from '../Project/ProjectGetter.js'
import FileStoreHandler from '../FileStore/FileStoreHandler.js'
let ProjectZipStreamManager let ProjectZipStreamManager
const archiver = require('archiver')
const async = require('async')
const logger = require('@overleaf/logger')
const ProjectEntityHandler = require('../Project/ProjectEntityHandler')
const ProjectGetter = require('../Project/ProjectGetter')
const FileStoreHandler = require('../FileStore/FileStoreHandler')
module.exports = ProjectZipStreamManager = { export default ProjectZipStreamManager = {
createZipStreamForMultipleProjects(projectIds, callback) { createZipStreamForMultipleProjects(projectIds, callback) {
// We'll build up a zip file that contains multiple zip files // We'll build up a zip file that contains multiple zip files
const archive = archiver('zip') const archive = archiver('zip')

View file

@ -1,9 +1,9 @@
const EditorHttpController = require('./EditorHttpController') import EditorHttpController from './EditorHttpController.js'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware') import AuthorizationMiddleware from '../Authorization/AuthorizationMiddleware.js'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const { validate, Joi } = require('../../infrastructure/Validation') import { validate, Joi } from '../../infrastructure/Validation.js'
const rateLimiters = { const rateLimiters = {
addDocToProject: new RateLimiter('add-doc-to-project', { addDocToProject: new RateLimiter('add-doc-to-project', {
@ -17,7 +17,7 @@ const rateLimiters = {
joinProject: new RateLimiter('join-project', { points: 45, duration: 60 }), joinProject: new RateLimiter('join-project', { points: 45, duration: 60 }),
} }
module.exports = { export default {
apply(webRouter, privateApiRouter) { apply(webRouter, privateApiRouter) {
webRouter.post( webRouter.post(
'/project/:Project_id/doc', '/project/:Project_id/doc',

View file

@ -9,11 +9,12 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const ExportsHandler = require('./ExportsHandler') import ExportsHandler from './ExportsHandler.mjs'
const SessionManager = require('../Authentication/SessionManager')
const logger = require('@overleaf/logger')
module.exports = { import SessionManager from '../Authentication/SessionManager.js'
import logger from '@overleaf/logger'
export default {
exportProject(req, res, next) { exportProject(req, res, next) {
const { project_id: projectId, brand_variation_id: brandVariationId } = const { project_id: projectId, brand_variation_id: brandVariationId } =
req.params req.params

View file

@ -11,21 +11,20 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
import OError from '@overleaf/o-error'
import ProjectGetter from '../Project/ProjectGetter.js'
import ProjectHistoryHandler from '../Project/ProjectHistoryHandler.js'
import ProjectLocator from '../Project/ProjectLocator.js'
import ProjectRootDocManager from '../Project/ProjectRootDocManager.js'
import UserGetter from '../User/UserGetter.js'
import logger from '@overleaf/logger'
import settings from '@overleaf/settings'
import async from 'async'
import Request from 'request'
let ExportsHandler let ExportsHandler
const OError = require('@overleaf/o-error') const request = Request.defaults()
const ProjectGetter = require('../Project/ProjectGetter')
const ProjectHistoryHandler = require('../Project/ProjectHistoryHandler')
const ProjectLocator = require('../Project/ProjectLocator')
const ProjectRootDocManager = require('../Project/ProjectRootDocManager')
const UserGetter = require('../User/UserGetter')
const logger = require('@overleaf/logger')
let settings = require('@overleaf/settings')
const async = require('async')
let request = require('request')
request = request.defaults()
settings = require('@overleaf/settings')
module.exports = ExportsHandler = { export default ExportsHandler = {
exportProject(exportParams, callback) { exportProject(exportParams, callback) {
if (callback == null) { if (callback == null) {
callback = function () {} callback = function () {}

View file

@ -1,11 +1,10 @@
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
import FileStoreHandler from './FileStoreHandler.js'
import ProjectLocator from '../Project/ProjectLocator.js'
import Errors from '../Errors/Errors.js'
import { preparePlainTextResponse } from '../../infrastructure/Response.js'
const FileStoreHandler = require('./FileStoreHandler') export default {
const ProjectLocator = require('../Project/ProjectLocator')
const Errors = require('../Errors/Errors')
const { preparePlainTextResponse } = require('../../infrastructure/Response')
module.exports = {
getFile(req, res) { getFile(req, res) {
const projectId = req.params.Project_id const projectId = req.params.Project_id
const fileId = req.params.File_id const fileId = req.params.File_id

View file

@ -1,14 +1,15 @@
const RedisWrapper = require('../../infrastructure/RedisWrapper') import RedisWrapper from '../../infrastructure/RedisWrapper.js'
const rclient = RedisWrapper.client('health_check') import settings from '@overleaf/settings'
const settings = require('@overleaf/settings') import logger from '@overleaf/logger'
const logger = require('@overleaf/logger') import UserGetter from '../User/UserGetter.js'
const UserGetter = require('../User/UserGetter') import {
const {
SmokeTestFailure, SmokeTestFailure,
runSmokeTests, runSmokeTests,
} = require('./../../../../test/smoke/src/SmokeTests') } from './../../../../test/smoke/src/SmokeTests.js'
module.exports = { const rclient = RedisWrapper.client('health_check')
export default {
check(req, res, next) { check(req, res, next) {
if (!settings.siteIsOpen || !settings.editorIsOpen) { if (!settings.siteIsOpen || !settings.editorIsOpen) {
// always return successful health checks when site is closed // always return successful health checks when site is closed

View file

@ -1,17 +1,15 @@
// @ts-check // @ts-check
const { callbackify } = require('util') import { callbackify } from 'util'
const { ObjectId } = require('mongodb-legacy') import OError from '@overleaf/o-error'
const OError = require('@overleaf/o-error') import logger from '@overleaf/logger'
const logger = require('@overleaf/logger') import HistoryManager from '../History/HistoryManager.js'
const HistoryManager = require('../History/HistoryManager') import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.js'
const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler') import DocstoreManager from '../Docstore/DocstoreManager.js'
const DocstoreManager = require('../Docstore/DocstoreManager') import ProjectOptionsHandler from '../Project/ProjectOptionsHandler.js'
const ProjectOptionsHandler = require('../Project/ProjectOptionsHandler') import mongodb from '../../infrastructure/mongodb.js'
const {
db, const { db, ObjectId, READ_PREFERENCE_SECONDARY } = mongodb
READ_PREFERENCE_SECONDARY,
} = require('../../infrastructure/mongodb')
/** /**
* Migrate projects based on a query. * Migrate projects based on a query.
@ -267,7 +265,7 @@ async function hardResyncProject(projectId) {
await HistoryManager.promises.resyncProject(projectId, { force: true }) await HistoryManager.promises.resyncProject(projectId, { force: true })
} }
module.exports = { export default {
migrateProjects: callbackify(migrateProjects), migrateProjects: callbackify(migrateProjects),
migrateProject: callbackify(migrateProject), migrateProject: callbackify(migrateProject),
promises: { migrateProjects, migrateProject }, promises: { migrateProjects, migrateProject },

View file

@ -9,9 +9,9 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const InactiveProjectManager = require('./InactiveProjectManager') import InactiveProjectManager from './InactiveProjectManager.js'
module.exports = { export default {
deactivateOldProjects(req, res) { deactivateOldProjects(req, res) {
const numberOfProjectsToArchive = parseInt( const numberOfProjectsToArchive = parseInt(
req.body.numberOfProjectsToArchive, req.body.numberOfProjectsToArchive,

View file

@ -10,14 +10,12 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let LinkedFilesController import SessionManager from '../Authentication/SessionManager.js'
const SessionManager = require('../Authentication/SessionManager') import Settings from '@overleaf/settings'
const Settings = require('@overleaf/settings') import _ from 'lodash'
const _ = require('lodash') import AnalyticsManager from '../../../../app/src/Features/Analytics/AnalyticsManager.js'
const AnalyticsManager = require('../../../../app/src/Features/Analytics/AnalyticsManager') import LinkedFilesHandler from './LinkedFilesHandler.js'
const LinkedFilesHandler = require('./LinkedFilesHandler') import {
const {
CompileFailedError, CompileFailedError,
UrlFetchFailedError, UrlFetchFailedError,
InvalidUrlError, InvalidUrlError,
@ -31,20 +29,22 @@ const {
FeatureNotAvailableError, FeatureNotAvailableError,
RemoteServiceError, RemoteServiceError,
FileCannotRefreshError, FileCannotRefreshError,
} = require('./LinkedFilesErrors') } from './LinkedFilesErrors.js'
const { import {
OutputFileFetchFailedError, OutputFileFetchFailedError,
FileTooLargeError, FileTooLargeError,
OError, OError,
} = require('../Errors/Errors') } from '../Errors/Errors.js'
const Modules = require('../../infrastructure/Modules') import Modules from '../../infrastructure/Modules.js'
const { plainTextResponse } = require('../../infrastructure/Response') import { plainTextResponse } from '../../infrastructure/Response.js'
const ReferencesHandler = require('../References/ReferencesHandler') import ReferencesHandler from '../References/ReferencesHandler.mjs'
const EditorRealTimeController = require('../Editor/EditorRealTimeController') import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const ProjectOutputFileAgent = require('./ProjectOutputFileAgent') import ProjectOutputFileAgent from './ProjectOutputFileAgent.mjs'
const ProjectFileAgent = require('./ProjectFileAgent') import ProjectFileAgent from './ProjectFileAgent.js'
const UrlAgent = require('./UrlAgent') import UrlAgent from './UrlAgent.mjs'
let LinkedFilesController
async function createLinkedFile(req, res, next) { async function createLinkedFile(req, res, next) {
const { project_id: projectId } = req.params const { project_id: projectId } = req.params
@ -146,7 +146,7 @@ async function refreshLinkedFile(req, res, next) {
} }
} }
module.exports = LinkedFilesController = { export default LinkedFilesController = {
Agents: null, Agents: null,
async _cacheAgents() { async _cacheAgents() {

View file

@ -1,9 +1,9 @@
const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware') import AuthorizationMiddleware from '../Authorization/AuthorizationMiddleware.js'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const LinkedFilesController = require('./LinkedFilesController') import LinkedFilesController from './LinkedFilesController.mjs'
const { validate, Joi } = require('../../infrastructure/Validation') import { validate, Joi } from '../../infrastructure/Validation.js'
const rateLimiters = { const rateLimiters = {
createLinkedFile: new RateLimiter('create-linked-file', { createLinkedFile: new RateLimiter('create-linked-file', {
@ -16,7 +16,7 @@ const rateLimiters = {
}), }),
} }
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
webRouter.post( webRouter.post(
'/project/:project_id/linked_file', '/project/:project_id/linked_file',

View file

@ -1,16 +1,16 @@
const AuthorizationManager = require('../Authorization/AuthorizationManager') import AuthorizationManager from '../Authorization/AuthorizationManager.js'
const CompileManager = require('../Compile/CompileManager') import CompileManager from '../Compile/CompileManager.js'
const ClsiManager = require('../Compile/ClsiManager') import ClsiManager from '../Compile/ClsiManager.js'
const ProjectFileAgent = require('./ProjectFileAgent') import ProjectFileAgent from './ProjectFileAgent.js'
const _ = require('lodash') import _ from 'lodash'
const { import {
CompileFailedError, CompileFailedError,
BadDataError, BadDataError,
AccessDeniedError, AccessDeniedError,
} = require('./LinkedFilesErrors') } from './LinkedFilesErrors.js'
const { OutputFileFetchFailedError } = require('../Errors/Errors') import { OutputFileFetchFailedError } from '../Errors/Errors.js'
const LinkedFilesHandler = require('./LinkedFilesHandler') import LinkedFilesHandler from './LinkedFilesHandler.js'
const { promisify } = require('@overleaf/promise-utils') import { promisify } from '@overleaf/promise-utils'
function _prepare(projectId, linkedFileData, userId, callback) { function _prepare(projectId, linkedFileData, userId, callback) {
_checkAuth(projectId, linkedFileData, userId, (err, allowed) => { _checkAuth(projectId, linkedFileData, userId, (err, allowed) => {
@ -226,7 +226,7 @@ function _compileAndGetFileStream(linkedFileData, userId, callback) {
}) })
} }
module.exports = { export default {
createLinkedFile, createLinkedFile,
refreshLinkedFile, refreshLinkedFile,
promises: { promises: {

View file

@ -1,11 +1,11 @@
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const urlValidator = require('valid-url') import urlValidator from 'valid-url'
const { InvalidUrlError, UrlFetchFailedError } = require('./LinkedFilesErrors') import { InvalidUrlError, UrlFetchFailedError } from './LinkedFilesErrors.js'
const LinkedFilesHandler = require('./LinkedFilesHandler') import LinkedFilesHandler from './LinkedFilesHandler.js'
const UrlHelper = require('../Helpers/UrlHelper') import UrlHelper from '../Helpers/UrlHelper.js'
const { fetchStream, RequestFailedError } = require('@overleaf/fetch-utils') import { fetchStream, RequestFailedError } from '@overleaf/fetch-utils'
const { callbackify } = require('@overleaf/promise-utils') import { callbackify } from '@overleaf/promise-utils'
const { FileTooLargeError } = require('../Errors/Errors') import { FileTooLargeError } from '../Errors/Errors.js'
async function createLinkedFile( async function createLinkedFile(
projectId, projectId,
@ -76,7 +76,7 @@ function _getUrl(projectId, data, currentUserId) {
return url return url
} }
module.exports = { export default {
createLinkedFile: callbackify(createLinkedFile), createLinkedFile: callbackify(createLinkedFile),
refreshLinkedFile: callbackify(refreshLinkedFile), refreshLinkedFile: callbackify(refreshLinkedFile),
promises: { createLinkedFile, refreshLinkedFile }, promises: { createLinkedFile, refreshLinkedFile },

View file

@ -1,8 +1,8 @@
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const EditorRealTimeController = require('../Editor/EditorRealTimeController') import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
const MetaHandler = require('./MetaHandler') import MetaHandler from './MetaHandler.mjs'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function getMetadata(req, res) { async function getMetadata(req, res) {
const { project_id: projectId } = req.params const { project_id: projectId } = req.params
@ -55,7 +55,7 @@ async function broadcastMetadataForDoc(req, res) {
res.sendStatus(200) // 204? res.sendStatus(200) // 204?
} }
module.exports = { export default {
getMetadata: expressify(getMetadata), getMetadata: expressify(getMetadata),
broadcastMetadataForDoc: expressify(broadcastMetadataForDoc), broadcastMetadataForDoc: expressify(broadcastMetadataForDoc),
} }

View file

@ -1,7 +1,7 @@
const ProjectEntityHandler = require('../Project/ProjectEntityHandler') import ProjectEntityHandler from '../Project/ProjectEntityHandler.js'
const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler') import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.js'
const packageMapping = require('./packageMapping') import packageMapping from './packageMapping.mjs'
const { callbackify } = require('@overleaf/promise-utils') import { callbackify } from '@overleaf/promise-utils'
/** @typedef {{ /** @typedef {{
* labels: string[] * labels: string[]
@ -117,7 +117,7 @@ async function getMetaForDoc(projectId, docId) {
return await extractMetaFromDoc(lines) return await extractMetaFromDoc(lines)
} }
module.exports = { export default {
promises: { promises: {
getAllMetaForProject, getAllMetaForProject,
getMetaForDoc, getMetaForDoc,

View file

@ -1,4 +1,4 @@
module.exports = { export default {
inputenc: [ inputenc: [
{ {
caption: '\\inputencoding{}', caption: '\\inputencoding{}',

View file

@ -1,8 +1,8 @@
const NotificationsHandler = require('./NotificationsHandler') import NotificationsHandler from './NotificationsHandler.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const _ = require('lodash') import _ from 'lodash'
module.exports = { export default {
getAllUnreadNotifications(req, res, next) { getAllUnreadNotifications(req, res, next) {
const userId = SessionManager.getLoggedInUserId(req.session) const userId = SessionManager.getLoggedInUserId(req.session)
NotificationsHandler.getUserNotifications( NotificationsHandler.getUserNotifications(

View file

@ -1,13 +1,13 @@
const PasswordResetHandler = require('./PasswordResetHandler') import PasswordResetHandler from './PasswordResetHandler.mjs'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const AuthenticationManager = require('../Authentication/AuthenticationManager') import AuthenticationManager from '../Authentication/AuthenticationManager.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const UserUpdater = require('../User/UserUpdater') import UserUpdater from '../User/UserUpdater.js'
const UserSessionsManager = require('../User/UserSessionsManager') import UserSessionsManager from '../User/UserSessionsManager.js'
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const EmailsHelper = require('../Helpers/EmailHelper') import EmailsHelper from '../Helpers/EmailHelper.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function setNewUserPassword(req, res, next) { async function setNewUserPassword(req, res, next) {
let user let user
@ -189,7 +189,7 @@ async function renderSetPasswordForm(req, res, next) {
}) })
} }
module.exports = { export default {
renderRequestResetForm(req, res) { renderRequestResetForm(req, res) {
const errorQuery = req.query.error const errorQuery = req.query.error
let error = null let error = null

View file

@ -1,12 +1,13 @@
const settings = require('@overleaf/settings') import settings from '@overleaf/settings'
const UserAuditLogHandler = require('../User/UserAuditLogHandler') import UserAuditLogHandler from '../User/UserAuditLogHandler.js'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const OneTimeTokenHandler = require('../Security/OneTimeTokenHandler') import OneTimeTokenHandler from '../Security/OneTimeTokenHandler.js'
const EmailHandler = require('../Email/EmailHandler') import EmailHandler from '../Email/EmailHandler.js'
const AuthenticationManager = require('../Authentication/AuthenticationManager') import AuthenticationManager from '../Authentication/AuthenticationManager.js'
const { callbackify, promisify } = require('util') import { callbackify, promisify } from 'util'
const { assertUserPermissions } = import PermissionsManager from '../Authorization/PermissionsManager.js'
require('../Authorization/PermissionsManager').promises
const assertUserPermissions = PermissionsManager.promises.assertUserPermissions
const AUDIT_LOG_TOKEN_PREFIX_LENGTH = 10 const AUDIT_LOG_TOKEN_PREFIX_LENGTH = 10
@ -138,4 +139,4 @@ PasswordResetHandler.promises = {
setNewUserPassword, setNewUserPassword,
} }
module.exports = PasswordResetHandler export default PasswordResetHandler

View file

@ -1,16 +1,16 @@
const PasswordResetController = require('./PasswordResetController') import PasswordResetController from './PasswordResetController.mjs'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const CaptchaMiddleware = require('../../Features/Captcha/CaptchaMiddleware') import CaptchaMiddleware from '../../Features/Captcha/CaptchaMiddleware.js'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const { Joi, validate } = require('../../infrastructure/Validation') import { Joi, validate } from '../../infrastructure/Validation.js'
const rateLimiter = new RateLimiter('password_reset_rate_limit', { const rateLimiter = new RateLimiter('password_reset_rate_limit', {
points: 6, points: 6,
duration: 60, duration: 60,
}) })
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
const rateLimit = RateLimiterMiddleware.rateLimit(rateLimiter, { const rateLimit = RateLimiterMiddleware.rateLimit(rateLimiter, {
ipOnly: true, ipOnly: true,

View file

@ -1,8 +1,8 @@
// TODO: This file was created by bulk-decaffeinate. // TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment. // Sanity-check the conversion and remove this comment.
const _ = require('lodash') import _ from 'lodash'
module.exports = { export default {
areSame(lines1, lines2) { areSame(lines1, lines2) {
if (!Array.isArray(lines1) || !Array.isArray(lines2)) { if (!Array.isArray(lines1) || !Array.isArray(lines2)) {
return false return false

View file

@ -10,10 +10,11 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const ProjectDetailsHandler = require('./ProjectDetailsHandler') import ProjectDetailsHandler from './ProjectDetailsHandler.js'
const logger = require('@overleaf/logger')
module.exports = { import logger from '@overleaf/logger'
export default {
getProjectDetails(req, res, next) { getProjectDetails(req, res, next) {
const { project_id: projectId } = req.params const { project_id: projectId } = req.params
return ProjectDetailsHandler.getDetails( return ProjectDetailsHandler.getDetails(

View file

@ -1,32 +1,33 @@
// ts-check // ts-check
const _ = require('lodash') import _ from 'lodash'
const Metrics = require('@overleaf/metrics')
const Settings = require('@overleaf/settings') import Metrics from '@overleaf/metrics'
const ProjectHelper = require('./ProjectHelper') import Settings from '@overleaf/settings'
const ProjectGetter = require('./ProjectGetter') import ProjectHelper from './ProjectHelper.js'
const PrivilegeLevels = require('../Authorization/PrivilegeLevels') import ProjectGetter from './ProjectGetter.js'
const SessionManager = require('../Authentication/SessionManager') import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
const Sources = require('../Authorization/Sources') import SessionManager from '../Authentication/SessionManager.js'
const UserGetter = require('../User/UserGetter') import Sources from '../Authorization/Sources.js'
const SurveyHandler = require('../Survey/SurveyHandler') import UserGetter from '../User/UserGetter.js'
const TagsHandler = require('../Tags/TagsHandler') import SurveyHandler from '../Survey/SurveyHandler.mjs'
const { expressify } = require('@overleaf/promise-utils') import TagsHandler from '../Tags/TagsHandler.js'
const logger = require('@overleaf/logger') import { expressify } from '@overleaf/promise-utils'
const Features = require('../../infrastructure/Features') import logger from '@overleaf/logger'
const SubscriptionViewModelBuilder = require('../Subscription/SubscriptionViewModelBuilder') import Features from '../../infrastructure/Features.js'
const NotificationsHandler = require('../Notifications/NotificationsHandler') import SubscriptionViewModelBuilder from '../Subscription/SubscriptionViewModelBuilder.js'
const Modules = require('../../infrastructure/Modules') import NotificationsHandler from '../Notifications/NotificationsHandler.js'
const { OError, V1ConnectionError } = require('../Errors/Errors') import Modules from '../../infrastructure/Modules.js'
const { User } = require('../../models/User') import { OError, V1ConnectionError } from '../Errors/Errors.js'
const UserPrimaryEmailCheckHandler = require('../User/UserPrimaryEmailCheckHandler') import { User } from '../../models/User.js'
const UserController = require('../User/UserController') import UserPrimaryEmailCheckHandler from '../User/UserPrimaryEmailCheckHandler.js'
const LimitationsManager = require('../Subscription/LimitationsManager') import UserController from '../User/UserController.js'
const NotificationsBuilder = require('../Notifications/NotificationsBuilder') import LimitationsManager from '../Subscription/LimitationsManager.js'
const GeoIpLookup = require('../../infrastructure/GeoIpLookup') import NotificationsBuilder from '../Notifications/NotificationsBuilder.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import GeoIpLookup from '../../infrastructure/GeoIpLookup.js'
const SplitTestSessionHandler = require('../SplitTests/SplitTestSessionHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const SubscriptionLocator = require('../Subscription/SubscriptionLocator') import SplitTestSessionHandler from '../SplitTests/SplitTestSessionHandler.js'
const TutorialHandler = require('../Tutorial/TutorialHandler') import SubscriptionLocator from '../Subscription/SubscriptionLocator.js'
import TutorialHandler from '../Tutorial/TutorialHandler.js'
/** /**
* @import { GetProjectsRequest, GetProjectsResponse, AllUsersProjects, MongoProject } from "./types" * @import { GetProjectsRequest, GetProjectsResponse, AllUsersProjects, MongoProject } from "./types"
@ -763,7 +764,7 @@ function _hasActiveFilter(filters) {
) )
} }
module.exports = { export default {
projectListPage: expressify(projectListPage), projectListPage: expressify(projectListPage),
getProjectsJson: expressify(getProjectsJson), getProjectsJson: expressify(getProjectsJson),
} }

View file

@ -1,4 +1,4 @@
module.exports = { export default {
use(req, res, next) { use(req, res, next) {
if (req.query != null) { if (req.query != null) {
if (req.query.referal != null) { if (req.query.referal != null) {

View file

@ -1,7 +1,7 @@
const ReferalHandler = require('./ReferalHandler') import ReferalHandler from './ReferalHandler.mjs'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
module.exports = { export default {
bonus(req, res, next) { bonus(req, res, next) {
const userId = SessionManager.getLoggedInUserId(req.session) const userId = SessionManager.getLoggedInUserId(req.session)
ReferalHandler.getReferedUsers(userId, (err, { referedUserCount }) => { ReferalHandler.getReferedUsers(userId, (err, { referedUserCount }) => {

View file

@ -1,5 +1,5 @@
const { callbackify } = require('@overleaf/promise-utils') import { callbackify } from '@overleaf/promise-utils'
const { User } = require('../../models/User') import { User } from '../../models/User.js'
async function getReferedUsers(userId) { async function getReferedUsers(userId) {
const projection = { refered_users: 1, refered_user_count: 1 } const projection = { refered_users: 1, refered_user_count: 1 }
@ -9,7 +9,7 @@ async function getReferedUsers(userId) {
return { referedUsers, referedUserCount } return { referedUsers, referedUserCount }
} }
module.exports = { export default {
getReferedUsers: callbackify(getReferedUsers), getReferedUsers: callbackify(getReferedUsers),
promises: { promises: {
getReferedUsers, getReferedUsers,

View file

@ -10,14 +10,13 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let ReferencesController import ReferencesHandler from './ReferencesHandler.mjs'
const logger = require('@overleaf/logger') import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
const ReferencesHandler = require('./ReferencesHandler') import { OError } from '../Errors/Errors.js'
const settings = require('@overleaf/settings')
const EditorRealTimeController = require('../Editor/EditorRealTimeController')
const { OError } = require('../Errors/Errors')
module.exports = ReferencesController = { let ReferencesController
export default ReferencesController = {
indexAll(req, res, next) { indexAll(req, res, next) {
const projectId = req.params.Project_id const projectId = req.params.Project_id
const { shouldBroadcast } = req.body const { shouldBroadcast } = req.body

View file

@ -12,25 +12,26 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
import OError from '@overleaf/o-error'
import logger from '@overleaf/logger'
import request from 'request'
import settings from '@overleaf/settings'
import Features from '../../infrastructure/Features.js'
import ProjectGetter from '../Project/ProjectGetter.js'
import UserGetter from '../User/UserGetter.js'
import DocumentUpdaterHandler from '../DocumentUpdater/DocumentUpdaterHandler.js'
import _ from 'lodash'
import Async from 'async'
import Errors from '../Errors/Errors.js'
import { promisify } from '@overleaf/promise-utils'
let ReferencesHandler let ReferencesHandler
const OError = require('@overleaf/o-error')
const logger = require('@overleaf/logger')
const request = require('request')
const settings = require('@overleaf/settings')
const Features = require('../../infrastructure/Features')
const ProjectGetter = require('../Project/ProjectGetter')
const UserGetter = require('../User/UserGetter')
const DocumentUpdaterHandler = require('../DocumentUpdater/DocumentUpdaterHandler')
const _ = require('lodash')
const Async = require('async')
const Errors = require('../Errors/Errors')
const { promisify } = require('@overleaf/promise-utils')
if (!Features.hasFeature('references')) { if (!Features.hasFeature('references')) {
logger.debug('references search not enabled') logger.debug('references search not enabled')
} }
module.exports = ReferencesHandler = { export default ReferencesHandler = {
_buildDocUrl(projectId, docId) { _buildDocUrl(projectId, docId) {
return `${settings.apis.docstore.url}/project/${projectId}/doc/${docId}/raw` return `${settings.apis.docstore.url}/project/${projectId}/doc/${docId}/raw`
}, },

View file

@ -1,15 +1,15 @@
const request = require('request') import request from 'request'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const LearnedWordsManager = require('./LearnedWordsManager') import LearnedWordsManager from './LearnedWordsManager.js'
const TEN_SECONDS = 1000 * 10 const TEN_SECONDS = 1000 * 10
const languageCodeIsSupported = code => const languageCodeIsSupported = code =>
Settings.languages.some(lang => lang.code === code && lang.server !== false) Settings.languages.some(lang => lang.code === code && lang.server !== false)
module.exports = { export default {
learn(req, res, next) { learn(req, res, next) {
const { word } = req.body const { word } = req.body
const userId = SessionManager.getLoggedInUserId(req.session) const userId = SessionManager.getLoggedInUserId(req.session)

View file

@ -1,15 +1,14 @@
const Features = require('../../infrastructure/Features') import Features from '../../infrastructure/Features.js'
const AnalyticsManager = require('../Analytics/AnalyticsManager') import AnalyticsManager from '../Analytics/AnalyticsManager.js'
import Path from 'path'
import fs from 'fs'
import ErrorController from '../Errors/ErrorController.js'
import SessionManager from '../Authentication/SessionManager.js'
import { expressify } from '@overleaf/promise-utils'
import logger from '@overleaf/logger'
import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const Path = require('path') const __dirname = new URL('.', import.meta.url).pathname
const fs = require('fs')
const ErrorController = require('../Errors/ErrorController')
const SessionManager = require('../Authentication/SessionManager')
const { expressify } = require('@overleaf/promise-utils')
const logger = require('@overleaf/logger')
const SplitTestHandler = require('../SplitTests/SplitTestHandler')
const homepageExists = fs.existsSync( const homepageExists = fs.existsSync(
Path.join( Path.join(
@ -67,7 +66,7 @@ function externalPage(page, title) {
return expressify(middleware) return expressify(middleware)
} }
module.exports = { export default {
index: expressify(index), index: expressify(index),
home: expressify(home), home: expressify(home),
externalPage, externalPage,

View file

@ -8,6 +8,8 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
import _ from 'lodash'
const extensionsToProxy = [ const extensionsToProxy = [
'.png', '.png',
'.xml', '.xml',
@ -18,9 +20,8 @@ const extensionsToProxy = [
'.gif', '.gif',
'.jpg', '.jpg',
] ]
const _ = require('lodash')
module.exports = { export default {
shouldProxy(url) { shouldProxy(url) {
const shouldProxy = _.find( const shouldProxy = _.find(
extensionsToProxy, extensionsToProxy,

View file

@ -8,10 +8,11 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
const HomeController = require('./HomeController') import HomeController from './HomeController.mjs'
const UniversityController = require('./UniversityController')
module.exports = { import UniversityController from './UniversityController.mjs'
export default {
apply(webRouter) { apply(webRouter) {
webRouter.get('/', HomeController.index) webRouter.get('/', HomeController.index)
webRouter.get('/home', HomeController.home) webRouter.get('/home', HomeController.home)

View file

@ -10,11 +10,8 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let UniversityController let UniversityController
const settings = require('@overleaf/settings')
const logger = require('@overleaf/logger')
const Settings = require('@overleaf/settings')
module.exports = UniversityController = { export default UniversityController = {
getPage(req, res, next) { getPage(req, res, next) {
const url = const url =
req.url != null ? req.url.toLowerCase().replace('.html', '') : undefined req.url != null ? req.url.toLowerCase().replace('.html', '') : undefined

View file

@ -1,12 +1,13 @@
// ts-check // ts-check
const SubscriptionGroupHandler = require('./SubscriptionGroupHandler') import SubscriptionGroupHandler from './SubscriptionGroupHandler.js'
const OError = require('@overleaf/o-error')
const logger = require('@overleaf/logger') import OError from '@overleaf/o-error'
const SubscriptionLocator = require('./SubscriptionLocator') import logger from '@overleaf/logger'
const SessionManager = require('../Authentication/SessionManager') import SubscriptionLocator from './SubscriptionLocator.js'
const UserAuditLogHandler = require('../User/UserAuditLogHandler') import SessionManager from '../Authentication/SessionManager.js'
const { expressify } = require('@overleaf/promise-utils') import UserAuditLogHandler from '../User/UserAuditLogHandler.js'
const Modules = require('../../infrastructure/Modules') import { expressify } from '@overleaf/promise-utils'
import Modules from '../../infrastructure/Modules.js'
/** /**
* @import { Subscription } from "../../../../types/subscription/dashboard/subscription" * @import { Subscription } from "../../../../types/subscription/dashboard/subscription"
@ -110,7 +111,7 @@ async function _removeUserFromGroup(
res.sendStatus(200) res.sendStatus(200)
} }
module.exports = { export default {
removeUserFromGroup: expressify(removeUserFromGroup), removeUserFromGroup: expressify(removeUserFromGroup),
removeSelfFromGroup: expressify(removeSelfFromGroup), removeSelfFromGroup: expressify(removeSelfFromGroup),
} }

View file

@ -1,12 +1,12 @@
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const PermissionsController = require('../Authorization/PermissionsController') import PermissionsController from '../Authorization/PermissionsController.js'
const SubscriptionController = require('./SubscriptionController') import SubscriptionController from './SubscriptionController.js'
const SubscriptionGroupController = require('./SubscriptionGroupController') import SubscriptionGroupController from './SubscriptionGroupController.mjs'
const TeamInvitesController = require('./TeamInvitesController') import TeamInvitesController from './TeamInvitesController.mjs'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const { Joi, validate } = require('../../infrastructure/Validation') import { Joi, validate } from '../../infrastructure/Validation.js'
const teamInviteRateLimiter = new RateLimiter('team-invite', { const teamInviteRateLimiter = new RateLimiter('team-invite', {
points: 10, points: 10,
@ -18,7 +18,7 @@ const subscriptionRateLimiter = new RateLimiter('subscription', {
duration: 60, duration: 60,
}) })
module.exports = { export default {
apply(webRouter, privateApiRouter, publicApiRouter) { apply(webRouter, privateApiRouter, publicApiRouter) {
if (!Settings.enableSubscriptions) { if (!Settings.enableSubscriptions) {
return return

View file

@ -1,20 +1,20 @@
const settings = require('@overleaf/settings') import settings from '@overleaf/settings'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const TeamInvitesHandler = require('./TeamInvitesHandler') import TeamInvitesHandler from './TeamInvitesHandler.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const SubscriptionLocator = require('./SubscriptionLocator') import SubscriptionLocator from './SubscriptionLocator.js'
const ErrorController = require('../Errors/ErrorController') import ErrorController from '../Errors/ErrorController.js'
const EmailHelper = require('../Helpers/EmailHelper') import EmailHelper from '../Helpers/EmailHelper.js'
const UserGetter = require('../User/UserGetter') import UserGetter from '../User/UserGetter.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const HttpErrorHandler = require('../Errors/HttpErrorHandler') import HttpErrorHandler from '../Errors/HttpErrorHandler.js'
const PermissionsManager = require('../Authorization/PermissionsManager') import PermissionsManager from '../Authorization/PermissionsManager.js'
const EmailHandler = require('../Email/EmailHandler') import EmailHandler from '../Email/EmailHandler.js'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const Modules = require('../../infrastructure/Modules') import Modules from '../../infrastructure/Modules.js'
const UserAuditLogHandler = require('../User/UserAuditLogHandler') import UserAuditLogHandler from '../User/UserAuditLogHandler.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const rateLimiters = { const rateLimiters = {
resendGroupInvite: new RateLimiter('resend-group-invite', { resendGroupInvite: new RateLimiter('resend-group-invite', {
@ -306,7 +306,7 @@ async function resendInvite(req, res, next) {
return res.status(200).json({ success: true }) return res.status(200).json({ success: true })
} }
module.exports = { export default {
createInvite: expressify(createInvite), createInvite: expressify(createInvite),
viewInvite: expressify(viewInvite), viewInvite: expressify(viewInvite),
viewInvites: expressify(viewInvites), viewInvites: expressify(viewInvites),

View file

@ -1,6 +1,6 @@
const SurveyManager = require('./SurveyManager') import SurveyManager from './SurveyManager.js'
const { Survey } = require('../../models/Survey') import { Survey } from '../../models/Survey.js'
const { CacheLoader } = require('cache-flow') import { CacheLoader } from 'cache-flow'
class SurveyCache extends CacheLoader { class SurveyCache extends CacheLoader {
constructor() { constructor() {
@ -22,4 +22,4 @@ class SurveyCache extends CacheLoader {
} }
} }
module.exports = new SurveyCache() export default new SurveyCache()

View file

@ -1,8 +1,9 @@
// ts-check // ts-check
const crypto = require('crypto') import crypto from 'crypto'
const SurveyCache = require('./SurveyCache')
const SubscriptionLocator = require('../Subscription/SubscriptionLocator') import SurveyCache from './SurveyCache.mjs'
const { callbackify } = require('@overleaf/promise-utils') import SubscriptionLocator from '../Subscription/SubscriptionLocator.js'
import { callbackify } from '@overleaf/promise-utils'
/** /**
* @import { Survey } from '../../../../types/project/dashboard/survey' * @import { Survey } from '../../../../types/project/dashboard/survey'
@ -55,7 +56,7 @@ function _userInRolloutPercentile(userId, surveyName, rolloutPercentage) {
return userPercentile < rolloutPercentage return userPercentile < rolloutPercentage
} }
module.exports = { export default {
getSurvey: callbackify(getSurvey), getSurvey: callbackify(getSurvey),
promises: { promises: {
getSurvey, getSurvey,

View file

@ -1,7 +1,7 @@
const TagsHandler = require('./TagsHandler') import TagsHandler from './TagsHandler.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function _getTags(userId, _req, res) { async function _getTags(userId, _req, res) {
if (!userId) { if (!userId) {
@ -88,7 +88,7 @@ async function editTag(req, res) {
res.status(204).end() res.status(204).end()
} }
module.exports = { export default {
apiGetAllTags: expressify(apiGetAllTags), apiGetAllTags: expressify(apiGetAllTags),
getAllTags: expressify(getAllTags), getAllTags: expressify(getAllTags),
createTag: expressify(createTag), createTag: expressify(createTag),

View file

@ -1,16 +1,16 @@
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const TpdsUpdateHandler = require('./TpdsUpdateHandler') import TpdsUpdateHandler from './TpdsUpdateHandler.mjs'
const UpdateMerger = require('./UpdateMerger') import UpdateMerger from './UpdateMerger.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const Path = require('path') import Path from 'path'
const metrics = require('@overleaf/metrics') import metrics from '@overleaf/metrics'
const NotificationsBuilder = require('../Notifications/NotificationsBuilder') import NotificationsBuilder from '../Notifications/NotificationsBuilder.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const ProjectCreationHandler = require('../Project/ProjectCreationHandler') import ProjectCreationHandler from '../Project/ProjectCreationHandler.js'
const ProjectDetailsHandler = require('../Project/ProjectDetailsHandler') import ProjectDetailsHandler from '../Project/ProjectDetailsHandler.js'
const HttpErrorHandler = require('../Errors/HttpErrorHandler') import HttpErrorHandler from '../Errors/HttpErrorHandler.js'
const TpdsQueueManager = require('./TpdsQueueManager') import TpdsQueueManager from './TpdsQueueManager.mjs'
async function createProject(req, res) { async function createProject(req, res) {
const { user_id: userId } = req.params const { user_id: userId } = req.params
@ -197,7 +197,7 @@ function splitPath(projectId, path) {
return { filePath, projectName } return { filePath, projectName }
} }
module.exports = { export default {
createProject: expressify(createProject), createProject: expressify(createProject),
mergeUpdate: expressify(mergeUpdate), mergeUpdate: expressify(mergeUpdate),
deleteUpdate: expressify(deleteUpdate), deleteUpdate: expressify(deleteUpdate),

View file

@ -1,6 +1,6 @@
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const { fetchJson } = require('@overleaf/fetch-utils') import { fetchJson } from '@overleaf/fetch-utils'
async function getQueues(userId) { async function getQueues(userId) {
try { try {
@ -10,7 +10,7 @@ async function getQueues(userId) {
} }
} }
module.exports = { export default {
promises: { promises: {
getQueues, getQueues,
}, },

View file

@ -1,16 +1,16 @@
const { callbackify } = require('util') import { callbackify } from 'util'
const UpdateMerger = require('./UpdateMerger') import UpdateMerger from './UpdateMerger.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const NotificationsBuilder = require('../Notifications/NotificationsBuilder') import NotificationsBuilder from '../Notifications/NotificationsBuilder.js'
const ProjectCreationHandler = require('../Project/ProjectCreationHandler') import ProjectCreationHandler from '../Project/ProjectCreationHandler.js'
const ProjectDeleter = require('../Project/ProjectDeleter') import ProjectDeleter from '../Project/ProjectDeleter.js'
const ProjectGetter = require('../Project/ProjectGetter') import ProjectGetter from '../Project/ProjectGetter.js'
const ProjectHelper = require('../Project/ProjectHelper') import ProjectHelper from '../Project/ProjectHelper.js'
const ProjectRootDocManager = require('../Project/ProjectRootDocManager') import ProjectRootDocManager from '../Project/ProjectRootDocManager.js'
const FileTypeManager = require('../Uploads/FileTypeManager') import FileTypeManager from '../Uploads/FileTypeManager.js'
const CooldownManager = require('../Cooldown/CooldownManager') import CooldownManager from '../Cooldown/CooldownManager.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const Modules = require('../../infrastructure/Modules') import Modules from '../../infrastructure/Modules.js'
async function newUpdate( async function newUpdate(
userId, userId,
@ -189,7 +189,7 @@ async function createFolder(userId, projectId, projectName, path) {
} }
} }
module.exports = { export default {
newUpdate: callbackify(newUpdate), newUpdate: callbackify(newUpdate),
deleteUpdate: callbackify(deleteUpdate), deleteUpdate: callbackify(deleteUpdate),
createFolder: callbackify(createFolder), createFolder: callbackify(createFolder),

View file

@ -1,29 +1,26 @@
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const TokenAccessHandler = require('./TokenAccessHandler') import TokenAccessHandler from './TokenAccessHandler.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const settings = require('@overleaf/settings') import OError from '@overleaf/o-error'
const OError = require('@overleaf/o-error') import { expressify } from '@overleaf/promise-utils'
const { expressify } = require('@overleaf/promise-utils') import AuthorizationManager from '../Authorization/AuthorizationManager.js'
const AuthorizationManager = require('../Authorization/AuthorizationManager') import PrivilegeLevels from '../Authorization/PrivilegeLevels.js'
const PrivilegeLevels = require('../Authorization/PrivilegeLevels') import ProjectAuditLogHandler from '../Project/ProjectAuditLogHandler.js'
const ProjectAuditLogHandler = require('../Project/ProjectAuditLogHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import CollaboratorsInviteHandler from '../Collaborators/CollaboratorsInviteHandler.mjs'
const CollaboratorsInviteHandler = require('../Collaborators/CollaboratorsInviteHandler') import CollaboratorsHandler from '../Collaborators/CollaboratorsHandler.js'
const CollaboratorsHandler = require('../Collaborators/CollaboratorsHandler') import EditorRealTimeController from '../Editor/EditorRealTimeController.js'
const EditorRealTimeController = require('../Editor/EditorRealTimeController') import CollaboratorsGetter from '../Collaborators/CollaboratorsGetter.js'
const CollaboratorsGetter = require('../Collaborators/CollaboratorsGetter') import ProjectGetter from '../Project/ProjectGetter.js'
const ProjectGetter = require('../Project/ProjectGetter') import AsyncFormHelper from '../Helpers/AsyncFormHelper.js'
const AsyncFormHelper = require('../Helpers/AsyncFormHelper') import AnalyticsManager from '../Analytics/AnalyticsManager.js'
const AnalyticsManager = require('../Analytics/AnalyticsManager') import { canRedirectToAdminDomain } from '../Helpers/AdminAuthorizationHelper.js'
const { import { getSafeAdminDomainRedirect } from '../Helpers/UrlHelper.js'
canRedirectToAdminDomain, import UserGetter from '../User/UserGetter.js'
} = require('../Helpers/AdminAuthorizationHelper') import Settings from '@overleaf/settings'
const { getSafeAdminDomainRedirect } = require('../Helpers/UrlHelper') import LimitationsManager from '../Subscription/LimitationsManager.js'
const UserGetter = require('../User/UserGetter')
const Settings = require('@overleaf/settings')
const LimitationsManager = require('../Subscription/LimitationsManager')
const orderedPrivilegeLevels = [ const orderedPrivilegeLevels = [
PrivilegeLevels.NONE, PrivilegeLevels.NONE,
@ -167,7 +164,7 @@ async function checkAndGetProjectOrResponseAction(
token token
) )
if (!project) { if (!project) {
if (settings.overleaf) { if (Settings.overleaf) {
const v1ImportData = await _handleV1Project(token, userId) const v1ImportData = await _handleV1Project(token, userId)
return [ return [
null, null,
@ -645,7 +642,7 @@ async function moveReadWriteToReadOnly(req, res, next) {
res.sendStatus(204) res.sendStatus(204)
} }
module.exports = { export default {
READ_ONLY_TOKEN_PATTERN: TokenAccessHandler.READ_ONLY_TOKEN_PATTERN, READ_ONLY_TOKEN_PATTERN: TokenAccessHandler.READ_ONLY_TOKEN_PATTERN,
READ_AND_WRITE_TOKEN_PATTERN: TokenAccessHandler.READ_AND_WRITE_TOKEN_PATTERN, READ_AND_WRITE_TOKEN_PATTERN: TokenAccessHandler.READ_AND_WRITE_TOKEN_PATTERN,

View file

@ -1,8 +1,8 @@
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware') import AuthorizationMiddleware from '../Authorization/AuthorizationMiddleware.js'
const TokenAccessController = require('./TokenAccessController') import TokenAccessController from './TokenAccessController.mjs'
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
webRouter.get( webRouter.get(
`/project/:Project_id/sharing-updates`, `/project/:Project_id/sharing-updates`,

View file

@ -1,6 +1,6 @@
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const TutorialHandler = require('./TutorialHandler') import TutorialHandler from './TutorialHandler.js'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const VALID_KEYS = [ const VALID_KEYS = [
'react-history-buttons-tutorial', 'react-history-buttons-tutorial',
@ -46,7 +46,7 @@ async function postponeTutorial(req, res, next) {
res.sendStatus(204) res.sendStatus(204)
} }
module.exports = { export default {
completeTutorial: expressify(completeTutorial), completeTutorial: expressify(completeTutorial),
postponeTutorial: expressify(postponeTutorial), postponeTutorial: expressify(postponeTutorial),
} }

View file

@ -1,18 +1,20 @@
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const metrics = require('@overleaf/metrics') import metrics from '@overleaf/metrics'
const fs = require('fs') import fs from 'fs'
const Path = require('path') import Path from 'path'
const FileSystemImportManager = require('./FileSystemImportManager') import FileSystemImportManager from './FileSystemImportManager.js'
const ProjectUploadManager = require('./ProjectUploadManager') import ProjectUploadManager from './ProjectUploadManager.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const EditorController = require('../Editor/EditorController') import EditorController from '../Editor/EditorController.js'
const ProjectLocator = require('../Project/ProjectLocator') import ProjectLocator from '../Project/ProjectLocator.js'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const { InvalidZipFileError } = require('./ArchiveErrors') import { InvalidZipFileError } from './ArchiveErrors.js'
const multer = require('multer') import multer from 'multer'
const { defaultsDeep } = require('lodash') import lodash from 'lodash'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const { DuplicateNameError } = require('../Errors/Errors') import { DuplicateNameError } from '../Errors/Errors.js'
const defaultsDeep = lodash.defaultsDeep
const upload = multer( const upload = multer(
defaultsDeep( defaultsDeep(
@ -164,7 +166,7 @@ function multerMiddleware(req, res, next) {
}) })
} }
module.exports = { export default {
uploadProject, uploadProject,
uploadFile: expressify(uploadFile), uploadFile: expressify(uploadFile),
multerMiddleware, multerMiddleware,

View file

@ -1,9 +1,9 @@
const AuthorizationMiddleware = require('../Authorization/AuthorizationMiddleware') import AuthorizationMiddleware from '../Authorization/AuthorizationMiddleware.js'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const ProjectUploadController = require('./ProjectUploadController') import ProjectUploadController from './ProjectUploadController.mjs'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const rateLimiters = { const rateLimiters = {
projectUpload: new RateLimiter('project-upload', { projectUpload: new RateLimiter('project-upload', {
@ -16,7 +16,7 @@ const rateLimiters = {
}), }),
} }
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
webRouter.post( webRouter.post(
'/project/new/upload', '/project/new/upload',

View file

@ -1,17 +1,17 @@
const UserGetter = require('./UserGetter') import UserGetter from './UserGetter.js'
const OError = require('@overleaf/o-error') import OError from '@overleaf/o-error'
const UserSessionsManager = require('./UserSessionsManager') import UserSessionsManager from './UserSessionsManager.js'
const logger = require('@overleaf/logger') import logger from '@overleaf/logger'
const Settings = require('@overleaf/settings') import Settings from '@overleaf/settings'
const AuthenticationController = require('../Authentication/AuthenticationController') import AuthenticationController from '../Authentication/AuthenticationController.js'
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const NewsletterManager = require('../Newsletter/NewsletterManager') import NewsletterManager from '../Newsletter/NewsletterManager.js'
const SubscriptionLocator = require('../Subscription/SubscriptionLocator') import SubscriptionLocator from '../Subscription/SubscriptionLocator.js'
const _ = require('lodash') import _ from 'lodash'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
const Features = require('../../infrastructure/Features') import Features from '../../infrastructure/Features.js'
const SplitTestHandler = require('../SplitTests/SplitTestHandler') import SplitTestHandler from '../SplitTests/SplitTestHandler.js'
const Modules = require('../../infrastructure/Modules') import Modules from '../../infrastructure/Modules.js'
async function settingsPage(req, res) { async function settingsPage(req, res) {
const userId = SessionManager.getLoggedInUserId(req.session) const userId = SessionManager.getLoggedInUserId(req.session)
@ -324,4 +324,4 @@ const UserPagesController = {
}, },
} }
module.exports = UserPagesController export default UserPagesController

View file

@ -1,16 +1,16 @@
const SessionManager = require('../Authentication/SessionManager') import SessionManager from '../Authentication/SessionManager.js'
const UserMembershipHandler = require('./UserMembershipHandler') import UserMembershipHandler from './UserMembershipHandler.js'
const Errors = require('../Errors/Errors') import Errors from '../Errors/Errors.js'
const EmailHelper = require('../Helpers/EmailHelper') import EmailHelper from '../Helpers/EmailHelper.js'
const { csvAttachment } = require('../../infrastructure/Response') import { csvAttachment } from '../../infrastructure/Response.js'
const { import {
UserIsManagerError, UserIsManagerError,
UserAlreadyAddedError, UserAlreadyAddedError,
UserNotFoundError, UserNotFoundError,
} = require('./UserMembershipErrors') } from './UserMembershipErrors.js'
const { SSOConfig } = require('../../models/SSOConfig') import { SSOConfig } from '../../models/SSOConfig.js'
const CSVParser = require('json2csv').Parser import { Parser as CSVParser } from 'json2csv'
const { expressify } = require('@overleaf/promise-utils') import { expressify } from '@overleaf/promise-utils'
async function manageGroupMembers(req, res, next) { async function manageGroupMembers(req, res, next) {
const { entity: subscription, entityConfig } = req const { entity: subscription, entityConfig } = req
@ -99,7 +99,7 @@ async function _renderManagersPage(req, res, next, template) {
}) })
} }
module.exports = { export default {
manageGroupMembers: expressify(manageGroupMembers), manageGroupMembers: expressify(manageGroupMembers),
manageGroupManagers: expressify(manageGroupManagers), manageGroupManagers: expressify(manageGroupManagers),
manageInstitutionManagers: expressify(manageInstitutionManagers), manageInstitutionManagers: expressify(manageInstitutionManagers),

View file

@ -1,9 +1,9 @@
const UserMembershipMiddleware = require('./UserMembershipMiddleware') import UserMembershipMiddleware from './UserMembershipMiddleware.js'
const UserMembershipController = require('./UserMembershipController') import UserMembershipController from './UserMembershipController.mjs'
const SubscriptionGroupController = require('../Subscription/SubscriptionGroupController') import SubscriptionGroupController from '../Subscription/SubscriptionGroupController.mjs'
const TeamInvitesController = require('../Subscription/TeamInvitesController') import TeamInvitesController from '../Subscription/TeamInvitesController.mjs'
const { RateLimiter } = require('../../infrastructure/RateLimiter') import { RateLimiter } from '../../infrastructure/RateLimiter.js'
const RateLimiterMiddleware = require('../Security/RateLimiterMiddleware') import RateLimiterMiddleware from '../Security/RateLimiterMiddleware.js'
const rateLimiters = { const rateLimiters = {
createTeamInvite: new RateLimiter('create-team-invite', { createTeamInvite: new RateLimiter('create-team-invite', {
@ -16,7 +16,7 @@ const rateLimiters = {
}), }),
} }
module.exports = { export default {
apply(webRouter) { apply(webRouter) {
// group members routes // group members routes
webRouter.get( webRouter.get(

View file

@ -10,13 +10,13 @@
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
let V1Handler import OError from '@overleaf/o-error'
const OError = require('@overleaf/o-error') import V1Api from './V1Api.js'
const V1Api = require('./V1Api') import logger from '@overleaf/logger'
const Settings = require('@overleaf/settings')
const logger = require('@overleaf/logger')
module.exports = V1Handler = { let V1Handler
export default V1Handler = {
authWithV1(email, password, callback) { authWithV1(email, password, callback) {
return V1Api.request( return V1Api.request(
{ {

View file

@ -1,8 +1,11 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import path from 'node:path'
const sinon = require('sinon') import sinon from 'sinon'
const { expect } = require('chai') import { expect } from 'chai'
const MockResponse = require('../helpers/MockResponse') import MockResponse from '../helpers/MockResponse.js'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const modulePath = path.join( const modulePath = path.join(
__dirname, __dirname,
@ -10,7 +13,7 @@ const modulePath = path.join(
) )
describe('BetaProgramController', function () { describe('BetaProgramController', function () {
beforeEach(function () { beforeEach(async function () {
this.user = { this.user = {
_id: (this.user_id = 'a_simple_id'), _id: (this.user_id = 'a_simple_id'),
email: 'user@example.com', email: 'user@example.com',
@ -28,28 +31,28 @@ describe('BetaProgramController', function () {
sessionMaintenance: sinon.stub(), sessionMaintenance: sinon.stub(),
}, },
} }
this.BetaProgramController = SandboxedModule.require(modulePath, { this.BetaProgramController = await esmock.strict(modulePath, {
requires: { '../../../../app/src/Features/SplitTests/SplitTestSessionHandler':
'../SplitTests/SplitTestSessionHandler': this.SplitTestSessionHandler, this.SplitTestSessionHandler,
'./BetaProgramHandler': (this.BetaProgramHandler = { '../../../../app/src/Features/BetaProgram/BetaProgramHandler':
(this.BetaProgramHandler = {
promises: { promises: {
optIn: sinon.stub().resolves(), optIn: sinon.stub().resolves(),
optOut: sinon.stub().resolves(), optOut: sinon.stub().resolves(),
}, },
}), }),
'../User/UserGetter': (this.UserGetter = { '../../../../app/src/Features/User/UserGetter': (this.UserGetter = {
promises: { promises: {
getUser: sinon.stub().resolves(), getUser: sinon.stub().resolves(),
}, },
}),
'@overleaf/settings': (this.settings = {
languages: {},
}),
'../../../../app/src/Features/Authentication/AuthenticationController':
(this.AuthenticationController = {
getLoggedInUserId: sinon.stub().returns(this.user._id),
}), }),
'@overleaf/settings': (this.settings = {
languages: {},
}),
'../Authentication/AuthenticationController':
(this.AuthenticationController = {
getLoggedInUserId: sinon.stub().returns(this.user._id),
}),
},
}) })
this.res = new MockResponse() this.res = new MockResponse()
this.next = sinon.stub() this.next = sinon.stub()

View file

@ -1,14 +1,19 @@
const SandboxedModule = require('sandboxed-module') import esmock from 'esmock'
const path = require('path') import path from 'node:path'
import sinon from 'sinon'
import { expect } from 'chai'
import { fileURLToPath } from 'node:url'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const modulePath = path.join( const modulePath = path.join(
__dirname, __dirname,
'../../../../app/src/Features/BetaProgram/BetaProgramHandler' '../../../../app/src/Features/BetaProgram/BetaProgramHandler'
) )
const sinon = require('sinon')
const { expect } = require('chai')
describe('BetaProgramHandler', function () { describe('BetaProgramHandler', function () {
beforeEach(function () { beforeEach(async function () {
this.user_id = 'some_id' this.user_id = 'some_id'
this.user = { this.user = {
_id: this.user_id, _id: this.user_id,
@ -17,20 +22,19 @@ describe('BetaProgramHandler', function () {
betaProgram: false, betaProgram: false,
save: sinon.stub().callsArgWith(0, null), save: sinon.stub().callsArgWith(0, null),
} }
this.handler = SandboxedModule.require(modulePath, { this.handler = await esmock.strict(modulePath, {
requires: { '@overleaf/metrics': {
'@overleaf/metrics': { inc: sinon.stub(),
inc: sinon.stub(), },
'../../../../app/src/Features/User/UserUpdater': (this.UserUpdater = {
promises: {
updateUser: sinon.stub().resolves(),
}, },
'../User/UserUpdater': (this.UserUpdater = { }),
promises: { '../../../../app/src/Features/Analytics/AnalyticsManager':
updateUser: sinon.stub().resolves(), (this.AnalyticsManager = {
},
}),
'../Analytics/AnalyticsManager': (this.AnalyticsManager = {
setUserPropertyForUserInBackground: sinon.stub(), setUserPropertyForUserInBackground: sinon.stub(),
}), }),
},
}) })
}) })