mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
refactor: remove util.promisify calls
This commit is contained in:
11
src/image.js
11
src/image.js
@@ -5,9 +5,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const winston = require('winston');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
|
||||
const file = require('./file');
|
||||
const plugins = require('./plugins');
|
||||
@@ -46,7 +43,7 @@ image.resizeImage = async function (data) {
|
||||
});
|
||||
} else {
|
||||
const sharp = requireSharp();
|
||||
const buffer = await readFileAsync(data.path);
|
||||
const buffer = await fs.promises.readFile(data.path);
|
||||
const sharpImage = sharp(buffer, {
|
||||
failOnError: true,
|
||||
});
|
||||
@@ -93,7 +90,7 @@ image.stripEXIF = async function (path) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const buffer = await readFileAsync(path);
|
||||
const buffer = await fs.promises.readFile(path);
|
||||
const sharp = requireSharp();
|
||||
await sharp(buffer, { failOnError: true }).rotate().toFile(path);
|
||||
} catch (err) {
|
||||
@@ -111,7 +108,7 @@ image.checkDimensions = async function (path) {
|
||||
};
|
||||
|
||||
image.convertImageToBase64 = async function (path) {
|
||||
return await readFileAsync(path, 'base64');
|
||||
return await fs.promises.readFile(path, 'base64');
|
||||
};
|
||||
|
||||
image.mimeFromBase64 = function (imageData) {
|
||||
@@ -132,7 +129,7 @@ image.writeImageDataToTempFile = async function (imageData) {
|
||||
|
||||
const buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
|
||||
|
||||
await writeFileAsync(filepath, buffer, { encoding: 'base64' });
|
||||
await fs.promises.writeFile(filepath, buffer, { encoding: 'base64' });
|
||||
return filepath;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user