Răsfoiți Sursa

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
Simon Detheridge 5 ani în urmă
părinte
comite
ae0805e684

+ 34 - 18
services/web/app/src/Features/Compile/CompileController.js

@@ -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')
-      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) {
       if (error != null) {
         return next(error)
         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
+        )
+      })
     })
     })
   },
   },
 
 

+ 67 - 0
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() {
   describe('proxyToClsi', function() {
     beforeEach(function() {
     beforeEach(function() {