mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: post upload sync duplication bug
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user