@ -52,7 +52,7 @@ module.exports = async (req, res, next) => {
const { filters , filterBanDuration , filterMode ,
const { filters , filterBanDuration , filterMode ,
maxFiles , forceAnon , replyLimit ,
maxFiles , forceAnon , replyLimit ,
threadLimit , ids , userPostSpoiler ,
threadLimit , ids , userPostSpoiler ,
defaultName , t phTrigger, tphTriggerAction ,
defaultName , p phTrigger, tphTrigger , t riggerAction ,
captchaMode , locked , allowedFileTypes , flags } = res . locals . board . settings ;
captchaMode , locked , allowedFileTypes , flags } = res . locals . board . settings ;
if ( locked === true ) {
if ( locked === true ) {
await deleteTempFiles ( req ) . catch ( e => console . error ) ;
await deleteTempFiles ( req ) . catch ( e => console . error ) ;
@ -366,25 +366,24 @@ module.exports = async (req, res, next) => {
const postId = await Posts . insertOne ( res . locals . board , data , thread ) ;
const postId = await Posts . insertOne ( res . locals . board , data , thread ) ;
let enableCaptcha = false ;
let enableCaptcha = false ;
if ( ! data . thread //if this is a new threa d
if ( triggerAction > 0 //trigger is enable d
&& tphTriggerAction > 0 //and the triger mode is not nothing
&& ( tphTrigger > 0 || pphTrigger > 0 ) //and we have a trigger > 0 for threads or posts
&& ( ( tphT riggerAction < 3 && captchaMode < tphT riggerAction ) //and captcha mode less than captcha trigger
&& ( ( triggerAction < 3 && captchaMode < triggerAction ) //and captcha mode less than trigger if trigger < 2
|| ( tphT riggerAction === 3 && locked !== true ) ) ) { //and not locked with lock trigger
|| ( triggerAction === 3 && locked !== true ) ) ) { //or trigger is to lock and board not locked
const pastHourMongoId = Mongo . ObjectId . createFromTime ( Math . floor ( ( Date . now ( ) - msTime . hour ) / 1000 ) ) ;
const pastHourMongoId = Mongo . ObjectId . createFromTime ( Math . floor ( ( Date . now ( ) - msTime . hour ) / 1000 ) ) ;
//count threads in past hour
//count threads in past hour
const hourPosts = await Stats . getHourPosts ( res . locals . board . _id ) ;
const hourPosts = await Stats . getHourPosts ( res . locals . board . _id ) ;
//if its above the trigger
//if its above the trigger
if ( hourPosts && hourPosts . tph && hourPosts . tph >= tphTrigger ) { //TODO: add an option to check pph OR tph, not just tph
if ( hourPosts && ( hourPosts . tph >= tphTrigger || hourPosts . pph > pphTrigger ) ) { //TODO: add an option to check pph OR tph, not just tph
//update in memory for other stuff done e.g. rebuilds
//update in memory for other stuff done e.g. rebuilds
const update = {
const update = {
'$set' : { }
'$set' : { }
} ;
} ;
if ( tphT riggerAction < 3 ) {
if ( triggerAction < 3 ) {
res . locals . board . settings . captchaMode = tphT riggerAction ;
res . locals . board . settings . captchaMode = triggerAction ;
update [ '$set' ] [ 'settings.captchaMode' ] = tphT riggerAction ;
update [ '$set' ] [ 'settings.captchaMode' ] = triggerAction ;
enableCaptcha = true ;
enableCaptcha = true ;
}
} else if ( triggerAction === 3 ) {
if ( tphTriggerAction === 3 ) {
res . locals . board . settings . locked = true ;
res . locals . board . settings . locked = true ;
update [ '$set' ] [ 'settings.locked' ] = true ;
update [ '$set' ] [ 'settings.locked' ] = true ;
}
}