diff --git a/models/forms/changeboardsettings.js b/models/forms/changeboardsettings.js index 9316c953..c648a03a 100644 --- a/models/forms/changeboardsettings.js +++ b/models/forms/changeboardsettings.js @@ -89,6 +89,22 @@ module.exports = async (req, res, next) => { //array of promises we might need const promises = []; + let captchaEnabled = false; + if (newSettings.captchaMode > oldSettings.captchaMode) { + captchaEnabled = true; + if (newSettings.captchaMode == 2) { + promises.push(remove(`${uploadDirectory}html/${req.params.board}/thread/`)); + } + buildQueue.push({ + 'task': 'buildBoardMultiple', + 'options': { + 'board': res.locals.board, + 'startpage': 1, + 'endpage': newMaxPage + } + }); + } + //do rebuilding and pruning if max number of pages is changed and any threads are pruned const oldMaxPage = Math.ceil(oldSettings.threadLimit/10); const newMaxPage = Math.ceil(newSettings.threadLimit/10); @@ -102,14 +118,16 @@ module.exports = async (req, res, next) => { promises.push(remove(`${uploadDirectory}html/${req.params.board}/${i}.html`)); } //rebuild all board pages for page nav numbers, and catalog - buildQueue.push({ - 'task': 'buildBoardMultiple', - 'options': { - 'board': res.locals.board, - 'startpage': 1, - 'endpage': newMaxPage - } - }); + if (!captchaEnabled) { + buildQueue.push({ + 'task': 'buildBoardMultiple', + 'options': { + 'board': res.locals.board, + 'startpage': 1, + 'endpage': newMaxPage + } + }); + } buildQueue.push({ 'task': 'buildCatalog', 'options': { @@ -119,11 +137,6 @@ module.exports = async (req, res, next) => { } } - if (newSettings.captchaMode !== oldSettings.captchaMode) { - promises.push(remove(`${uploadDirectory}html/${req.params.board}/`)); -//TODO: dont remove all pages, only remove some and add important pages to build queue here - } - if (promises.length > 0) { await Promise.all(promises); } diff --git a/models/forms/makepost.js b/models/forms/makepost.js index 98aaccbe..9065d576 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -348,6 +348,7 @@ module.exports = async (req, res, next) => { const postId = await Posts.insertOne(res.locals.board, data, thread); + let enableCaptcha = false; if (!data.thread //if this is a new thread && tphTriggerAction > 0 //and the triger mode is not nothing && ((tphTriggerAction < 3 && captchaMode < tphTriggerAction) //and captcha mode less than captcha trigger @@ -379,8 +380,7 @@ module.exports = async (req, res, next) => { await Boards.db.updateOne({ '_id': res.locals.board._id, }, update); - //remove the html (since pages will need captcha in postform now) - await remove(`${uploadDirectory}html/${req.params.board}/`); + enableCaptcha = true; } } @@ -405,7 +405,20 @@ module.exports = async (req, res, next) => { res.redirect(successRedirect); //now add other pages to be built in background - if (data.thread) { + if (captchaEnabled) { + if (res.locals.board.settings.captchaMode == 2) { + //only delete threads if all posts require threads, otherwise just build board pages for thread captcha + await remove(`${uploadDirectory}html/${req.params.board}/thread/`); + } + buildQueue.push({ + 'task': 'buildBoardMultiple', + 'options': { + 'board': res.locals.board, + 'startpage': 1, + 'endpage': Math.ceil(threadLimit/10) + } + }); + } else if (data.thread) { //refersh pages const threadPage = await Posts.getThreadPage(req.params.board, thread); if (data.email === 'sage' || thread.sage) { @@ -428,20 +441,22 @@ module.exports = async (req, res, next) => { } }); } - } else { + } else if (!data.thread) { //new thread, prunes any old threads before rebuilds const prunedThreads = await Posts.pruneThreads(res.locals.board); if (prunedThreads.length > 0) { await deletePosts(prunedThreads, req.params.board); - } - buildQueue.push({ - 'task': 'buildBoardMultiple', - 'options': { - 'board': res.locals.board, - 'startpage': 1, - 'endpage': Math.ceil(threadLimit/10) + if (!captchaEnabled) { + buildQueue.push({ + 'task': 'buildBoardMultiple', + 'options': { + 'board': res.locals.board, + 'startpage': 1, + 'endpage': Math.ceil(threadLimit/10) + } + }); } - }); + } } //always rebuild catalog for post counts and ordering