mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
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:
parent
12f3e8d6bb
commit
ae0805e684
2 changed files with 101 additions and 18 deletions
|
@ -33,6 +33,14 @@ const Path = require('path')
|
|||
|
||||
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 = {
|
||||
compile(req, res, next) {
|
||||
res.setTimeout(COMPILE_TIMEOUT_MS)
|
||||
|
@ -377,8 +385,11 @@ module.exports = CompileController = {
|
|||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
getImageNameForProject(project_id, (error, imageName) => {
|
||||
if (error) return next(error)
|
||||
|
||||
const url = CompileController._getUrl(project_id, user_id, 'sync/pdf')
|
||||
const destination = { url, qs: { page, h, v } }
|
||||
const destination = { url, qs: { page, h, v, imageName } }
|
||||
return CompileController.proxyToClsi(
|
||||
project_id,
|
||||
destination,
|
||||
|
@ -387,6 +398,7 @@ module.exports = CompileController = {
|
|||
next
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
proxySyncCode(req, res, next) {
|
||||
|
@ -417,8 +429,11 @@ module.exports = CompileController = {
|
|||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
getImageNameForProject(project_id, (error, imageName) => {
|
||||
if (error) return next(error)
|
||||
|
||||
const url = CompileController._getUrl(project_id, user_id, 'sync/code')
|
||||
const destination = { url, qs: { file, line, column } }
|
||||
const destination = { url, qs: { file, line, column, imageName } }
|
||||
return CompileController.proxyToClsi(
|
||||
project_id,
|
||||
destination,
|
||||
|
@ -427,6 +442,7 @@ module.exports = CompileController = {
|
|||
next
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
proxyToClsi(project_id, url, req, res, next) {
|
||||
|
|
|
@ -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() {
|
||||
beforeEach(function() {
|
||||
|
|
Loading…
Reference in a new issue