mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Revert "Send content-length header when getting file"
This reverts commit 6f5f7a98fd3ce53091aacc744f43c7704ba73461.
This commit is contained in:
parent
daf4f1ffd4
commit
e529875245
7 changed files with 25 additions and 38 deletions
|
@ -28,13 +28,12 @@ module.exports =
|
||||||
getFileStream: (location, name, callback = (err, res)->)->
|
getFileStream: (location, name, callback = (err, res)->)->
|
||||||
filteredName = filterName name
|
filteredName = filterName name
|
||||||
logger.log location:location, name:filteredName, "getting file"
|
logger.log location:location, name:filteredName, "getting file"
|
||||||
path = "#{location}/#{filteredName}"
|
sourceStream = fs.createReadStream "#{location}/#{filteredName}"
|
||||||
fs.stat path, (error, stat) ->
|
sourceStream.on 'error', (err) ->
|
||||||
sourceStream = fs.createReadStream path
|
logger.err err:err, location:location, name:name, "Error reading from file"
|
||||||
sourceStream.on 'error', (err) ->
|
callback err
|
||||||
logger.err err:err, location:location, name:name, "Error reading from file"
|
callback null,sourceStream
|
||||||
callback err
|
|
||||||
callback null, sourceStream, stat.size
|
|
||||||
|
|
||||||
copyFile: (location, fromName, toName, callback = (err)->)->
|
copyFile: (location, fromName, toName, callback = (err)->)->
|
||||||
filteredFromName=filterName fromName
|
filteredFromName=filterName fromName
|
||||||
|
|
|
@ -12,7 +12,7 @@ module.exports =
|
||||||
{key, bucket} = req
|
{key, bucket} = req
|
||||||
{format, style} = req.query
|
{format, style} = req.query
|
||||||
logger.log key:key, bucket:bucket, format:format, style:style, "reciving request to get file"
|
logger.log key:key, bucket:bucket, format:format, style:style, "reciving request to get file"
|
||||||
FileHandler.getFile bucket, key, {format:format,style:style}, (err, fileStream, size)->
|
FileHandler.getFile bucket, key, {format:format,style:style}, (err, fileStream)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, key:key, bucket:bucket, format:format, style:style, "problem getting file"
|
logger.err err:err, key:key, bucket:bucket, format:format, style:style, "problem getting file"
|
||||||
if !res.finished and res?.send?
|
if !res.finished and res?.send?
|
||||||
|
@ -22,7 +22,6 @@ module.exports =
|
||||||
res.send 200
|
res.send 200
|
||||||
else
|
else
|
||||||
logger.log key:key, bucket:bucket, format:format, style:style, "sending file to response"
|
logger.log key:key, bucket:bucket, format:format, style:style, "sending file to response"
|
||||||
res.header("Content-Length", size)
|
|
||||||
fileStream.pipe res
|
fileStream.pipe res
|
||||||
|
|
||||||
insertFile: (req, res)->
|
insertFile: (req, res)->
|
||||||
|
|
|
@ -22,20 +22,20 @@ module.exports =
|
||||||
(done)-> PersistorManager.deleteFile bucket, convetedKey, done
|
(done)-> PersistorManager.deleteFile bucket, convetedKey, done
|
||||||
], callback
|
], callback
|
||||||
|
|
||||||
getFile: (bucket, key, opts = {}, callback = (err, fileStream, size) ->)->
|
getFile: (bucket, key, opts = {}, callback)->
|
||||||
logger.log bucket:bucket, key:key, opts:opts, "getting file"
|
logger.log bucket:bucket, key:key, opts:opts, "getting file"
|
||||||
if !opts.format? and !opts.style?
|
if !opts.format? and !opts.style?
|
||||||
@_getStandardFile bucket, key, opts, callback
|
@_getStandardFile bucket, key, opts, callback
|
||||||
else
|
else
|
||||||
@_getConvertedFile bucket, key, opts, callback
|
@_getConvertedFile bucket, key, opts, callback
|
||||||
|
|
||||||
_getStandardFile: (bucket, key, opts, callback = (err, fileStream, size) ->)->
|
_getStandardFile: (bucket, key, opts, callback)->
|
||||||
PersistorManager.getFileStream bucket, key, (err, fileStream, size)->
|
PersistorManager.getFileStream bucket, key, (err, fileStream)->
|
||||||
if err?
|
if err?
|
||||||
logger.err bucket:bucket, key:key, opts:opts, "error getting fileStream"
|
logger.err bucket:bucket, key:key, opts:opts, "error getting fileStream"
|
||||||
callback err, fileStream, size
|
callback err, fileStream
|
||||||
|
|
||||||
_getConvertedFile: (bucket, key, opts, callback = (err, fileStream, size) ->)->
|
_getConvertedFile: (bucket, key, opts, callback)->
|
||||||
convetedKey = KeyBuilder.addCachingToKey(key, opts)
|
convetedKey = KeyBuilder.addCachingToKey(key, opts)
|
||||||
PersistorManager.checkIfFileExists bucket, convetedKey, (err, exists)=>
|
PersistorManager.checkIfFileExists bucket, convetedKey, (err, exists)=>
|
||||||
if exists
|
if exists
|
||||||
|
|
|
@ -67,7 +67,7 @@ module.exports =
|
||||||
return callback(err)
|
return callback(err)
|
||||||
@sendFile bucketName, key, fsPath, callback
|
@sendFile bucketName, key, fsPath, callback
|
||||||
|
|
||||||
getFileStream: (bucketName, key, callback = (err, res, size)->)->
|
getFileStream: (bucketName, key, callback = (err, res)->)->
|
||||||
logger.log bucketName:bucketName, key:key, "getting file from s3"
|
logger.log bucketName:bucketName, key:key, "getting file from s3"
|
||||||
s3Client = knox.createClient
|
s3Client = knox.createClient
|
||||||
key: settings.filestore.s3.key
|
key: settings.filestore.s3.key
|
||||||
|
@ -76,7 +76,7 @@ module.exports =
|
||||||
s3Stream = s3Client.get(key)
|
s3Stream = s3Client.get(key)
|
||||||
s3Stream.end()
|
s3Stream.end()
|
||||||
s3Stream.on 'response', (res) ->
|
s3Stream.on 'response', (res) ->
|
||||||
callback null, res, res.headers["content-length"]
|
callback null, res
|
||||||
s3Stream.on 'error', (err) ->
|
s3Stream.on 'error', (err) ->
|
||||||
logger.err err:err, bucketName:bucketName, key:key, "error getting file stream from s3"
|
logger.err err:err, bucketName:bucketName, key:key, "error getting file stream from s3"
|
||||||
callback err
|
callback err
|
||||||
|
|
|
@ -66,12 +66,11 @@ describe "FSPersistorManagerTests", ->
|
||||||
|
|
||||||
describe "getFileStream", ->
|
describe "getFileStream", ->
|
||||||
it "should use correct file location", (done) ->
|
it "should use correct file location", (done) ->
|
||||||
@Fs.createReadStream.returns(@stream = on:->)
|
@Fs.createReadStream.returns(
|
||||||
@Fs.stat = sinon.stub().callsArgWith(1, null, { size: @size = 42 })
|
on:->
|
||||||
@FSPersistorManager.getFileStream @location, @name1, (err, res, size)=>
|
)
|
||||||
|
@FSPersistorManager.getFileStream @location, @name1, (err,res)=>
|
||||||
@Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true
|
@Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true
|
||||||
res.should.equal @stream
|
|
||||||
size.should.equal @size
|
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "copyFile", ->
|
describe "copyFile", ->
|
||||||
|
|
|
@ -43,16 +43,15 @@ describe "FileController", ->
|
||||||
project_id:@project_id
|
project_id:@project_id
|
||||||
file_id:@file_id
|
file_id:@file_id
|
||||||
@res =
|
@res =
|
||||||
header: sinon.stub()
|
setHeader: ->
|
||||||
@fileStream = {}
|
@fileStream = {}
|
||||||
|
|
||||||
describe "getFile", ->
|
describe "getFile", ->
|
||||||
|
|
||||||
it "should pipe the stream", (done)->
|
it "should pipe the stream", (done)->
|
||||||
@FileHandler.getFile.callsArgWith(3, null, @fileStream, @size = 42)
|
@FileHandler.getFile.callsArgWith(3, null, @fileStream)
|
||||||
@fileStream.pipe = (res)=>
|
@fileStream.pipe = (res)=>
|
||||||
res.should.equal @res
|
res.should.equal @res
|
||||||
res.header.calledWith("Content-Length", @size).should.equal true
|
|
||||||
done()
|
done()
|
||||||
@controller.getFile @req, @res
|
@controller.getFile @req, @res
|
||||||
|
|
||||||
|
|
|
@ -45,22 +45,13 @@ describe "S3PersistorManagerTests", ->
|
||||||
|
|
||||||
|
|
||||||
it "should use correct key", (done)->
|
it "should use correct key", (done)->
|
||||||
@response =
|
@stubbedKnoxClient.get.returns(
|
||||||
headers:
|
on:->
|
||||||
"content-length": @size = 42
|
|
||||||
|
|
||||||
@stubbedKnoxClient.get.returns(@stream =
|
|
||||||
on: (e, callback) =>
|
|
||||||
if e == "response"
|
|
||||||
callback(@response)
|
|
||||||
end:->
|
end:->
|
||||||
|
|
||||||
)
|
)
|
||||||
@S3PersistorManager.getFileStream @bucketName, @key, (err, res, size) =>
|
@S3PersistorManager.getFileStream @bucketName, @key, @fsPath, (err)=>
|
||||||
res.should.equal @response
|
@stubbedKnoxClient.get.calledWith(@key).should.equal true
|
||||||
size.should.equal @size
|
done()
|
||||||
@stubbedKnoxClient.get.calledWith(@key).should.equal true
|
|
||||||
done()
|
|
||||||
|
|
||||||
describe "sendFile", ->
|
describe "sendFile", ->
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue