mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
2 years ago
|
'use strict';
|
||
|
|
||
|
const { Bans } = require(__dirname+'/../../db/')
|
||
|
, dynamicResponse = require(__dirname+'/../misc/dynamic.js');
|
||
|
|
||
|
//ehhh, kinda too many args
|
||
|
module.exports = async (req, res, hitGlobalFilter, boardFilterMode, globalFilterMode,
|
||
|
boardFilterBanDuration, globalFilterBanDuration, filterBanAppealable, redirect) => {
|
||
|
|
||
|
//global filter mode takes prio
|
||
|
const useFilterMode = hitGlobalFilter ? globalFilterMode : boardFilterMode;
|
||
|
|
||
|
if (useFilterMode === 1) {
|
||
|
return dynamicResponse(req, res, 400, 'message', {
|
||
|
'title': 'Bad request',
|
||
|
'message': 'Your post was blocked by a word filter',
|
||
|
'redirect': redirect
|
||
|
});
|
||
|
} else {
|
||
|
const useFilterBanDuration = hitGlobalFilter ? globalFilterBanDuration : boardFilterBanDuration;
|
||
|
const banBoard = hitGlobalFilter ? null : res.locals.board._id;
|
||
|
const banDate = new Date();
|
||
|
const banExpiry = new Date(useFilterBanDuration + banDate.getTime());
|
||
|
const ban = {
|
||
|
'ip': {
|
||
|
'cloak': res.locals.ip.cloak,
|
||
|
'raw': res.locals.ip.raw,
|
||
|
},
|
||
|
'type': res.locals.anonymizer ? 1 : 0,
|
||
|
'range': 0,
|
||
|
'reason': `${hitGlobalFilter ? 'global ' :''}word filter auto ban`,
|
||
|
'board': banBoard,
|
||
|
'posts': null,
|
||
|
'issuer': 'system', //todo: make a "system" property instead?
|
||
|
'date': banDate,
|
||
|
'expireAt': banExpiry,
|
||
|
'allowAppeal': hitGlobalFilter ? filterBanAppealable : true,
|
||
|
'showUser': true,
|
||
|
'seen': false
|
||
|
};
|
||
|
const insertedResult = await Bans.insertOne(ban);
|
||
|
//add and delete some props for the dynamic response
|
||
|
ban._id = insertedResult.insertedId;
|
||
|
ban.ip.raw = null;
|
||
|
return dynamicResponse(req, res, 403, 'ban', {
|
||
|
bans: [ban]
|
||
|
});
|
||
|
}
|
||
|
|
||
|
};
|