From a517a3659cf836c69c54cf4094c13cc4e4674ce3 Mon Sep 17 00:00:00 2001 From: fatchan Date: Tue, 2 Jun 2020 16:59:34 +1000 Subject: [PATCH] Bugfix & improve bans from filter to remove unnecessary queyr, use insertedId from insertOne instead of fetching again --- models/forms/editpost.js | 7 ++++--- models/forms/makepost.js | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/models/forms/editpost.js b/models/forms/editpost.js index 64937032..443f888e 100644 --- a/models/forms/editpost.js +++ b/models/forms/editpost.js @@ -52,6 +52,7 @@ todo: handle some more situations 'single': res.locals.ip.single, 'raw': res.locals.ip.raw, }, + 'subnet': '/32', 'reason': 'global word filter auto ban', 'board': null, 'posts': null, @@ -61,10 +62,10 @@ todo: handle some more situations 'allowAppeal': true, //should i make this configurable if appealable? 'seen': false }; - await Bans.insertOne(ban); - const bans = await Bans.find(res.locals.ip.single, banBoard); //need to query db so it has _id field for appeal checkmark + const insertedResult = await Bans.insertOne(ban); + ban._id = insertedResult.insertedId; return res.status(403).render('ban', { - bans: bans + bans: [ban] }); } } diff --git a/models/forms/makepost.js b/models/forms/makepost.js index b192b688..bf46c34d 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -135,8 +135,9 @@ module.exports = async (req, res, next) => { const ban = { 'ip': { 'single': res.locals.ip.single, - 'raw': res.local.ip.raw, + 'raw': res.locals.ip.raw, }, + 'subnet': '/32', 'reason': `${hitGlobalFilter ? 'global ' :''}word filter auto ban`, 'board': banBoard, 'posts': null, @@ -146,10 +147,10 @@ module.exports = async (req, res, next) => { 'allowAppeal': true, //should i make this configurable if appealable? 'seen': false }; - await Bans.insertOne(ban); - const bans = await Bans.find(res.locals.ip.single, banBoard); //need to query db so it has _id field for appeal checkmark + const insertedResult = await Bans.insertOne(ban); + ban._id = insertedResult.insertedId; return res.status(403).render('ban', { - bans: bans + bans: [ban] }); } }