diff --git a/services/web/app/src/Features/Compile/CompileController.js b/services/web/app/src/Features/Compile/CompileController.js index 2fb030e28c..1c6e3d1867 100644 --- a/services/web/app/src/Features/Compile/CompileController.js +++ b/services/web/app/src/Features/Compile/CompileController.js @@ -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,15 +385,19 @@ module.exports = CompileController = { if (error != null) { return next(error) } - const url = CompileController._getUrl(project_id, user_id, 'sync/pdf') - const destination = { url, qs: { page, h, v } } - return CompileController.proxyToClsi( - project_id, - destination, - req, - res, - next - ) + 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, imageName } } + return CompileController.proxyToClsi( + project_id, + destination, + req, + res, + next + ) + }) }) }, @@ -417,15 +429,19 @@ module.exports = CompileController = { if (error != null) { return next(error) } - const url = CompileController._getUrl(project_id, user_id, 'sync/code') - const destination = { url, qs: { file, line, column } } - return CompileController.proxyToClsi( - project_id, - destination, - req, - res, - next - ) + 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, imageName } } + return CompileController.proxyToClsi( + project_id, + destination, + req, + res, + next + ) + }) }) }, diff --git a/services/web/test/unit/src/Compile/CompileControllerTests.js b/services/web/test/unit/src/Compile/CompileControllerTests.js index 95529d012f..afdd694626 100644 --- a/services/web/test/unit/src/Compile/CompileControllerTests.js +++ b/services/web/test/unit/src/Compile/CompileControllerTests.js @@ -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() {