fix: use file lib instead of direct fs module access

v1.18.x
Julian Lam 4 years ago
parent c043cfebd6
commit 08736b1812

@ -3,13 +3,13 @@
const async = require('async'); const async = require('async');
const nconf = require('nconf'); const nconf = require('nconf');
const crypto = require('crypto'); const crypto = require('crypto');
const fs = require('fs');
const path = require('path'); const path = require('path');
const winston = require('winston'); const winston = require('winston');
const mime = require('mime'); const mime = require('mime');
const db = require('../database'); const db = require('../database');
const image = require('../image'); const image = require('../image');
const file = require('../file');
module.exports = function (Posts) { module.exports = function (Posts) {
Posts.uploads = {}; Posts.uploads = {};
@ -78,12 +78,8 @@ module.exports = function (Posts) {
if (!filePaths.length) { if (!filePaths.length) {
return; return;
} }
filePaths = await async.filter(filePaths, function (filePath, next) { // Only process files that exist
// Only process files that exist filePaths = await async.filter(filePaths, async filePath => await file.exists(path.join(pathPrefix, filePath)));
fs.access(path.join(pathPrefix, filePath), fs.constants.F_OK | fs.constants.R_OK, function (err) {
next(null, !err);
});
});
const now = Date.now(); const now = Date.now();
const scores = filePaths.map(() => now); const scores = filePaths.map(() => now);

Loading…
Cancel
Save