fix: post upload sync duplication bug

This commit is contained in:
Julian Lam
2025-01-08 12:06:56 -05:00
parent 7c1b900062
commit cfeb49ddd9

View File

@@ -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));