Merge pull request #3850 from overleaf/jpa-set-image-name-for-synctex

[misc] include the projects imageName as part of synctex requests

GitOrigin-RevId: 99f05cf67859b1e43c2342fc0c2575ddd661a57d
This commit is contained in:
Simon Detheridge 2021-03-30 16:40:36 +01:00 committed by Copybot
parent 12f3e8d6bb
commit ae0805e684
2 changed files with 101 additions and 18 deletions

View file

@ -33,6 +33,14 @@ const Path = require('path')
const COMPILE_TIMEOUT_MS = 10 * 60 * 1000 const COMPILE_TIMEOUT_MS = 10 * 60 * 1000
function getImageNameForProject(projectId, callback) {
ProjectGetter.getProject(projectId, { imageName: 1 }, (err, project) => {
if (err) return callback(err)
if (!project) return callback(new Error('project not found'))
callback(null, project.imageName)
})
}
module.exports = CompileController = { module.exports = CompileController = {
compile(req, res, next) { compile(req, res, next) {
res.setTimeout(COMPILE_TIMEOUT_MS) res.setTimeout(COMPILE_TIMEOUT_MS)
@ -377,15 +385,19 @@ module.exports = CompileController = {
if (error != null) { if (error != null) {
return next(error) return next(error)
} }
const url = CompileController._getUrl(project_id, user_id, 'sync/pdf') getImageNameForProject(project_id, (error, imageName) => {
const destination = { url, qs: { page, h, v } } if (error) return next(error)
return CompileController.proxyToClsi(
project_id, const url = CompileController._getUrl(project_id, user_id, 'sync/pdf')
destination, const destination = { url, qs: { page, h, v, imageName } }
req, return CompileController.proxyToClsi(
res, project_id,
next destination,
) req,
res,
next
)
})
}) })
}, },
@ -417,15 +429,19 @@ module.exports = CompileController = {
if (error != null) { if (error != null) {
return next(error) return next(error)
} }
const url = CompileController._getUrl(project_id, user_id, 'sync/code') getImageNameForProject(project_id, (error, imageName) => {
const destination = { url, qs: { file, line, column } } if (error) return next(error)
return CompileController.proxyToClsi(
project_id, const url = CompileController._getUrl(project_id, user_id, 'sync/code')
destination, const destination = { url, qs: { file, line, column, imageName } }
req, return CompileController.proxyToClsi(
res, project_id,
next destination,
) req,
res,
next
)
})
}) })
}, },

View file

@ -413,6 +413,73 @@ describe('CompileController', function() {
}) })
}) })
}) })
describe('proxySyncCode', function() {
let file, line, column, imageName
beforeEach(function(done) {
this.req.params = { Project_id: this.project_id }
file = 'main.tex'
line = String(Date.now())
column = String(Date.now() + 1)
this.req.query = { file, line, column }
imageName = 'foo/bar:tag-0'
this.ProjectGetter.getProject = sinon.stub().yields(null, { imageName })
this.next.callsFake(done)
this.res.callback = done
this.CompileController.proxyToClsi = sinon.stub().callsFake(() => done())
this.CompileController.proxySyncCode(this.req, this.res, this.next)
})
it('should proxy the request with an imageName', function() {
expect(this.CompileController.proxyToClsi).to.have.been.calledWith(
this.project_id,
{
url: `/project/${this.project_id}/user/${this.user_id}/sync/code`,
qs: { file, line, column, imageName }
},
this.req,
this.res,
this.next
)
})
})
describe('proxySyncPdf', function() {
let page, h, v, imageName
beforeEach(function(done) {
this.req.params = { Project_id: this.project_id }
page = String(Date.now())
h = String(Math.random())
v = String(Math.random())
this.req.query = { page, h, v }
imageName = 'foo/bar:tag-1'
this.ProjectGetter.getProject = sinon.stub().yields(null, { imageName })
this.next.callsFake(done)
this.res.callback = done
this.CompileController.proxyToClsi = sinon.stub().callsFake(() => done())
this.CompileController.proxySyncPdf(this.req, this.res, this.next)
})
it('should proxy the request with an imageName', function() {
expect(this.CompileController.proxyToClsi).to.have.been.calledWith(
this.project_id,
{
url: `/project/${this.project_id}/user/${this.user_id}/sync/pdf`,
qs: { page, h, v, imageName }
},
this.req,
this.res,
this.next
)
})
})
describe('proxyToClsi', function() { describe('proxyToClsi', function() {
beforeEach(function() { beforeEach(function() {