Node.js based forum software built for the modern web
return early if there are no files
Barış Soner Uşaklıcba5aa975ea2
diff --git a/src/posts/uploads.js b/src/posts/uploads.jsindex 70fd46791f..8af6dd10c9 100644--- a/src/posts/uploads.js+++ b/src/posts/uploads.js@@ -74,7 +74,9 @@ module.exports = function (Posts) {Posts.uploads.associate = function (pid, filePaths, callback) {// Adds an upload to a post's sorted set of uploadsfilePaths = !Array.isArray(filePaths) ? [filePaths] : filePaths;-+ if (!filePaths.length) {+ return setImmediate(callback);+ }async.filter(filePaths, function (filePath, next) {// Only process files that existfs.access(path.join(pathPrefix, filePath), fs.constants.F_OK | fs.constants.R_OK, function (err) {@@ -99,6 +101,9 @@ module.exports = function (Posts) {Posts.uploads.dissociate = function (pid, filePaths, callback) {// Removes an upload from a post's sorted set of uploadsfilePaths = !Array.isArray(filePaths) ? [filePaths] : filePaths;+ if (!filePaths.length) {+ return setImmediate(callback);+ }let methods = [async.apply(db.sortedSetRemove.bind(db), 'post:' + pid + ':uploads', filePaths)];methods = methods.concat(filePaths.map(path => async.apply(db.sortedSetRemove.bind(db), 'upload:' + md5(path) + ':pids', pid)));