2019-05-29 05:21:06 -04:00
|
|
|
const AdminController = require('./Features/ServerAdmin/AdminController')
|
|
|
|
const ErrorController = require('./Features/Errors/ErrorController')
|
|
|
|
const ProjectController = require('./Features/Project/ProjectController')
|
|
|
|
const ProjectApiController = require('./Features/Project/ProjectApiController')
|
2022-09-13 09:57:47 -04:00
|
|
|
const ProjectListController = require('./Features/Project/ProjectListController')
|
2019-05-29 05:21:06 -04:00
|
|
|
const SpellingController = require('./Features/Spelling/SpellingController')
|
|
|
|
const EditorRouter = require('./Features/Editor/EditorRouter')
|
2021-07-07 05:38:56 -04:00
|
|
|
const Settings = require('@overleaf/settings')
|
2019-05-29 05:21:06 -04:00
|
|
|
const TpdsController = require('./Features/ThirdPartyDataStore/TpdsController')
|
|
|
|
const SubscriptionRouter = require('./Features/Subscription/SubscriptionRouter')
|
|
|
|
const UploadsRouter = require('./Features/Uploads/UploadsRouter')
|
2020-10-30 04:10:50 -04:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2019-05-29 05:21:06 -04:00
|
|
|
const ReferalController = require('./Features/Referal/ReferalController')
|
|
|
|
const AuthenticationController = require('./Features/Authentication/AuthenticationController')
|
2023-07-10 04:40:45 -04:00
|
|
|
const PermissionsController = require('./Features/Authorization/PermissionsController')
|
2021-07-28 04:51:20 -04:00
|
|
|
const SessionManager = require('./Features/Authentication/SessionManager')
|
2019-05-29 05:21:06 -04:00
|
|
|
const TagsController = require('./Features/Tags/TagsController')
|
|
|
|
const NotificationsController = require('./Features/Notifications/NotificationsController')
|
|
|
|
const CollaboratorsRouter = require('./Features/Collaborators/CollaboratorsRouter')
|
|
|
|
const UserInfoController = require('./Features/User/UserInfoController')
|
|
|
|
const UserController = require('./Features/User/UserController')
|
|
|
|
const UserEmailsController = require('./Features/User/UserEmailsController')
|
|
|
|
const UserPagesController = require('./Features/User/UserPagesController')
|
2023-08-29 15:04:27 -04:00
|
|
|
const TutorialController = require('./Features/Tutorial/TutorialController')
|
2019-05-29 05:21:06 -04:00
|
|
|
const DocumentController = require('./Features/Documents/DocumentController')
|
|
|
|
const CompileManager = require('./Features/Compile/CompileManager')
|
|
|
|
const CompileController = require('./Features/Compile/CompileController')
|
|
|
|
const ClsiCookieManager = require('./Features/Compile/ClsiCookieManager')(
|
|
|
|
Settings.apis.clsi != null ? Settings.apis.clsi.backendGroupName : undefined
|
|
|
|
)
|
|
|
|
const HealthCheckController = require('./Features/HealthCheck/HealthCheckController')
|
|
|
|
const ProjectDownloadsController = require('./Features/Downloads/ProjectDownloadsController')
|
|
|
|
const FileStoreController = require('./Features/FileStore/FileStoreController')
|
|
|
|
const HistoryController = require('./Features/History/HistoryController')
|
|
|
|
const ExportsController = require('./Features/Exports/ExportsController')
|
|
|
|
const PasswordResetRouter = require('./Features/PasswordReset/PasswordResetRouter')
|
|
|
|
const StaticPagesRouter = require('./Features/StaticPages/StaticPagesRouter')
|
|
|
|
const ChatController = require('./Features/Chat/ChatController')
|
|
|
|
const Modules = require('./infrastructure/Modules')
|
2023-01-30 07:45:48 -05:00
|
|
|
const {
|
|
|
|
RateLimiter,
|
|
|
|
openProjectRateLimiter,
|
|
|
|
} = require('./infrastructure/RateLimiter')
|
2019-05-29 05:21:06 -04:00
|
|
|
const RateLimiterMiddleware = require('./Features/Security/RateLimiterMiddleware')
|
|
|
|
const InactiveProjectController = require('./Features/InactiveData/InactiveProjectController')
|
|
|
|
const ContactRouter = require('./Features/Contacts/ContactRouter')
|
|
|
|
const ReferencesController = require('./Features/References/ReferencesController')
|
|
|
|
const AuthorizationMiddleware = require('./Features/Authorization/AuthorizationMiddleware')
|
|
|
|
const BetaProgramController = require('./Features/BetaProgram/BetaProgramController')
|
|
|
|
const AnalyticsRouter = require('./Features/Analytics/AnalyticsRouter')
|
|
|
|
const MetaController = require('./Features/Metadata/MetaController')
|
|
|
|
const TokenAccessController = require('./Features/TokenAccess/TokenAccessController')
|
|
|
|
const Features = require('./infrastructure/Features')
|
|
|
|
const LinkedFilesRouter = require('./Features/LinkedFiles/LinkedFilesRouter')
|
|
|
|
const TemplatesRouter = require('./Features/Templates/TemplatesRouter')
|
|
|
|
const InstitutionsController = require('./Features/Institutions/InstitutionsController')
|
|
|
|
const UserMembershipRouter = require('./Features/UserMembership/UserMembershipRouter')
|
2020-02-26 06:55:28 -05:00
|
|
|
const SystemMessageController = require('./Features/SystemMessages/SystemMessageController')
|
2021-06-10 04:04:11 -04:00
|
|
|
const AnalyticsRegistrationSourceMiddleware = require('./Features/Analytics/AnalyticsRegistrationSourceMiddleware')
|
2021-11-08 10:09:29 -05:00
|
|
|
const AnalyticsUTMTrackingMiddleware = require('./Features/Analytics/AnalyticsUTMTrackingMiddleware')
|
2022-01-26 06:15:19 -05:00
|
|
|
const CaptchaMiddleware = require('./Features/Captcha/CaptchaMiddleware')
|
2021-01-21 07:20:55 -05:00
|
|
|
const { Joi, validate } = require('./infrastructure/Validation')
|
2021-04-16 04:36:46 -04:00
|
|
|
const {
|
2021-04-28 04:48:58 -04:00
|
|
|
renderUnsupportedBrowserPage,
|
2021-04-27 03:52:58 -04:00
|
|
|
unsupportedBrowserMiddleware,
|
2021-04-16 04:36:46 -04:00
|
|
|
} = require('./infrastructure/UnsupportedBrowserMiddleware')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-11-10 08:40:18 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2019-05-29 05:21:06 -04:00
|
|
|
const _ = require('underscore')
|
2022-01-17 05:19:53 -05:00
|
|
|
const { plainTextResponse } = require('./infrastructure/Response')
|
2022-12-12 08:09:15 -05:00
|
|
|
const PublicAccessLevels = require('./Features/Authorization/PublicAccessLevels')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2023-01-17 07:32:51 -05:00
|
|
|
const rateLimiters = {
|
2023-01-19 07:15:17 -05:00
|
|
|
addEmail: new RateLimiter('add-email', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
addProjectToTag: new RateLimiter('add-project-to-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
addProjectsToTag: new RateLimiter('add-projects-to-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
canSkipCaptcha: new RateLimiter('can-skip-captcha', {
|
|
|
|
points: 20,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
changePassword: new RateLimiter('change-password', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
compileProjectHttp: new RateLimiter('compile-project-http', {
|
|
|
|
points: 800,
|
|
|
|
duration: 60 * 60,
|
|
|
|
}),
|
|
|
|
confirmEmail: new RateLimiter('confirm-email', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
createProject: new RateLimiter('create-project', {
|
|
|
|
points: 20,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
createTag: new RateLimiter('create-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
deleteEmail: new RateLimiter('delete-email', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
deleteTag: new RateLimiter('delete-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
deleteUser: new RateLimiter('delete-user', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
downloadProjectRevision: new RateLimiter('download-project-revision', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60 * 60,
|
|
|
|
}),
|
|
|
|
endorseEmail: new RateLimiter('endorse-email', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
getProjects: new RateLimiter('get-projects', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
grantTokenAccessReadOnly: new RateLimiter('grant-token-access-read-only', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
grantTokenAccessReadWrite: new RateLimiter('grant-token-access-read-write', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
indexAllProjectReferences: new RateLimiter('index-all-project-references', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
miscOutputDownload: new RateLimiter('misc-output-download', {
|
|
|
|
points: 1000,
|
|
|
|
duration: 60 * 60,
|
|
|
|
}),
|
|
|
|
multipleProjectsZipDownload: new RateLimiter(
|
|
|
|
'multiple-projects-zip-download',
|
|
|
|
{
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
openDashboard: new RateLimiter('open-dashboard', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
readAndWriteToken: new RateLimiter('read-and-write-token', {
|
|
|
|
points: 15,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
readOnlyToken: new RateLimiter('read-only-token', {
|
|
|
|
points: 15,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
removeProjectFromTag: new RateLimiter('remove-project-from-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
removeProjectsFromTag: new RateLimiter('remove-projects-from-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
renameTag: new RateLimiter('rename-tag', {
|
|
|
|
points: 30,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
resendConfirmation: new RateLimiter('resend-confirmation', {
|
2023-08-30 04:36:51 -04:00
|
|
|
points: 1,
|
2023-01-19 07:15:17 -05:00
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
sendChatMessage: new RateLimiter('send-chat-message', {
|
|
|
|
points: 100,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
statusCompiler: new RateLimiter('status-compiler', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
2023-01-17 07:32:51 -05:00
|
|
|
zipDownload: new RateLimiter('zip-download', {
|
|
|
|
points: 10,
|
|
|
|
duration: 60,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
2021-09-08 08:14:25 -04:00
|
|
|
webRouter.use(unsupportedBrowserMiddleware)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
if (!Settings.allowPublicAccess) {
|
|
|
|
webRouter.all('*', AuthenticationController.requireGlobalLogin)
|
|
|
|
}
|
2019-07-18 10:19:10 -04:00
|
|
|
|
2021-06-21 10:02:43 -04:00
|
|
|
webRouter.get('*', AnalyticsRegistrationSourceMiddleware.setInbound())
|
2021-11-08 10:09:29 -05:00
|
|
|
webRouter.get('*', AnalyticsUTMTrackingMiddleware.recordUTMTags())
|
2021-06-21 10:02:43 -04:00
|
|
|
|
2022-01-26 06:15:19 -05:00
|
|
|
// Mount onto /login in order to get the deviceHistory cookie.
|
|
|
|
webRouter.post(
|
|
|
|
'/login/can-skip-captcha',
|
|
|
|
// Keep in sync with the overleaf-login options.
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.canSkipCaptcha),
|
2022-01-26 06:15:19 -05:00
|
|
|
CaptchaMiddleware.canSkipCaptcha
|
|
|
|
)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get('/login', UserPagesController.loginPage)
|
|
|
|
AuthenticationController.addEndpointToLoginWhitelist('/login')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2022-01-26 06:15:19 -05:00
|
|
|
webRouter.post(
|
|
|
|
'/login',
|
|
|
|
CaptchaMiddleware.validateCaptcha('login'),
|
|
|
|
AuthenticationController.passportLogin
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-07-20 05:26:03 -04:00
|
|
|
if (Settings.enableLegacyLogin) {
|
|
|
|
AuthenticationController.addEndpointToLoginWhitelist('/login/legacy')
|
|
|
|
webRouter.get('/login/legacy', UserPagesController.loginPage)
|
2022-01-26 06:15:32 -05:00
|
|
|
webRouter.post(
|
|
|
|
'/login/legacy',
|
|
|
|
CaptchaMiddleware.validateCaptcha('login'),
|
|
|
|
AuthenticationController.passportLogin
|
|
|
|
)
|
2021-07-20 05:26:03 -04:00
|
|
|
}
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/read-only/one-time-login',
|
|
|
|
UserPagesController.oneTimeLoginPage
|
|
|
|
)
|
|
|
|
AuthenticationController.addEndpointToLoginWhitelist(
|
|
|
|
'/read-only/one-time-login'
|
|
|
|
)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.post('/logout', UserController.logout)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get('/restricted', AuthorizationMiddleware.restricted)
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-07-20 05:26:23 -04:00
|
|
|
if (Features.hasFeature('registration-page')) {
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get('/register', UserPagesController.registerPage)
|
|
|
|
AuthenticationController.addEndpointToLoginWhitelist('/register')
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
EditorRouter.apply(webRouter, privateApiRouter)
|
|
|
|
CollaboratorsRouter.apply(webRouter, privateApiRouter)
|
|
|
|
SubscriptionRouter.apply(webRouter, privateApiRouter, publicApiRouter)
|
|
|
|
UploadsRouter.apply(webRouter, privateApiRouter)
|
|
|
|
PasswordResetRouter.apply(webRouter, privateApiRouter)
|
|
|
|
StaticPagesRouter.apply(webRouter, privateApiRouter)
|
|
|
|
ContactRouter.apply(webRouter, privateApiRouter)
|
|
|
|
AnalyticsRouter.apply(webRouter, privateApiRouter, publicApiRouter)
|
|
|
|
LinkedFilesRouter.apply(webRouter, privateApiRouter, publicApiRouter)
|
|
|
|
TemplatesRouter.apply(webRouter)
|
|
|
|
UserMembershipRouter.apply(webRouter)
|
|
|
|
|
|
|
|
Modules.applyRouter(webRouter, privateApiRouter, publicApiRouter)
|
|
|
|
|
|
|
|
if (Settings.enableSubscriptions) {
|
2019-05-29 05:21:06 -04:00
|
|
|
webRouter.get(
|
2019-08-06 08:20:52 -04:00
|
|
|
'/user/bonus',
|
2019-05-29 05:21:06 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
ReferalController.bonus
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-07-24 04:54:55 -04:00
|
|
|
// .getMessages will generate an empty response for anonymous users.
|
|
|
|
webRouter.get('/system/messages', SystemMessageController.getMessages)
|
2020-02-26 06:55:28 -05:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/user/settings',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-07-14 05:12:12 -04:00
|
|
|
PermissionsController.useCapabilities(),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserPagesController.settingsPage
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/user/settings',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserController.updateUserSettings
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/user/password/update',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.changePassword),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserController.changePassword
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/user/emails',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-07-10 04:40:45 -04:00
|
|
|
PermissionsController.useCapabilities(),
|
2020-03-11 09:21:44 -04:00
|
|
|
UserController.promises.ensureAffiliationMiddleware,
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.list
|
|
|
|
)
|
|
|
|
webRouter.get('/user/emails/confirm', UserEmailsController.showConfirm)
|
|
|
|
webRouter.post(
|
|
|
|
'/user/emails/confirm',
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.confirmEmail),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.confirm
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/user/emails/resend_confirmation',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.resendConfirmation),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.resendConfirmation
|
|
|
|
)
|
|
|
|
|
2022-02-03 06:37:34 -05:00
|
|
|
webRouter.get(
|
|
|
|
'/user/emails/primary-email-check',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserEmailsController.primaryEmailCheckPage
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/user/emails/primary-email-check',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserEmailsController.primaryEmailCheck
|
|
|
|
)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
if (Features.hasFeature('affiliations')) {
|
2019-05-29 05:21:06 -04:00
|
|
|
webRouter.post(
|
2019-08-06 08:20:52 -04:00
|
|
|
'/user/emails',
|
2019-05-29 05:21:06 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-07-10 04:40:45 -04:00
|
|
|
PermissionsController.requirePermission('add-secondary-email'),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.addEmail),
|
2023-06-26 04:32:49 -04:00
|
|
|
CaptchaMiddleware.validateCaptcha('addEmail'),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.add
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
webRouter.post(
|
2019-08-06 08:20:52 -04:00
|
|
|
'/user/emails/delete',
|
2019-05-29 05:21:06 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.deleteEmail),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.remove
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
webRouter.post(
|
2019-08-06 08:20:52 -04:00
|
|
|
'/user/emails/default',
|
2019-05-29 05:21:06 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.setDefault
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
webRouter.post(
|
2019-08-06 08:20:52 -04:00
|
|
|
'/user/emails/endorse',
|
2019-05-29 05:21:06 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-07-10 04:40:45 -04:00
|
|
|
PermissionsController.requirePermission('endorse-email'),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.endorseEmail),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserEmailsController.endorse
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/user/sessions',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserPagesController.sessionsPage
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/user/sessions/clear',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserController.clearSessions
|
|
|
|
)
|
|
|
|
|
2022-04-27 04:42:39 -04:00
|
|
|
// deprecated
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.delete(
|
|
|
|
'/user/newsletter/unsubscribe',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserController.unsubscribe
|
|
|
|
)
|
2022-04-27 04:42:39 -04:00
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/user/newsletter/unsubscribe',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserController.unsubscribe
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/user/newsletter/subscribe',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserController.subscribe
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/user/email-preferences',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserPagesController.emailPreferencesPage
|
|
|
|
)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/user/delete',
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.deleteUser),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-07-10 04:40:45 -04:00
|
|
|
PermissionsController.requirePermission('delete-own-account'),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserController.tryDeleteUser
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/user/personal_info',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
UserInfoController.getLoggedInUsersPersonalInfo
|
|
|
|
)
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/user/:user_id/personal_info',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserInfoController.getPersonalInfo
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/user/reconfirm',
|
|
|
|
UserPagesController.renderReconfirmAccountPage
|
|
|
|
)
|
|
|
|
// for /user/reconfirm POST, see password router
|
|
|
|
|
2020-04-15 07:37:05 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/user/tpds/queues',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
TpdsController.getQueues
|
|
|
|
)
|
|
|
|
|
2023-08-29 15:04:27 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/tutorial/:tutorialKey/complete',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
TutorialController.completeTutorial
|
|
|
|
)
|
|
|
|
|
2023-12-05 07:59:55 -05:00
|
|
|
webRouter.post(
|
|
|
|
'/tutorial/:tutorialKey/postpone',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
TutorialController.postponeTutorial
|
|
|
|
)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/user/projects',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
ProjectController.userProjectsJson
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/entities',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.projectEntitiesJson
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/project',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.openDashboard),
|
2023-03-06 09:33:19 -05:00
|
|
|
ProjectListController.projectListPage
|
2019-08-06 08:20:52 -04:00
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/new',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.createProject),
|
2019-08-06 08:20:52 -04:00
|
|
|
ProjectController.newProject
|
|
|
|
)
|
2022-09-13 09:57:47 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/api/project',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.getProjects),
|
2022-09-13 09:57:47 -04:00
|
|
|
ProjectListController.getProjectsJson
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
|
2021-11-19 06:08:57 -05:00
|
|
|
for (const route of [
|
|
|
|
// Keep the old route for continuous metrics
|
|
|
|
'/Project/:Project_id',
|
|
|
|
// New route for pdf-detach
|
|
|
|
'/Project/:Project_id/:detachRole(detacher|detached)',
|
|
|
|
]) {
|
|
|
|
webRouter.get(
|
|
|
|
route,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(openProjectRateLimiter, {
|
2021-11-19 06:08:57 -05:00
|
|
|
params: ['Project_id'],
|
|
|
|
}),
|
|
|
|
AuthenticationController.validateUserSession(),
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.loadEditor
|
|
|
|
)
|
|
|
|
}
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.head(
|
|
|
|
'/Project/:Project_id/file/:File_id',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
FileStoreController.getFileHead
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/Project/:Project_id/file/:File_id',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
FileStoreController.getFile
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/settings',
|
2022-12-12 08:09:15 -05:00
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
publicAccessLevel: Joi.string()
|
|
|
|
.valid(PublicAccessLevels.PRIVATE, PublicAccessLevels.TOKEN_BASED)
|
|
|
|
.optional(),
|
|
|
|
}),
|
|
|
|
}),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectSettings,
|
|
|
|
ProjectController.updateProjectSettings
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/settings/admin',
|
2019-09-30 09:21:49 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanAdminProject,
|
|
|
|
ProjectController.updateProjectAdminSettings
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/compile',
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.compileProjectHttp, {
|
2019-08-06 08:20:52 -04:00
|
|
|
params: ['Project_id'],
|
|
|
|
}),
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.compile
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/compile/stop',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.stopCompile
|
|
|
|
)
|
|
|
|
|
|
|
|
// LEGACY: Used by the web download buttons, adds filename header, TODO: remove at some future date
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/output/output.pdf',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.downloadPdf
|
|
|
|
)
|
|
|
|
|
|
|
|
// PDF Download button
|
|
|
|
webRouter.get(
|
|
|
|
/^\/download\/project\/([^/]*)\/output\/output\.pdf$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = { Project_id: req.params[0] }
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.downloadPdf
|
|
|
|
)
|
|
|
|
|
|
|
|
// PDF Download button for specific build
|
|
|
|
webRouter.get(
|
|
|
|
/^\/download\/project\/([^/]*)\/build\/([0-9a-f-]+)\/output\/output\.pdf$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
Project_id: req.params[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
build_id: req.params[1],
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-08-06 08:20:52 -04:00
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.downloadPdf
|
|
|
|
)
|
|
|
|
|
2020-11-26 07:55:22 -05:00
|
|
|
// Align with limits defined in CompileController.downloadPdf
|
2023-01-30 07:45:48 -05:00
|
|
|
const rateLimiterMiddlewareOutputFiles = RateLimiterMiddleware.rateLimit(
|
2023-01-19 07:15:17 -05:00
|
|
|
rateLimiters.miscOutputDownload,
|
|
|
|
{ params: ['Project_id'] }
|
|
|
|
)
|
2020-11-26 07:55:22 -05:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
// Used by the pdf viewers
|
|
|
|
webRouter.get(
|
|
|
|
/^\/project\/([^/]*)\/output\/(.*)$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
Project_id: req.params[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: req.params[1],
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-08-06 08:20:52 -04:00
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
2020-11-26 07:55:22 -05:00
|
|
|
rateLimiterMiddlewareOutputFiles,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.getFileFromClsi
|
|
|
|
)
|
|
|
|
// direct url access to output files for a specific build (query string not required)
|
|
|
|
webRouter.get(
|
|
|
|
/^\/project\/([^/]*)\/build\/([0-9a-f-]+)\/output\/(.*)$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
Project_id: req.params[0],
|
|
|
|
build_id: req.params[1],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: req.params[2],
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
2020-11-26 07:55:22 -05:00
|
|
|
rateLimiterMiddlewareOutputFiles,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.getFileFromClsi
|
|
|
|
)
|
|
|
|
|
|
|
|
// direct url access to output files for user but no build, to retrieve files when build fails
|
|
|
|
webRouter.get(
|
|
|
|
/^\/project\/([^/]*)\/user\/([0-9a-f-]+)\/output\/(.*)$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
Project_id: req.params[0],
|
|
|
|
user_id: req.params[1],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: req.params[2],
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
2020-11-26 07:55:22 -05:00
|
|
|
rateLimiterMiddlewareOutputFiles,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.getFileFromClsi
|
|
|
|
)
|
|
|
|
|
|
|
|
// direct url access to output files for a specific user and build (query string not required)
|
|
|
|
webRouter.get(
|
|
|
|
/^\/project\/([^/]*)\/user\/([0-9a-f]+)\/build\/([0-9a-f-]+)\/output\/(.*)$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
Project_id: req.params[0],
|
|
|
|
user_id: req.params[1],
|
|
|
|
build_id: req.params[2],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: req.params[3],
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
2020-11-26 07:55:22 -05:00
|
|
|
rateLimiterMiddlewareOutputFiles,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.getFileFromClsi
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.delete(
|
|
|
|
'/project/:Project_id/output',
|
2021-01-21 07:20:55 -05:00
|
|
|
validate({ query: { clsiserverid: Joi.string() } }),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.deleteAuxFiles
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/sync/code',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.proxySyncCode
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/sync/pdf',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.proxySyncPdf
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/wordcount',
|
2021-01-21 07:20:55 -05:00
|
|
|
validate({ query: { clsiserverid: Joi.string() } }),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
CompileController.wordCount
|
|
|
|
)
|
|
|
|
|
2019-10-02 10:06:57 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/Project/:Project_id/archive',
|
2022-03-28 06:23:47 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-10-02 10:06:57 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.archiveProject
|
|
|
|
)
|
|
|
|
webRouter.delete(
|
|
|
|
'/Project/:Project_id/archive',
|
2022-03-28 06:23:47 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-10-02 10:06:57 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.unarchiveProject
|
|
|
|
)
|
2019-09-26 08:42:15 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/project/:project_id/trash',
|
2022-03-28 06:23:47 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-09-26 08:42:15 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.trashProject
|
|
|
|
)
|
|
|
|
webRouter.delete(
|
|
|
|
'/project/:project_id/trash',
|
2022-03-28 06:23:47 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-09-26 08:42:15 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.untrashProject
|
|
|
|
)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.delete(
|
|
|
|
'/Project/:Project_id',
|
2019-09-30 09:21:49 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanAdminProject,
|
|
|
|
ProjectController.deleteProject
|
|
|
|
)
|
2019-10-02 10:06:57 -04:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/Project/:Project_id/restore',
|
2019-09-30 09:21:49 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanAdminProject,
|
|
|
|
ProjectController.restoreProject
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/Project/:Project_id/clone',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectController.cloneProject
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/rename',
|
2019-09-30 09:21:49 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanAdminProject,
|
|
|
|
ProjectController.renameProject
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/updates',
|
2022-03-28 08:23:15 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
HistoryController.proxyToHistoryApiAndInjectUserDetails
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/doc/:doc_id/diff',
|
2022-03-28 08:23:15 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
HistoryController.proxyToHistoryApi
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/diff',
|
2022-03-28 08:23:15 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
HistoryController.proxyToHistoryApiAndInjectUserDetails
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/filetree/diff',
|
2022-03-28 08:23:15 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
HistoryController.proxyToHistoryApi
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:project_id/restore_file',
|
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectContent,
|
|
|
|
HistoryController.restoreFileFromV2
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:project_id/version/:version/zip',
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.downloadProjectRevision),
|
2022-03-28 08:23:15 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
HistoryController.downloadZipOfVersion
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/project/:Project_id/history/resync',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
HistoryController.resyncProjectHistory
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:Project_id/labels',
|
2022-03-28 08:23:15 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
HistoryController.getLabels
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/labels',
|
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectContent,
|
|
|
|
HistoryController.createLabel
|
|
|
|
)
|
|
|
|
webRouter.delete(
|
|
|
|
'/project/:Project_id/labels/:label_id',
|
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectContent,
|
|
|
|
HistoryController.deleteLabel
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:project_id/export/:brand_variation_id',
|
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectContent,
|
|
|
|
ExportsController.exportProject
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:project_id/export/:export_id',
|
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectContent,
|
|
|
|
ExportsController.exportStatus
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:project_id/export/:export_id/:type',
|
|
|
|
AuthorizationMiddleware.ensureUserCanWriteProjectContent,
|
|
|
|
ExportsController.exportDownload
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/Project/:Project_id/download/zip',
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.zipDownload, {
|
2022-03-24 11:40:54 -04:00
|
|
|
params: ['Project_id'],
|
|
|
|
}),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ProjectDownloadsController.downloadProject
|
|
|
|
)
|
|
|
|
webRouter.get(
|
|
|
|
'/project/download/zip',
|
2022-03-31 03:54:53 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.multipleProjectsZipDownload),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadMultipleProjects,
|
|
|
|
ProjectDownloadsController.downloadMultipleProjects
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/project/:project_id/metadata',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
2020-10-27 06:53:44 -04:00
|
|
|
Settings.allowAnonymousReadAndWriteSharing
|
|
|
|
? (req, res, next) => {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
: AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
MetaController.getMetadata
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:project_id/doc/:doc_id/metadata',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
2020-10-27 06:53:44 -04:00
|
|
|
Settings.allowAnonymousReadAndWriteSharing
|
|
|
|
? (req, res, next) => {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
: AuthenticationController.requireLogin(),
|
2019-08-06 08:20:52 -04:00
|
|
|
MetaController.broadcastMetadataForDoc
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/internal/expire-deleted-projects-after-duration',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
ProjectController.expireDeletedProjectsAfterDuration
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/internal/expire-deleted-users-after-duration',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserController.expireDeletedUsersAfterDuration
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/internal/project/:projectId/expire-deleted-project',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
ProjectController.expireDeletedProject
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/internal/users/:userId/expire',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
UserController.expireDeletedUser
|
|
|
|
)
|
|
|
|
|
2020-03-24 06:20:06 -04:00
|
|
|
privateApiRouter.get(
|
|
|
|
'/user/:userId/tag',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2020-03-24 06:20:06 -04:00
|
|
|
TagsController.apiGetAllTags
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/tag',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
TagsController.getAllTags
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/tag',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.createTag),
|
2022-10-17 06:14:24 -04:00
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
name: Joi.string().required(),
|
2023-04-12 04:30:56 -04:00
|
|
|
color: Joi.string(),
|
2022-10-17 06:14:24 -04:00
|
|
|
}),
|
|
|
|
}),
|
2019-08-06 08:20:52 -04:00
|
|
|
TagsController.createTag
|
|
|
|
)
|
|
|
|
webRouter.post(
|
2020-03-24 06:20:06 -04:00
|
|
|
'/tag/:tagId/rename',
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.renameTag),
|
2022-10-17 06:14:24 -04:00
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
name: Joi.string().required(),
|
|
|
|
}),
|
|
|
|
}),
|
2019-08-06 08:20:52 -04:00
|
|
|
TagsController.renameTag
|
|
|
|
)
|
2023-04-12 04:30:56 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/tag/:tagId/edit',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.renameTag),
|
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
name: Joi.string().required(),
|
|
|
|
color: Joi.string(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
TagsController.editTag
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.delete(
|
2020-03-24 06:20:06 -04:00
|
|
|
'/tag/:tagId',
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.deleteTag),
|
2019-08-06 08:20:52 -04:00
|
|
|
TagsController.deleteTag
|
|
|
|
)
|
|
|
|
webRouter.post(
|
2020-03-24 06:20:06 -04:00
|
|
|
'/tag/:tagId/project/:projectId',
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.addProjectToTag),
|
2019-08-06 08:20:52 -04:00
|
|
|
TagsController.addProjectToTag
|
|
|
|
)
|
2022-10-17 06:14:24 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/tag/:tagId/projects',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.addProjectsToTag),
|
2022-10-17 06:14:24 -04:00
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
projectIds: Joi.array().items(Joi.string()).required(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
TagsController.addProjectsToTag
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.delete(
|
2020-03-24 06:20:06 -04:00
|
|
|
'/tag/:tagId/project/:projectId',
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.removeProjectFromTag),
|
2019-08-06 08:20:52 -04:00
|
|
|
TagsController.removeProjectFromTag
|
|
|
|
)
|
2022-10-17 06:14:24 -04:00
|
|
|
webRouter.delete(
|
|
|
|
'/tag/:tagId/projects',
|
|
|
|
AuthenticationController.requireLogin(),
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.removeProjectsFromTag),
|
2022-10-17 06:14:24 -04:00
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
projectIds: Joi.array().items(Joi.string()).required(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
TagsController.removeProjectsFromTag
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/notifications',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
NotificationsController.getAllUnreadNotifications
|
|
|
|
)
|
|
|
|
webRouter.delete(
|
2021-05-05 09:20:32 -04:00
|
|
|
'/notifications/:notificationId',
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
NotificationsController.markNotificationAsRead
|
|
|
|
)
|
|
|
|
|
|
|
|
// Deprecated in favour of /internal/project/:project_id but still used by versioning
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/project/:project_id/details',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
ProjectApiController.getProjectDetails
|
|
|
|
)
|
|
|
|
|
|
|
|
// New 'stable' /internal API end points
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/internal/project/:project_id',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
ProjectApiController.getProjectDetails
|
|
|
|
)
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/internal/project/:Project_id/zip',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
ProjectDownloadsController.downloadProject
|
|
|
|
)
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/internal/project/:project_id/compile/pdf',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
CompileController.compileAndDownloadPdf
|
|
|
|
)
|
|
|
|
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/internal/deactivateOldProjects',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
InactiveProjectController.deactivateOldProjects
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/internal/project/:project_id/deactivate',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
InactiveProjectController.deactivateProject
|
|
|
|
)
|
|
|
|
|
2019-11-18 05:57:36 -05:00
|
|
|
privateApiRouter.get(
|
2019-08-06 08:20:52 -04:00
|
|
|
/^\/internal\/project\/([^/]*)\/output\/(.*)$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
Project_id: req.params[0],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: req.params[1],
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
CompileController.getFileFromClsi
|
|
|
|
)
|
|
|
|
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/project/:Project_id/doc/:doc_id',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
DocumentController.getDocument
|
|
|
|
)
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/project/:Project_id/doc/:doc_id',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
DocumentController.setDocument
|
|
|
|
)
|
|
|
|
|
2022-10-05 05:27:19 -04:00
|
|
|
privateApiRouter.post(
|
|
|
|
'/user/:user_id/project/new',
|
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
|
|
|
TpdsController.createProject
|
|
|
|
)
|
2022-09-21 08:01:56 -04:00
|
|
|
privateApiRouter.post(
|
|
|
|
'/tpds/folder-update',
|
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
|
|
|
TpdsController.updateFolder
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
privateApiRouter.post(
|
|
|
|
'/user/:user_id/update/*',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
TpdsController.mergeUpdate
|
|
|
|
)
|
|
|
|
privateApiRouter.delete(
|
|
|
|
'/user/:user_id/update/*',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
TpdsController.deleteUpdate
|
|
|
|
)
|
2022-10-05 05:26:52 -04:00
|
|
|
privateApiRouter.post(
|
|
|
|
'/project/:project_id/user/:user_id/update/*',
|
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
|
|
|
TpdsController.mergeUpdate
|
|
|
|
)
|
|
|
|
privateApiRouter.delete(
|
|
|
|
'/project/:project_id/user/:user_id/update/*',
|
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
|
|
|
TpdsController.deleteUpdate
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
|
|
|
|
privateApiRouter.post(
|
|
|
|
'/project/:project_id/contents/*',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
TpdsController.updateProjectContents
|
|
|
|
)
|
|
|
|
privateApiRouter.delete(
|
|
|
|
'/project/:project_id/contents/*',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
TpdsController.deleteProjectContents
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/spelling/check',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
SpellingController.proxyRequestToSpellingApi
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/spelling/learn',
|
2022-01-06 05:41:31 -05:00
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
word: Joi.string().required(),
|
|
|
|
}),
|
|
|
|
}),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthenticationController.requireLogin(),
|
2022-01-06 05:41:31 -05:00
|
|
|
SpellingController.learn
|
2019-08-06 08:20:52 -04:00
|
|
|
)
|
|
|
|
|
2022-05-24 07:21:25 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/spelling/unlearn',
|
|
|
|
validate({
|
|
|
|
body: Joi.object({
|
|
|
|
word: Joi.string().required(),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
SpellingController.unlearn
|
|
|
|
)
|
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get(
|
|
|
|
'/project/:project_id/messages',
|
2020-06-04 04:47:12 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
|
|
|
ChatController.getMessages
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:project_id/messages',
|
2020-06-04 04:47:12 -04:00
|
|
|
AuthorizationMiddleware.blockRestrictedUserFromProject,
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.sendChatMessage),
|
2019-08-06 08:20:52 -04:00
|
|
|
ChatController.sendMessage
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
'/project/:Project_id/references/indexAll',
|
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.indexAllProjectReferences),
|
2019-08-06 08:20:52 -04:00
|
|
|
ReferencesController.indexAll
|
|
|
|
)
|
|
|
|
|
|
|
|
// disable beta program while v2 is in beta
|
|
|
|
webRouter.get(
|
|
|
|
'/beta/participate',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
BetaProgramController.optInPage
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/beta/opt-in',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
BetaProgramController.optIn
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/beta/opt-out',
|
|
|
|
AuthenticationController.requireLogin(),
|
|
|
|
BetaProgramController.optOut
|
|
|
|
)
|
|
|
|
|
|
|
|
// New "api" endpoints. Started as a way for v1 to call over to v2 (for
|
|
|
|
// long-term features, as opposed to the nominally temporary ones in the
|
|
|
|
// overleaf-integration module), but may expand beyond that role.
|
|
|
|
publicApiRouter.post(
|
|
|
|
'/api/clsi/compile/:submission_id',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
CompileController.compileSubmission
|
|
|
|
)
|
|
|
|
publicApiRouter.get(
|
|
|
|
/^\/api\/clsi\/compile\/([^/]*)\/build\/([0-9a-f-]+)\/output\/(.*)$/,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const params = {
|
|
|
|
submission_id: req.params[0],
|
|
|
|
build_id: req.params[1],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: req.params[2],
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
},
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
CompileController.getFileFromClsiWithoutUser
|
|
|
|
)
|
|
|
|
publicApiRouter.post(
|
|
|
|
'/api/institutions/confirm_university_domain',
|
2021-05-31 04:30:04 -04:00
|
|
|
AuthenticationController.requirePrivateApiAuth(),
|
2019-08-06 08:20:52 -04:00
|
|
|
InstitutionsController.confirmDomain
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
webRouter.get('/chrome', function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
// Match v1 behaviour - this is used for a Chrome web app
|
2021-07-28 04:51:20 -04:00
|
|
|
if (SessionManager.isUserLoggedIn(req.session)) {
|
2019-08-06 08:20:52 -04:00
|
|
|
res.redirect('/project')
|
|
|
|
} else {
|
|
|
|
res.redirect('/register')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/admin',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.index
|
|
|
|
)
|
2022-04-07 09:41:05 -04:00
|
|
|
|
2021-03-30 07:10:27 -04:00
|
|
|
if (!Features.hasFeature('saas')) {
|
|
|
|
webRouter.post(
|
|
|
|
'/admin/openEditor',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.openEditor
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/admin/closeEditor',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.closeEditor
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/admin/disconnectAllUsers',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.disconnectAllUsers
|
|
|
|
)
|
|
|
|
}
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.post(
|
|
|
|
'/admin/flushProjectToTpds',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.flushProjectToTpds
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/admin/pollDropboxForUser',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.pollDropboxForUser
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/admin/messages',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.createMessage
|
|
|
|
)
|
|
|
|
webRouter.post(
|
|
|
|
'/admin/messages/clear',
|
|
|
|
AuthorizationMiddleware.ensureUserIsSiteAdmin,
|
|
|
|
AdminController.clearMessages
|
|
|
|
)
|
|
|
|
|
2022-01-17 05:19:53 -05:00
|
|
|
privateApiRouter.get('/perfTest', (req, res) => {
|
|
|
|
plainTextResponse(res, 'hello')
|
|
|
|
})
|
2019-08-06 08:20:52 -04:00
|
|
|
|
2021-02-25 05:49:24 -05:00
|
|
|
publicApiRouter.get('/status', (req, res) => {
|
2023-02-08 04:22:24 -05:00
|
|
|
if (Settings.shuttingDown) {
|
|
|
|
res.sendStatus(503) // Service unavailable
|
|
|
|
} else if (!Settings.siteIsOpen) {
|
2022-01-17 05:19:53 -05:00
|
|
|
plainTextResponse(res, 'web site is closed (web)')
|
2021-02-25 05:49:24 -05:00
|
|
|
} else if (!Settings.editorIsOpen) {
|
2022-01-17 05:19:53 -05:00
|
|
|
plainTextResponse(res, 'web editor is closed (web)')
|
2021-02-25 05:49:24 -05:00
|
|
|
} else {
|
2022-01-17 05:19:53 -05:00
|
|
|
plainTextResponse(res, 'web sharelatex is alive (web)')
|
2021-02-25 05:49:24 -05:00
|
|
|
}
|
|
|
|
})
|
2022-01-17 05:19:53 -05:00
|
|
|
privateApiRouter.get('/status', (req, res) => {
|
|
|
|
plainTextResponse(res, 'web sharelatex is alive (api)')
|
|
|
|
})
|
2019-08-06 08:20:52 -04:00
|
|
|
|
2019-11-04 06:43:28 -05:00
|
|
|
// used by kubernetes health-check and acceptance tests
|
2022-01-17 05:19:53 -05:00
|
|
|
webRouter.get('/dev/csrf', (req, res) => {
|
|
|
|
plainTextResponse(res, res.locals.csrfToken)
|
|
|
|
})
|
2019-08-06 08:20:52 -04:00
|
|
|
|
2020-07-09 09:28:46 -04:00
|
|
|
publicApiRouter.get(
|
|
|
|
'/health_check',
|
|
|
|
HealthCheckController.checkActiveHandles,
|
|
|
|
HealthCheckController.check
|
|
|
|
)
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/health_check',
|
|
|
|
HealthCheckController.checkActiveHandles,
|
|
|
|
HealthCheckController.checkApi
|
|
|
|
)
|
2021-05-31 12:59:51 -04:00
|
|
|
publicApiRouter.get(
|
|
|
|
'/health_check/api',
|
|
|
|
HealthCheckController.checkActiveHandles,
|
|
|
|
HealthCheckController.checkApi
|
|
|
|
)
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/health_check/api',
|
|
|
|
HealthCheckController.checkActiveHandles,
|
|
|
|
HealthCheckController.checkApi
|
|
|
|
)
|
2020-12-02 05:16:16 -05:00
|
|
|
publicApiRouter.get(
|
|
|
|
'/health_check/full',
|
|
|
|
HealthCheckController.checkActiveHandles,
|
|
|
|
HealthCheckController.check
|
|
|
|
)
|
|
|
|
privateApiRouter.get(
|
|
|
|
'/health_check/full',
|
|
|
|
HealthCheckController.checkActiveHandles,
|
|
|
|
HealthCheckController.check
|
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
|
|
|
|
publicApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)
|
|
|
|
privateApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)
|
|
|
|
|
|
|
|
publicApiRouter.get('/health_check/mongo', HealthCheckController.checkMongo)
|
|
|
|
privateApiRouter.get('/health_check/mongo', HealthCheckController.checkMongo)
|
|
|
|
|
|
|
|
webRouter.get(
|
|
|
|
'/status/compiler/:Project_id',
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.statusCompiler),
|
2019-08-06 08:20:52 -04:00
|
|
|
AuthorizationMiddleware.ensureUserCanReadProject,
|
2021-04-14 09:17:21 -04:00
|
|
|
function (req, res) {
|
2019-08-06 08:20:52 -04:00
|
|
|
const projectId = req.params.Project_id
|
2023-07-06 07:17:03 -04:00
|
|
|
// use a valid user id for testing
|
|
|
|
const testUserId = '123456789012345678901234'
|
2021-04-14 09:17:21 -04:00
|
|
|
const sendRes = _.once(function (statusCode, message) {
|
2019-08-06 08:20:52 -04:00
|
|
|
res.status(statusCode)
|
2022-01-17 05:19:53 -05:00
|
|
|
plainTextResponse(res, message)
|
2023-07-06 07:17:03 -04:00
|
|
|
ClsiCookieManager.clearServerId(projectId, testUserId, () => {})
|
2019-08-06 08:20:52 -04:00
|
|
|
}) // force every compile to a new server
|
|
|
|
// set a timeout
|
2021-10-26 04:08:56 -04:00
|
|
|
let handler = setTimeout(function () {
|
2019-08-06 08:20:52 -04:00
|
|
|
sendRes(500, 'Compiler timed out')
|
|
|
|
handler = null
|
|
|
|
}, 10000)
|
|
|
|
// run the compile
|
2021-04-14 09:17:21 -04:00
|
|
|
CompileManager.compile(
|
|
|
|
projectId,
|
|
|
|
testUserId,
|
|
|
|
{},
|
|
|
|
function (error, status) {
|
|
|
|
if (handler) {
|
|
|
|
clearTimeout(handler)
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
sendRes(500, `Compiler returned error ${error.message}`)
|
|
|
|
} else if (status === 'success') {
|
|
|
|
sendRes(200, 'Compiler returned in less than 10 seconds')
|
|
|
|
} else {
|
|
|
|
sendRes(500, `Compiler returned failure ${status}`)
|
|
|
|
}
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|
2019-08-06 08:20:52 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
webRouter.get('/no-cache', function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
res.header('Cache-Control', 'max-age=0')
|
|
|
|
res.sendStatus(404)
|
|
|
|
})
|
|
|
|
|
|
|
|
webRouter.get('/oops-express', (req, res, next) =>
|
|
|
|
next(new Error('Test error'))
|
|
|
|
)
|
2021-04-14 09:17:21 -04:00
|
|
|
webRouter.get('/oops-internal', function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
throw new Error('Test error')
|
|
|
|
})
|
|
|
|
webRouter.get('/oops-mongo', (req, res, next) =>
|
2021-04-14 09:17:21 -04:00
|
|
|
require('./models/Project').Project.findOne({}, function () {
|
2019-08-06 08:20:52 -04:00
|
|
|
throw new Error('Test error')
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-08-06 08:20:52 -04:00
|
|
|
)
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
privateApiRouter.get('/opps-small', function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
logger.err('test error occured')
|
2020-05-06 06:02:16 -04:00
|
|
|
res.sendStatus(200)
|
2019-08-06 08:20:52 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
webRouter.post('/error/client', function (req, res, next) {
|
2019-08-06 08:20:52 -04:00
|
|
|
logger.warn(
|
|
|
|
{ err: req.body.error, meta: req.body.meta },
|
|
|
|
'client side error'
|
|
|
|
)
|
|
|
|
metrics.inc('client-side-error')
|
|
|
|
res.sendStatus(204)
|
|
|
|
})
|
|
|
|
|
|
|
|
webRouter.get(
|
2020-02-25 04:39:53 -05:00
|
|
|
`/read/:token(${TokenAccessController.READ_ONLY_TOKEN_PATTERN})`,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.readOnlyToken),
|
2021-09-23 05:02:39 -04:00
|
|
|
AnalyticsRegistrationSourceMiddleware.setSource(
|
|
|
|
'collaboration',
|
|
|
|
'link-sharing'
|
|
|
|
),
|
2021-06-10 04:04:11 -04:00
|
|
|
TokenAccessController.tokenAccessPage,
|
|
|
|
AnalyticsRegistrationSourceMiddleware.clearSource()
|
2019-08-06 08:20:52 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.get(
|
2020-02-25 04:39:53 -05:00
|
|
|
`/:token(${TokenAccessController.READ_AND_WRITE_TOKEN_PATTERN})`,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.readAndWriteToken),
|
2021-09-23 05:02:39 -04:00
|
|
|
AnalyticsRegistrationSourceMiddleware.setSource(
|
|
|
|
'collaboration',
|
|
|
|
'link-sharing'
|
|
|
|
),
|
2021-06-10 04:04:11 -04:00
|
|
|
TokenAccessController.tokenAccessPage,
|
|
|
|
AnalyticsRegistrationSourceMiddleware.clearSource()
|
2020-02-25 04:39:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
`/:token(${TokenAccessController.READ_AND_WRITE_TOKEN_PATTERN})/grant`,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.grantTokenAccessReadWrite),
|
2020-02-25 04:39:53 -05:00
|
|
|
TokenAccessController.grantTokenAccessReadAndWrite
|
|
|
|
)
|
|
|
|
|
|
|
|
webRouter.post(
|
|
|
|
`/read/:token(${TokenAccessController.READ_ONLY_TOKEN_PATTERN})/grant`,
|
2023-01-30 07:45:48 -05:00
|
|
|
RateLimiterMiddleware.rateLimit(rateLimiters.grantTokenAccessReadOnly),
|
2020-02-25 04:39:53 -05:00
|
|
|
TokenAccessController.grantTokenAccessReadOnly
|
2019-08-06 08:20:52 -04:00
|
|
|
)
|
|
|
|
|
2021-04-28 04:48:58 -04:00
|
|
|
webRouter.get('/unsupported-browser', renderUnsupportedBrowserPage)
|
2021-04-16 04:36:46 -04:00
|
|
|
|
2019-08-06 08:20:52 -04:00
|
|
|
webRouter.get('*', ErrorController.notFound)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2023-01-30 07:45:48 -05:00
|
|
|
|
|
|
|
module.exports = { initialize, rateLimiters }
|