2019-12-16 05:24:35 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const {
|
|
|
|
exec
|
|
|
|
} = require('child_process');
|
|
|
|
const logger = require("logger-sharelatex");
|
|
|
|
const Settings = require("settings-sharelatex");
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:24:35 -05:00
|
|
|
module.exports = {
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:24:35 -05:00
|
|
|
compressPng(localPath, callback){
|
|
|
|
const startTime = new Date();
|
|
|
|
logger.log({localPath}, "optimising png path");
|
|
|
|
const args = `optipng ${localPath}`;
|
|
|
|
const opts = {
|
|
|
|
timeout: 30 * 1000,
|
2014-03-04 07:44:16 -05:00
|
|
|
killSignal: "SIGKILL"
|
2019-12-16 05:24:35 -05:00
|
|
|
};
|
|
|
|
if (!Settings.enableConversions) {
|
|
|
|
const error = new Error("Image conversions are disabled");
|
|
|
|
return callback(error);
|
|
|
|
}
|
|
|
|
return exec(args, opts,function(err, stdout, stderr){
|
|
|
|
if ((err != null) && (err.signal === 'SIGKILL')) {
|
|
|
|
logger.warn({err, stderr, localPath}, "optimiser timeout reached");
|
|
|
|
err = null;
|
|
|
|
} else if (err != null) {
|
|
|
|
logger.err({err, stderr, localPath}, "something went wrong converting compressPng");
|
|
|
|
} else {
|
|
|
|
logger.log({localPath}, "finished compressPng file");
|
|
|
|
}
|
|
|
|
return callback(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|