2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2020-11-25 06:57:23 -05:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2024-11-08 05:21:56 -05:00
|
|
|
const { callbackify } = require('node:util')
|
2019-12-19 11:56:03 -05:00
|
|
|
const safeExec = require('./SafeExec').promises
|
2014-02-14 11:39:05 -05:00
|
|
|
|
2019-12-16 05:42:31 -05:00
|
|
|
module.exports = {
|
2019-12-19 11:56:03 -05:00
|
|
|
compressPng: callbackify(compressPng),
|
|
|
|
promises: {
|
2021-07-13 07:04:46 -04:00
|
|
|
compressPng,
|
|
|
|
},
|
2019-12-19 11:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function compressPng(localPath, callback) {
|
|
|
|
const timer = new metrics.Timer('compressPng')
|
|
|
|
const args = ['optipng', localPath]
|
|
|
|
const opts = {
|
|
|
|
timeout: 30 * 1000,
|
2021-07-13 07:04:46 -04:00
|
|
|
killSignal: 'SIGKILL',
|
2019-12-19 11:56:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await safeExec(args, opts)
|
|
|
|
timer.done()
|
|
|
|
} catch (err) {
|
|
|
|
if (err.code === 'SIGKILL') {
|
|
|
|
logger.warn(
|
|
|
|
{ err, stderr: err.stderr, localPath },
|
|
|
|
'optimiser timeout reached'
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
throw err
|
2019-12-16 05:42:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|