allow fetching of export zips

This commit is contained in:
hugh-obrien 2018-07-30 19:14:59 +01:00
parent 3cf060dbac
commit 3532a29d50
3 changed files with 24 additions and 0 deletions

View file

@ -37,3 +37,10 @@ module.exports =
status_detail: parsed_export.status_detail status_detail: parsed_export.status_detail
} }
res.send export_json: json res.send export_json: json
exportZip: (req, res) ->
{export_id} = req.params
ExportsHandler.fetchZip export_id, (err, export_zip_url) ->
return err if err?
res.redirect export_zip_url

View file

@ -115,3 +115,19 @@ module.exports = ExportsHandler = self =
err = new Error("v1 export returned a failure status code: #{res.statusCode}") err = new Error("v1 export returned a failure status code: #{res.statusCode}")
logger.err err:err, export:export_id, "v1 export returned failure status code: #{res.statusCode}" logger.err err:err, export:export_id, "v1 export returned failure status code: #{res.statusCode}"
callback err callback err
fetchZip: (export_id, callback=(err, zip_url) ->) ->
console.log("#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}/zip_url")
request.get {
url: "#{settings.apis.v1.url}/api/v1/sharelatex/exports/#{export_id}/zip_url"
auth: {user: settings.apis.v1.user, pass: settings.apis.v1.pass }
}, (err, res, body) ->
if err?
logger.err err:err, export:export_id, "error making request to v1 export"
callback err
else if 200 <= res.statusCode < 300
callback null, body
else
err = new Error("v1 export returned a failure status code: #{res.statusCode}")
logger.err err:err, export:export_id, "v1 export zip fetch returned failure status code: #{res.statusCode}"
callback err

View file

@ -245,6 +245,7 @@ module.exports = class Router
webRouter.post '/project/:project_id/export/:brand_variation_id', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportProject 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', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportStatus
webRouter.get '/project/:project_id/export/:export_id/zip', AuthorizationMiddlewear.ensureUserCanAdminProject, ExportsController.exportZip
webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject webRouter.get '/Project/:Project_id/download/zip', AuthorizationMiddlewear.ensureUserCanReadProject, ProjectDownloadsController.downloadProject
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects