mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
converted get stream to use knox, test to see if it is more robust
This commit is contained in:
parent
3f54688ec8
commit
fada5ecaf4
2 changed files with 24 additions and 18 deletions
|
@ -8,7 +8,6 @@ knox = require("knox")
|
|||
path = require("path")
|
||||
LocalFileWriter = require("./LocalFileWriter")
|
||||
_ = require("underscore")
|
||||
|
||||
|
||||
thirtySeconds = 30 * 1000
|
||||
|
||||
|
@ -58,13 +57,19 @@ module.exports =
|
|||
return callback(err)
|
||||
@sendFileToS3 bucketName, key, fsPath, callback
|
||||
|
||||
getFileStream: (bucketName, key, callback)->
|
||||
getFileStream: (bucketName, key, callback = (err, res)->)->
|
||||
logger.log bucketName:bucketName, key:key, "getting file from s3"
|
||||
options = buildDefaultOptions(bucketName, "get", key)
|
||||
readStream = request(options)
|
||||
readStream.on "error", (err)->
|
||||
s3Client = knox.createClient
|
||||
key: settings.s3.key
|
||||
secret: settings.s3.secret
|
||||
bucket: bucketName
|
||||
s3Stream = s3Client.get(key)
|
||||
s3Stream.end()
|
||||
s3Stream.on 'response', (res) ->
|
||||
callback null, res
|
||||
s3Stream.on 'error', (err) ->
|
||||
logger.err err:err, bucketName:bucketName, key:key, "error getting file stream from s3"
|
||||
callback null, readStream
|
||||
callback err
|
||||
|
||||
copyFile: (bucketName, sourceKey, destKey, callback)->
|
||||
logger.log bucketName:bucketName, sourceKey:sourceKey, destKey:destKey, "copying file in s3"
|
||||
|
|
|
@ -20,6 +20,7 @@ describe "s3WrapperTests", ->
|
|||
copyFile:sinon.stub()
|
||||
list: sinon.stub()
|
||||
deleteMultiple: sinon.stub()
|
||||
get: sinon.stub()
|
||||
@knox =
|
||||
createClient: sinon.stub().returns(@stubbedKnoxClient)
|
||||
@LocalFileWriter =
|
||||
|
@ -36,19 +37,19 @@ describe "s3WrapperTests", ->
|
|||
@bucketName = "my-bucket"
|
||||
@error = "my errror"
|
||||
|
||||
describe "Pipe to dest", ->
|
||||
|
||||
it "should use correct options", (done)->
|
||||
|
||||
stubbedReadStream = {on:->}
|
||||
dest = {my:"object"}
|
||||
@request = (opts)=>
|
||||
return stubbedReadStream
|
||||
@requires["request"] = @request
|
||||
describe "getFileStream", ->
|
||||
beforeEach ->
|
||||
@s3Wrapper = SandboxedModule.require modulePath, requires: @requires
|
||||
@s3Wrapper.getFileStream @bucketName, @key, (err, readStream)->
|
||||
readStream.should.equal stubbedReadStream
|
||||
done()
|
||||
|
||||
|
||||
it "should use correct key", (done)->
|
||||
@stubbedKnoxClient.get.returns(
|
||||
on:->
|
||||
end:->
|
||||
)
|
||||
@s3Wrapper.getFileStream @bucketName, @key, @fsPath, (err)=>
|
||||
@stubbedKnoxClient.get.calledWith(@key).should.equal true
|
||||
done()
|
||||
|
||||
describe "sendFileToS3", ->
|
||||
|
||||
|
|
Loading…
Reference in a new issue