overleaf/services/filestore/app/coffee/ImageOptimiser.coffee

24 lines
704 B
CoffeeScript
Raw Normal View History

exec = require('child_process').exec
2014-02-14 11:39:05 -05:00
logger = require("logger-sharelatex")
module.exports =
compressPng: (localPath, callback)->
startTime = new Date()
logger.log localPath:localPath, "optimising png path"
args = "optipng #{localPath}"
opts =
timeout: 30 * 1000
killSignal: "SIGKILL"
2014-02-19 09:01:53 -05:00
exec args, opts,(err, stdout, stderr)->
if err?
2017-06-22 04:41:36 -04:00
if err.signal == 'SIGKILL'
logger.warn {err: err, stderr: stderr, localPath: localPath}, "optimiser timeout reached"
err = null
else
logger.err err:err, stderr:stderr, localPath:localPath, "something went wrong converting compressPng"
2014-02-19 09:01:53 -05:00
else
logger.log localPath:localPath, "finished compressPng file"
callback(err)
2014-02-14 11:39:05 -05:00