mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +01:00
fix: use file lib instead of direct fs module access
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user