Switch to using native fs.promises

This commit is contained in:
Maksim Karasev 2023-05-19 17:33:17 +03:00
parent 6a086453c6
commit e99da6e3d6
1 changed files with 3 additions and 6 deletions

View File

@ -2,8 +2,7 @@
import sharp from 'sharp';
import ffmpeg from 'fluent-ffmpeg';
import tmp from 'tmp';
import fs from 'fs';
import util from 'util';
import { promises as fs } from "fs";
import path from 'path';
import { FFMPEG_EXISTS, IMAGE_DIR } from '../utils/config';
import { getImage } from './imageService';
@ -54,8 +53,6 @@ export const getThumbnail = async (
height: number = 160,
): Promise<Buffer> => {
const image = await getImage(filename);
const readFilePromise = util.promisify(fs.readFile);
const unlinkFilePromise = util.promisify(fs.unlink);
let { imagebuffer } = image;
logger.verbose('Thumbnail cache miss.');
// Take a screenshot from videos
@ -71,8 +68,8 @@ export const getThumbnail = async (
path.join(IMAGE_DIR, filename),
tmpDir.name,
);
imagebuffer = await readFilePromise(`${tmpDir.name}/temp.png`);
await unlinkFilePromise(`${tmpDir.name}/temp.png`);
imagebuffer = await fs.readFile(`${tmpDir.name}/temp.png`);
await fs.unlink(`${tmpDir.name}/temp.png`);
} catch (e: any) {
logger.error(`${e.name}:${e.message}`);
}