Skip to content

Node.js based forum software built for the modern web

fix: post upload sync duplication bug

Julian Lamcfeb49ddd968
diff --git a/src/posts/uploads.js b/src/posts/uploads.js
index 12564d0f17..5f97be9563 100644
--- a/src/posts/uploads.js
+++ b/src/posts/uploads.js
@@ -54,23 +54,25 @@ module.exports = function (Posts) {
// Extract upload file paths from post content
let match = searchRegex.exec(content);
- const uploads = [];
+ let uploads = new Set();
while (match) {
- uploads.push(match[1].replace('-resized', ''));
+ uploads.add(match[1].replace('-resized', ''));
match = searchRegex.exec(content);
}
// Main posts can contain topic thumbs, which are also tracked by pid
if (isMainPost) {
const tid = await Posts.getPostField(pid, 'tid');
- let thumbs = await topics.thumbs.get(tid);
+ let thumbs = await topics.thumbs.get(tid, { thumbsOnly: true });
thumbs = thumbs.map(thumb => thumb.path).filter(path => !validator.isURL(path, {
require_protocol: true,
}));
thumbs = thumbs.map(t => t.slice(1)); // remove leading `/` or `\\` on windows
- uploads.push(...thumbs);
+ thumbs.forEach(t => uploads.add(t));
}
+ uploads = Array.from(uploads);
+
// Create add/remove sets
const add = uploads.filter(path => !currentUploads.includes(path));
const remove = currentUploads.filter(path => !uploads.includes(path));