mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
[filestore] convert to ES modules GitOrigin-RevId: 404905973548bb6e437fff66b368e87be8249b73
35 lines
732 B
JavaScript
35 lines
732 B
JavaScript
import logger from '@overleaf/logger'
|
|
import metrics from '@overleaf/metrics'
|
|
import { callbackify } from 'node:util'
|
|
import SafeExec from './SafeExec.js'
|
|
|
|
export default {
|
|
compressPng: callbackify(compressPng),
|
|
promises: {
|
|
compressPng,
|
|
},
|
|
}
|
|
|
|
async function compressPng(localPath, callback) {
|
|
const timer = new metrics.Timer('compressPng')
|
|
const args = ['optipng', localPath]
|
|
const opts = {
|
|
timeout: 30 * 1000,
|
|
killSignal: 'SIGKILL',
|
|
}
|
|
|
|
try {
|
|
await SafeExec.promises(args, opts)
|
|
timer.done()
|
|
} catch (err) {
|
|
if (err.code === 'SIGKILL') {
|
|
logger.warn(
|
|
{ err, stderr: err.stderr, localPath },
|
|
'optimiser timeout reached'
|
|
)
|
|
} else {
|
|
throw err
|
|
}
|
|
}
|
|
}
|