mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #247 from sharelatex/add-query-string-to-proxy-and-filter-synctex-requests
Add query string to proxy and filter synctex requests
This commit is contained in:
commit
d83cd547fb
2 changed files with 32 additions and 6 deletions
|
@ -9,7 +9,7 @@ AuthenticationController = require "../Authentication/AuthenticationController"
|
||||||
UserGetter = require "../User/UserGetter"
|
UserGetter = require "../User/UserGetter"
|
||||||
RateLimiter = require("../../infrastructure/RateLimiter")
|
RateLimiter = require("../../infrastructure/RateLimiter")
|
||||||
ClsiCookieManager = require("./ClsiCookieManager")
|
ClsiCookieManager = require("./ClsiCookieManager")
|
||||||
|
Path = require("path")
|
||||||
|
|
||||||
module.exports = CompileController =
|
module.exports = CompileController =
|
||||||
compile: (req, res, next = (error) ->) ->
|
compile: (req, res, next = (error) ->) ->
|
||||||
|
@ -98,8 +98,29 @@ module.exports = CompileController =
|
||||||
url = "/project/#{project_id}/output/#{req.params.file}"
|
url = "/project/#{project_id}/output/#{req.params.file}"
|
||||||
CompileController.proxyToClsi(project_id, url, req, res, next)
|
CompileController.proxyToClsi(project_id, url, req, res, next)
|
||||||
|
|
||||||
proxySync: (req, res, next = (error) ->) ->
|
proxySyncPdf: (req, res, next = (error) ->) ->
|
||||||
CompileController.proxyToClsi(req.params.Project_id, req.url, req, res, next)
|
project_id = req.params.Project_id
|
||||||
|
{page, h, v} = req.query
|
||||||
|
if not page?.match(/^\d+$/)
|
||||||
|
return next(new Error("invalid page parameter"))
|
||||||
|
if not h?.match(/^\d+\.\d+$/)
|
||||||
|
return next(new Error("invalid h parameter"))
|
||||||
|
if not v?.match(/^\d+\.\d+$/)
|
||||||
|
return next(new Error("invalid v parameter"))
|
||||||
|
destination = {url: "/project/#{project_id}/sync/pdf", qs: {page, h, v}}
|
||||||
|
CompileController.proxyToClsi(project_id, destination, req, res, next)
|
||||||
|
|
||||||
|
proxySyncCode: (req, res, next = (error) ->) ->
|
||||||
|
project_id = req.params.Project_id
|
||||||
|
{file, line, column} = req.query
|
||||||
|
if not file? or Path.resolve("/", file) isnt "/#{file}"
|
||||||
|
return next(new Error("invalid file parameter"))
|
||||||
|
if not line?.match(/^\d+$/)
|
||||||
|
return next(new Error("invalid line parameter"))
|
||||||
|
if not column?.match(/^\d+$/)
|
||||||
|
return next(new Error("invalid column parameter"))
|
||||||
|
destination = {url:"/project/#{project_id}/sync/code", qs: {file, line, column}}
|
||||||
|
CompileController.proxyToClsi(project_id, destination, req, res, next)
|
||||||
|
|
||||||
proxyToClsi: (project_id, url, req, res, next = (error) ->) ->
|
proxyToClsi: (project_id, url, req, res, next = (error) ->) ->
|
||||||
if req.query?.compileGroup
|
if req.query?.compileGroup
|
||||||
|
@ -114,6 +135,9 @@ module.exports = CompileController =
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, "error getting cookie jar for clsi request"
|
logger.err err:err, "error getting cookie jar for clsi request"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
|
# expand any url parameter passed in as {url:..., qs:...}
|
||||||
|
if typeof url is "object"
|
||||||
|
{url, qs} = url
|
||||||
if limits.compileGroup == "priority"
|
if limits.compileGroup == "priority"
|
||||||
compilerUrl = Settings.apis.clsi_priority.url
|
compilerUrl = Settings.apis.clsi_priority.url
|
||||||
else
|
else
|
||||||
|
@ -123,9 +147,11 @@ module.exports = CompileController =
|
||||||
oneMinute = 60 * 1000
|
oneMinute = 60 * 1000
|
||||||
# the base request
|
# the base request
|
||||||
options = { url: url, method: req.method, timeout: oneMinute, jar : jar }
|
options = { url: url, method: req.method, timeout: oneMinute, jar : jar }
|
||||||
|
# add any provided query string
|
||||||
|
options.qs = qs if qs?
|
||||||
# if we have a build parameter, pass it through to the clsi
|
# if we have a build parameter, pass it through to the clsi
|
||||||
if req.query?.pdfng && req.query?.build? # only for new pdf viewer
|
if req.query?.pdfng && req.query?.build? # only for new pdf viewer
|
||||||
options.qs = {}
|
options.qs ?= {}
|
||||||
options.qs.build = req.query.build
|
options.qs.build = req.query.build
|
||||||
# if we are byte serving pdfs, pass through If-* and Range headers
|
# if we are byte serving pdfs, pass through If-* and Range headers
|
||||||
# do not send any others, there's a proxying loop if Host: is passed!
|
# do not send any others, there's a proxying loop if Host: is passed!
|
||||||
|
|
|
@ -125,8 +125,8 @@ module.exports = class Router
|
||||||
), AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.getFileFromClsi
|
), AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.getFileFromClsi
|
||||||
|
|
||||||
webRouter.delete "/project/:Project_id/output", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.deleteAuxFiles
|
webRouter.delete "/project/:Project_id/output", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.deleteAuxFiles
|
||||||
webRouter.get "/project/:Project_id/sync/code", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.proxySync
|
webRouter.get "/project/:Project_id/sync/code", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.proxySyncCode
|
||||||
webRouter.get "/project/:Project_id/sync/pdf", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.proxySync
|
webRouter.get "/project/:Project_id/sync/pdf", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.proxySyncPdf
|
||||||
webRouter.get "/project/:Project_id/wordcount", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.wordCount
|
webRouter.get "/project/:Project_id/wordcount", AuthorizationMiddlewear.ensureUserCanReadProject, CompileController.wordCount
|
||||||
|
|
||||||
webRouter.delete '/Project/:Project_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ProjectController.deleteProject
|
webRouter.delete '/Project/:Project_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ProjectController.deleteProject
|
||||||
|
|
Loading…
Reference in a new issue