2014-02-19 08:02:53 -05:00
|
|
|
exec = require('child_process').exec
|
2014-02-14 11:39:05 -05:00
|
|
|
logger = require("logger-sharelatex")
|
2019-01-07 10:54:24 -05:00
|
|
|
Settings = require "settings-sharelatex"
|
2014-02-14 11:39:05 -05:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
compressPng: (localPath, callback)->
|
|
|
|
startTime = new Date()
|
2014-02-19 08:02:53 -05:00
|
|
|
logger.log localPath:localPath, "optimising png path"
|
|
|
|
args = "optipng #{localPath}"
|
|
|
|
opts =
|
2016-12-13 07:43:57 -05:00
|
|
|
timeout: 30 * 1000
|
2014-03-04 07:44:16 -05:00
|
|
|
killSignal: "SIGKILL"
|
2019-01-07 10:54:24 -05:00
|
|
|
if !Settings.enableConversions
|
|
|
|
error = new Error("Image conversions are disabled")
|
|
|
|
return callback(error)
|
2014-02-19 09:01:53 -05:00
|
|
|
exec args, opts,(err, stdout, stderr)->
|
2017-06-22 10:28:08 -04:00
|
|
|
if err? and err.signal == 'SIGKILL'
|
|
|
|
logger.warn {err: err, stderr: stderr, localPath: localPath}, "optimiser timeout reached"
|
|
|
|
err = null
|
|
|
|
else if err?
|
|
|
|
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"
|
2014-03-04 07:44:16 -05:00
|
|
|
callback(err)
|