|
|
@ -10,13 +10,16 @@ const uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory. |
|
|
|
|
|
|
|
|
|
|
|
module.exports = async (req, res) => { |
|
|
|
module.exports = async (req, res) => { |
|
|
|
|
|
|
|
|
|
|
|
const { threads, postIds } = res.locals.posts.reduce((acc, p) => { |
|
|
|
const { threads, postIds, postMongoIds } = res.locals.posts.reduce((acc, p) => { |
|
|
|
acc.postIds.push(p.postId); |
|
|
|
acc.postIds.push(p.postId); |
|
|
|
|
|
|
|
acc.postMongoIds.push(p._id); |
|
|
|
if (p.thread === null) { |
|
|
|
if (p.thread === null) { |
|
|
|
acc.threads.push(p); |
|
|
|
acc.threads.push(p); |
|
|
|
} |
|
|
|
} |
|
|
|
return acc; |
|
|
|
return acc; |
|
|
|
}, { threads: [], postIds: [] }); |
|
|
|
}, { threads: [], postIds: [], postMongoIds: [] }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(threads, postIds, postMongoIds)
|
|
|
|
|
|
|
|
|
|
|
|
const backlinkRebuilds = new Set(); |
|
|
|
const backlinkRebuilds = new Set(); |
|
|
|
const bulkWrites = []; |
|
|
|
const bulkWrites = []; |
|
|
@ -36,7 +39,7 @@ module.exports = async (req, res) => { |
|
|
|
'updateMany': { |
|
|
|
'updateMany': { |
|
|
|
'filter': { |
|
|
|
'filter': { |
|
|
|
'_id': { |
|
|
|
'_id': { |
|
|
|
'$in': postIds |
|
|
|
'$in': postMongoIds |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
'update': { |
|
|
|
'update': { |
|
|
@ -50,12 +53,14 @@ module.exports = async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
for (let j = 0; j < res.locals.posts.length; j++) { |
|
|
|
for (let j = 0; j < res.locals.posts.length; j++) { |
|
|
|
const post = res.locals.posts[j]; |
|
|
|
const post = res.locals.posts[j]; |
|
|
|
if (post.crossquotes.filter(c => c.thread === req.body.move_to_thread).length > 0) { |
|
|
|
//note: needs debugging
|
|
|
|
|
|
|
|
// if (post.crossquotes.filter(c => c.thread === req.body.move_to_thread).length > 0) {
|
|
|
|
//a crossquote is in the thread we move to, so need to remarkup and add backlinks to those posts
|
|
|
|
//a crossquote is in the thread we move to, so need to remarkup and add backlinks to those posts
|
|
|
|
backlinkRebuilds.add(post._id); |
|
|
|
backlinkRebuilds.add(post._id); |
|
|
|
} |
|
|
|
// }
|
|
|
|
//get backlinks for posts to remarkup
|
|
|
|
//get backlinks for posts to remarkup
|
|
|
|
for (let i = 0; i < post.backlinks.length; i++) { |
|
|
|
for (let i = 0; i < post.backlinks.length; i++) { |
|
|
|
backlinkRebuilds.add(post.backlinks[i]._id); |
|
|
|
backlinkRebuilds.add(post.backlinks[i]._id); |
|
|
@ -82,6 +87,7 @@ module.exports = async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//increase file/reply count in thread we are moving the posts to
|
|
|
|
//increase file/reply count in thread we are moving the posts to
|
|
|
|
const { replyposts, replyfiles } = res.locals.posts.reduce((acc, p) => { |
|
|
|
const { replyposts, replyfiles } = res.locals.posts.reduce((acc, p) => { |
|
|
|
acc.replyposts += 1; |
|
|
|
acc.replyposts += 1; |
|
|
@ -103,7 +109,6 @@ module.exports = async (req, res) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const postMongoIds = res.locals.posts.map(x => x._id); |
|
|
|
|
|
|
|
const movedPosts = await Posts.move(postMongoIds, req.body.move_to_thread).then(result => result.modifiedCount); |
|
|
|
const movedPosts = await Posts.move(postMongoIds, req.body.move_to_thread).then(result => result.modifiedCount); |
|
|
|
|
|
|
|
|
|
|
|
//get posts that quoted moved posts so we can remarkup them
|
|
|
|
//get posts that quoted moved posts so we can remarkup them
|
|
|
@ -113,7 +118,8 @@ module.exports = async (req, res) => { |
|
|
|
if (post.nomarkup && post.nomarkup.length > 0) { |
|
|
|
if (post.nomarkup && post.nomarkup.length > 0) { |
|
|
|
//redo the markup
|
|
|
|
//redo the markup
|
|
|
|
let message = markdown(post.nomarkup); |
|
|
|
let message = markdown(post.nomarkup); |
|
|
|
const { quotedMessage, threadQuotes, crossQuotes } = await linkQuotes(post.board, message, req.body.move_to_thread); |
|
|
|
let { quotedMessage, threadQuotes, crossQuotes } = await linkQuotes(post.board, message, post.thread); // req.body.move_to_thread);
|
|
|
|
|
|
|
|
//console.log(quotedMessage, threadQuotes, crossQuotes)
|
|
|
|
message = sanitize(quotedMessage, sanitizeOptions.after); |
|
|
|
message = sanitize(quotedMessage, sanitizeOptions.after); |
|
|
|
bulkWrites.push({ |
|
|
|
bulkWrites.push({ |
|
|
|
'updateMany': { |
|
|
|
'updateMany': { |
|
|
@ -147,6 +153,15 @@ module.exports = async (req, res) => { |
|
|
|
})); |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(require('util').inspect(bulkWrites, {depth:null}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
- post A quotes B, then A is moved to another thread: WORKS (removes backlink on B) |
|
|
|
|
|
|
|
- moving post A back into thread with B and backlink gets readded: WORKS |
|
|
|
|
|
|
|
- move post B out and backlink from A gets removed: WORKS |
|
|
|
|
|
|
|
- moving post B post back into thread with A and backlinks re-added: FAIL (need to come up with solution, but this is an uncommon occurence) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
//bulkwrite it all
|
|
|
|
//bulkwrite it all
|
|
|
|
if (bulkWrites.length > 0) { |
|
|
|
if (bulkWrites.length > 0) { |
|
|
|
await Posts.db.bulkWrite(bulkWrites); |
|
|
|
await Posts.db.bulkWrite(bulkWrites); |
|
|
|