- return new Promise<string>((res, rej) => {
- ffmpeg(fromPath)
- .on('error', rej)
- .on('end', () => res(imageName))
- .thumbnail(options)
- })
+ try {
+ await new Promise<string>((res, rej) => {
+ ffmpeg(fromPath)
+ .on('error', rej)
+ .on('end', () => res(imageName))
+ .thumbnail(options)
+ })
+
+ const destination = join(folder, imageName)
+ await processImage({ path: pendingImagePath }, destination, size)
+ } catch (err) {
+ logger.error('Cannot generate image from video %s.', fromPath, { err })
+
+ try {
+ await unlinkPromise(pendingImagePath)
+ } catch (err) {
+ logger.debug('Cannot remove pending image path after generation error.', { err })
+ }
+ }