diff --git a/db/posts.js b/db/posts.js index ff912bff..805462a2 100644 --- a/db/posts.js +++ b/db/posts.js @@ -260,7 +260,6 @@ module.exports = { }, insertOne: async (board, data, thread) => { -console.log(thread) if (data.thread !== null && data.email !== 'sage' && !thread.saged) { const filter = { 'postId': data.thread, @@ -286,9 +285,6 @@ console.log(thread) const postId = await Boards.getNextId(board); data.postId = postId; await db.insertOne(data); - if (!data.thread) { //if we just added a new thread, prune anyold ones - await module.exports.pruneOldThreads(board); - } return postId; }, @@ -328,7 +324,7 @@ console.log(thread) return db.deleteOne(options); }, - pruneOldThreads: async (board) => { + pruneOldThreads: async (board, threadLimit) => { //get lowest bumped threads const threads = await db.find({ 'thread': null, @@ -336,7 +332,7 @@ console.log(thread) }).sort({ 'sticky': -1, 'bumped': -1 - }).skip(100).toArray(); //100 therads in board limit for now + }).skip(threadLimit).toArray(); //100 therads in board limit for now //if there are any if (threads.length > 0) { //get the postIds diff --git a/models/forms/make-post.js b/models/forms/make-post.js index 983b5656..f3263ed9 100644 --- a/models/forms/make-post.js +++ b/models/forms/make-post.js @@ -59,7 +59,7 @@ module.exports = async (req, res, next, numFiles) => { 'redirect': redirect }); } - if (thread.replyposts >= 100) { //reply limit + if (thread.replyposts >= res.locals.board.settings.replyLimit) { //reply limit return res.status(400).render('message', { 'title': 'Bad request', 'message': 'Thread reached reply limit', @@ -71,7 +71,7 @@ module.exports = async (req, res, next, numFiles) => { // if we got a file if (numFiles > 0) { // check all mime types befoer we try saving anything - for (let i = 0; i < numFiles; i++) { + for (let i = 0; i < res.locals.board.settings.maxImages; i++) { if (!fileCheckMimeType(req.files.file[i].mimetype, {image: true, video: true})) { return res.status(400).render('message', { 'title': 'Bad request', @@ -161,12 +161,12 @@ module.exports = async (req, res, next, numFiles) => { userId = fullUserIdHash.substring(fullUserIdHash.length-6); } - //forceanon hide reply subjects so cant be used as name - let subject = hasPerms || !forceAnon ? req.body.subject : null; + //forceanon hide reply subjects so cant be used as name for replies + let subject = hasPerms || !forceAnon || !req.body.thread ? req.body.subject : null; //forceanon only allow sage email let email = hasPerms || !forceAnon || req.body.email === 'sage' ? req.body.email : null; - let name = 'Anonymous'; + let name = res.locals.board.settins.defaultName; let tripcode = null; let capcode = null; if ((hasPerms || !forceAnon) && req.body.name && req.body.name.length > 0) { @@ -233,7 +233,10 @@ module.exports = async (req, res, next, numFiles) => { let postId; try { - postId = await Posts.insertOne(req.params.board, data, thread); + postId = await Posts.insertOne(res.locals.board, data, thread); + if (!data.thread) { //if we just added a new thread, prune anyold ones + await module.exports.pruneOldThreads(req.params.board, res.locals.board.settings.threadLimit); + } } catch (err) { return next(err); } diff --git a/views/includes/postform.pug b/views/includes/postform.pug index 63efe0a5..0eb440ea 100644 --- a/views/includes/postform.pug +++ b/views/includes/postform.pug @@ -2,7 +2,7 @@ section.form-wrapper form.form-post(action=`/forms/board/${board._id}/post`, enctype='multipart/form-data', method='POST') input(type='hidden' name='_csrf' value=csrf) input(type='hidden' name='thread' value=thread != null ? thread.postId : null) - if !board.settings.forceAnon + unless board.settings.forceAnon section.postform-row .postform-label Name input#name(type='text', name='name', placeholder='Anonymous' autocomplete='off' maxlength='50') @@ -12,12 +12,16 @@ section.form-wrapper section.postform-row .postform-label Email input#name(type='text', name='email', autocomplete='off' maxlength='50') - else + else section.postform-row .postform-label Sage label.postform-style.ph-5 input#spoiler(type='checkbox', name='email', value='sage') | Sage + if thread + section.postform-row + .postform-label Subject + input#title(type='text', name='subject', autocomplete='off' maxlength='50') section.postform-row .postform-label Message textarea#message(name='message', rows='5', autocomplete='off' maxlength='2000') diff --git a/views/pages/globalmanage.pug b/views/pages/globalmanage.pug index a40d24d8..faedc003 100644 --- a/views/pages/globalmanage.pug +++ b/views/pages/globalmanage.pug @@ -7,7 +7,6 @@ block head block content h1.board-title Global Management - p: a(href='/changepassword') Change password h4 All Reports: form(action=`/forms/global/actions` method='POST' enctype='application/x-www-form-urlencoded') input(type='hidden' name='_csrf' value=csrf) diff --git a/views/pages/manage.pug b/views/pages/manage.pug index c4547009..830be786 100644 --- a/views/pages/manage.pug +++ b/views/pages/manage.pug @@ -7,8 +7,35 @@ block head block content include ../includes/boardheader.pug + h4 Settings: + section.form-wrapper + form.form-post(action=`/forms/board/${board._id}/settings` method='POST' enctype='application/x-www-form-urlencoded') + input(type='hidden' name='_csrf' value=csrf) + section.postform-row + .postform-label IDs + label.postform-style.ph-5 + input(type='checkbox', name='ids', value='true' checked=board.settings.ids) + | Show per-thread IDs + section.postform-row + .postform-label Force Anon + label.postform-style.ph-5 + input(type='checkbox', name='force_anon', value='true' checked=board.settings.forceAnon) + | Disable names and only allow sage email + section.postform-row + .postform-label Anon Name + input(type='text' name='default_name' placeholder=board.settings.defaultName) + section.postform-row + .postform-label Thread Limit + input(type='text' name='thread_limit' placeholder=board.settings.threadLimit) + section.postform-row + .postform-label Reply Limit + input(type='text' name='reply_limit' placeholder=board.settings.replyLimit) + section.postform-row + .postform-label Max Images + input(type='text' name='max_images' placeholder=board.settings.maxImages) + input(type='submit', value='save settings') + h4 Banners: include ../includes/bannerform.pug - p: a(href='/changepassword') Change password h4 Reports: form(action=`/forms/board/${board._id}/modactions` method='POST' enctype='application/x-www-form-urlencoded') input(type='hidden' name='_csrf' value=csrf) diff --git a/wipe.js b/wipe.js index 00cdf194..fb757606 100644 --- a/wipe.js +++ b/wipe.js @@ -42,6 +42,10 @@ const Mongo = require(__dirname+'/db/db.js') settings: { forceAnon: true, ids: true, + threadLimit: 100, + replyLimit: 300, + maxImages: 3, + defaultName: 'Anonymous', } }) await Boards.insertOne({ @@ -54,6 +58,10 @@ const Mongo = require(__dirname+'/db/db.js') settings: { forceAnon: false, ids: false, + threadLimit: 100, + replyLimit: 300, + maxImages: 3, + defaultNAme: 'Anonymous', } }) console.log('creating indexes')