Merge pull request #792 from sharelatex/hb-fetch-export-zips

Fetch export zips
This commit is contained in:
Hugh O'Brien 2018-08-02 13:50:11 +01:00 committed by GitHub
commit 22b664da1a
4 changed files with 54 additions and 0 deletions

View file

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

View file

@ -118,3 +118,19 @@ module.exports = ExportsHandler = self =
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}"
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.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/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects

View file

@ -281,3 +281,32 @@ describe 'ExportsHandler', ->
@callback.calledWith(null, { body: @body })
.should.equal true
describe 'fetchZip', ->
beforeEach (done) ->
@settings.apis =
v1:
url: 'http://localhost:5000'
user: 'overleaf'
pass: 'pass'
@export_id = 897
@body = "https://writelatex-conversions-dev.s3.amazonaws.com/exports/ieee_latexqc/tnb/2912/xggmprcrpfwbsnqzqqmvktddnrbqkqkr.zip?X-Amz-Expires=14400&X-Amz-Date=20180730T181003Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJDGDIJFGLNVGZH6A/20180730/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=dec990336913cef9933f0e269afe99722d7ab2830ebf2c618a75673ee7159fee"
@stubGet = sinon.stub().yields(null, {statusCode: 200}, { body: @body })
done()
describe "when all goes well", ->
beforeEach (done) ->
@stubRequest.get = @stubGet
@ExportsHandler.fetchZip @export_id, (error, body) =>
@callback(error, body)
done()
it 'should issue the request', ->
expect(@stubGet.getCall(0).args[0]).to.deep.equal
url: @settings.apis.v1.url + '/api/v1/sharelatex/exports/' + @export_id + '/zip_url'
auth:
user: @settings.apis.v1.user
pass: @settings.apis.v1.pass
it 'should return the v1 export id', ->
@callback.calledWith(null, { body: @body })
.should.equal true