refactor: remove util.promisify calls

This commit is contained in:
Barış Soner Uşaklı
2020-08-14 00:05:03 -04:00
parent 45c8de129c
commit 0189945996
18 changed files with 50 additions and 108 deletions

View File

@@ -2,8 +2,6 @@
const path = require('path');
const fs = require('fs');
const util = require('util');
const readFileAsync = util.promisify(fs.readFile);
const file = require('../../file');
@@ -17,7 +15,7 @@ themesController.get = async function (req, res, next) {
let themeConfig;
try {
themeConfig = await readFileAsync(themeConfigPath, 'utf8');
themeConfig = await fs.promises.readFile(themeConfigPath, 'utf8');
themeConfig = JSON.parse(themeConfig);
} catch (err) {
if (err.code === 'ENOENT') {

View File

@@ -4,9 +4,6 @@ const path = require('path');
const nconf = require('nconf');
const mime = require('mime');
const fs = require('fs');
const util = require('util');
const readdirAsync = util.promisify(fs.readdir);
const statAsync = util.promisify(fs.stat);
const meta = require('../../meta');
const posts = require('../../posts');
@@ -27,7 +24,7 @@ uploadsController.get = async function (req, res, next) {
const itemsPerPage = 20;
const page = parseInt(req.query.page, 10) || 1;
try {
let files = await readdirAsync(currentFolder);
let files = await fs.promises.readdir(currentFolder);
files = files.filter(filename => filename !== '.gitignore');
const itemCount = files.length;
var start = Math.max(0, (page - 1) * itemsPerPage);
@@ -91,10 +88,10 @@ async function filesToData(currentDir, files) {
}
async function getFileData(currentDir, file) {
const stat = await statAsync(path.join(currentDir, file));
const stat = await fs.promises.stat(path.join(currentDir, file));
let filesInDir = [];
if (stat.isDirectory()) {
filesInDir = await readdirAsync(path.join(currentDir, file));
filesInDir = await fs.promises.readdir(path.join(currentDir, file));
}
const url = nconf.get('upload_url') + currentDir.replace(nconf.get('upload_path'), '') + '/' + file;
return {