Merge pull request #978 from sharelatex/hb-use-exports-for-pdf-from-publish-modal

Generic Zip or Pdf Exports endpoint
This commit is contained in:
Hugh O'Brien 2018-10-08 10:13:18 +01:00 committed by GitHub
commit cc962c3e6f
4 changed files with 10 additions and 10 deletions

View file

@ -46,10 +46,11 @@ module.exports =
}
res.send export_json: json
exportZip: (req, res) ->
{export_id} = req.params
exportDownload: (req, res) ->
{type, export_id} = req.params
AuthenticationController.getLoggedInUserId(req)
ExportsHandler.fetchZip export_id, (err, export_zip_url) ->
ExportsHandler.fetchDownload export_id, type, (err, export_file_url) ->
return err if err?
res.redirect export_zip_url
res.redirect export_file_url

View file

@ -122,10 +122,9 @@ module.exports = ExportsHandler = self =
logger.err err:err, export:export_id, "v1 export returned failure status code: #{res.statusCode}"
callback err
fetchZip: (export_id, callback=(err, zip_url) ->) ->
console.log("#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}/zip_url")
fetchDownload: (export_id, type, callback=(err, file_url) ->) ->
request.get {
url: "#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}/zip_url"
url: "#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}/#{type}_url"
auth: {user: settings.apis.v1.user, pass: settings.apis.v1.pass }
}, (err, res, body) ->
if err?

View file

@ -247,7 +247,7 @@ module.exports = class Router
webRouter.post '/project/:project_id/export/:brand_variation_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportProject
webRouter.get '/project/:project_id/export/:export_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportStatus
webRouter.get '/project/:project_id/export/:export_id/zip', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportZip
webRouter.get '/project/:project_id/export/:export_id/:type', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportDownload
webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects

View file

@ -301,7 +301,7 @@ describe 'ExportsHandler', ->
@callback.calledWith(null, { body: @body })
.should.equal true
describe 'fetchZip', ->
describe 'fetchDownload', ->
beforeEach (done) ->
@settings.apis =
v1:
@ -316,7 +316,7 @@ describe 'ExportsHandler', ->
describe "when all goes well", ->
beforeEach (done) ->
@stubRequest.get = @stubGet
@ExportsHandler.fetchZip @export_id, (error, body) =>
@ExportsHandler.fetchDownload @export_id, 'zip', (error, body) =>
@callback(error, body)
done()