mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
changed file converted to use child process with nice
This commit is contained in:
parent
1ff5a5adb8
commit
f99a6dc39b
5 changed files with 25 additions and 28 deletions
|
@ -2,7 +2,7 @@ easyimage = require("easyimage")
|
|||
_ = require("underscore")
|
||||
metrics = require("./metrics")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
exec = require('child_process').exec
|
||||
approvedFormats = ["png"]
|
||||
|
||||
module.exports =
|
||||
|
@ -15,10 +15,8 @@ module.exports =
|
|||
if !_.include approvedFormats, requestedFormat
|
||||
err = new Error("invalid format requested")
|
||||
return callback err
|
||||
args =
|
||||
src: sourcePath
|
||||
dst: destPath
|
||||
easyimage.convert args, (err)->
|
||||
args = "nice convert -flatten -density 300 #{sourcePath} #{destPath}"
|
||||
exec args, (err, stdout, stderr)->
|
||||
timer.done()
|
||||
callback(err, destPath)
|
||||
|
||||
|
@ -31,8 +29,8 @@ module.exports =
|
|||
dst: destPath
|
||||
width: 424
|
||||
height: 300
|
||||
args = "convert -flatten -background white -resize 300x -density 300 #{sourcePath} #{destPath}"
|
||||
easyimage.exec args, (err)->
|
||||
args = "nice convert -flatten -background white -resize 300x -density 300 #{sourcePath} #{destPath}"
|
||||
exec args, (err, stdout, stderr)->
|
||||
callback(err, destPath)
|
||||
|
||||
preview: (sourcePath, callback)->
|
||||
|
@ -44,6 +42,6 @@ module.exports =
|
|||
dst: destPath
|
||||
width: 600
|
||||
height: 849
|
||||
args = "convert -flatten -background white -resize 600x -density 300 #{sourcePath} #{destPath}"
|
||||
easyimage.exec args, (err)->
|
||||
args = "nice convert -flatten -background white -resize 600x -density 300 #{sourcePath} #{destPath}"
|
||||
exec args, (err, stdout, stderr)->
|
||||
callback(err, destPath)
|
||||
|
|
|
@ -99,6 +99,8 @@ module.exports =
|
|||
request options, (err, res)->
|
||||
if err?
|
||||
logger.err err:err, res:res, bucketName:bucketName, key:key, "something went wrong copying file in aws"
|
||||
if !res?
|
||||
logger.err err:err, res:res, bucketName:bucketName, key:key, "no response object returned when checking if file exists"
|
||||
exists = res.statusCode == 200
|
||||
logger.log bucketName:bucketName, key:key, exists:exists, "checked if file exsists in s3"
|
||||
callback(err, exists)
|
||||
|
|
|
@ -13,7 +13,6 @@ module.exports =
|
|||
user_files: ""
|
||||
template_files: ""
|
||||
|
||||
|
||||
# Filestore health check
|
||||
# ----------------------
|
||||
# Project and file details to check in filestore when calling /health_check
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
"knox": "~0.8.8",
|
||||
"node-uuid": "~1.4.1",
|
||||
"underscore": "~1.5.2",
|
||||
"easyimage": "~0.1.6",
|
||||
"express": "~3.4.8",
|
||||
"longjohn": "~0.2.2",
|
||||
"async": "~0.2.10",
|
||||
"pngcrush": "0.0.3",
|
||||
"stream-buffers": "~0.2.5"
|
||||
"stream-buffers": "~0.2.5",
|
||||
"node-transloadit": "0.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"sinon": "",
|
||||
|
|
|
@ -13,8 +13,11 @@ describe "FileConverter", ->
|
|||
@easyimage =
|
||||
convert:sinon.stub()
|
||||
exec: sinon.stub()
|
||||
@child_process =
|
||||
exec : sinon.stub()
|
||||
@converter = SandboxedModule.require modulePath, requires:
|
||||
"easyimage":@easyimage
|
||||
'child_process': @child_process
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
|
@ -26,48 +29,43 @@ describe "FileConverter", ->
|
|||
describe "convert", ->
|
||||
|
||||
it "should convert the source to the requested format", (done)->
|
||||
@easyimage.convert.callsArgWith(1)
|
||||
@child_process.exec.callsArgWith(1)
|
||||
@converter.convert @sourcePath, @format, (err)=>
|
||||
args = @easyimage.convert.args[0][0]
|
||||
args.src.should.equal @sourcePath+"[0]"
|
||||
args.dst.should.equal "#{@sourcePath}.#{@format}"
|
||||
args = @child_process.exec.args[0][0]
|
||||
args.indexOf(@sourcePath).should.not.equal -1
|
||||
args.indexOf(@format).should.not.equal -1
|
||||
done()
|
||||
|
||||
|
||||
it "should return the dest path", (done)->
|
||||
@easyimage.convert.callsArgWith(1)
|
||||
@child_process.exec.callsArgWith(1)
|
||||
@converter.convert @sourcePath, @format, (err, destPath)=>
|
||||
destPath.should.equal "#{@sourcePath}.#{@format}"
|
||||
done()
|
||||
|
||||
it "should return the error from convert", (done)->
|
||||
@easyimage.convert.callsArgWith(1, @error)
|
||||
@child_process.exec.callsArgWith(1, @error)
|
||||
@converter.convert @sourcePath, @format, (err)=>
|
||||
err.should.equal @error
|
||||
done()
|
||||
|
||||
it "should not accapt an non aproved format", (done)->
|
||||
@easyimage.convert.callsArgWith(1)
|
||||
@child_process.exec.callsArgWith(1)
|
||||
@converter.convert @sourcePath, "ahhhhh", (err)=>
|
||||
expect(err).to.exist
|
||||
done()
|
||||
|
||||
|
||||
describe "thumbnail", ->
|
||||
it "should call easy image resize with args", (done)->
|
||||
@easyimage.exec.callsArgWith(1)
|
||||
@child_process.exec.callsArgWith(1)
|
||||
@converter.thumbnail @sourcePath, (err)=>
|
||||
args = @easyimage.exec.args[0][0]
|
||||
args = @child_process.exec.args[0][0]
|
||||
args.indexOf(@sourcePath).should.not.equal -1
|
||||
done()
|
||||
|
||||
it "should compress the png", ()->
|
||||
|
||||
|
||||
describe "preview", ->
|
||||
it "should call easy image resize with args", (done)->
|
||||
@easyimage.exec.callsArgWith(1)
|
||||
@child_process.exec.callsArgWith(1)
|
||||
@converter.preview @sourcePath, (err)=>
|
||||
args = @easyimage.exec.args[0][0]
|
||||
args = @child_process.exec.args[0][0]
|
||||
args.indexOf(@sourcePath).should.not.equal -1
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue