mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Intelligently redirect to v1 if no v2 project found for token
This commit is contained in:
@@ -3,9 +3,19 @@ AuthenticationController = require '../Authentication/AuthenticationController'
|
||||
TokenAccessHandler = require './TokenAccessHandler'
|
||||
Errors = require '../Errors/Errors'
|
||||
logger = require 'logger-sharelatex'
|
||||
settings = require 'settings-sharelatex'
|
||||
|
||||
module.exports = TokenAccessController =
|
||||
|
||||
redirectNotFoundErrorToV1: (err, req, res, next) ->
|
||||
if err instanceof Errors.NotFoundError and settings.overleaf
|
||||
logger.log {
|
||||
token: req.params['read_and_write_token']
|
||||
}, "[TokenAccess] No project found for token, redirecting to v1"
|
||||
res.redirect(settings.overleaf.host + req.url)
|
||||
else
|
||||
next(err)
|
||||
|
||||
_loadEditor: (projectId, req, res, next) ->
|
||||
req.params.Project_id = projectId.toString()
|
||||
return ProjectController.loadEditor(req, res, next)
|
||||
|
||||
@@ -426,6 +426,7 @@ module.exports = class Router
|
||||
maxRequests: 10,
|
||||
timeInterval: 60
|
||||
}),
|
||||
TokenAccessController.readAndWriteToken
|
||||
TokenAccessController.readAndWriteToken,
|
||||
TokenAccessController.redirectNotFoundErrorToV1
|
||||
|
||||
webRouter.get '*', ErrorController.notFound
|
||||
|
||||
Reference in New Issue
Block a user