@ -253,121 +253,7 @@ module.exports = {
News . find ( maxRecentNews ) , //some recent newsposts
Posts . db . find ( { 'board' : { $in : listedBoards } , 'thread' : null , 'date' : { $gte : ( new Date ( Date . now ( ) - ( 7 * 24 * 60 * 60 * 1000 ) ) ) } } ) . sort ( { 'replyposts' : - 1 } ) . limit ( 5 ) . toArray ( ) , //top 5 threads last 7 days
] ) ;
const [ localStats , webringStats ] = totalStats ;
const { html } = await render ( 'index.html' , 'home.pug' , {
localStats ,
webringStats ,
boards ,
fileStats ,
recentNews ,
hotThreads ,
} ) ;
const end = process . hrtime ( start ) ;
debugLogs && console . log ( timeDiffString ( label , end ) ) ;
return html ;
} ,
updateStats : async ( ) => {
const label = 'Hourly stats rollover' ;
const start = process . hrtime ( ) ;
await Stats . updateBoards ( ) ;
await Stats . resetStats ( ) ;
buildQueue . push ( {
'task' : 'buildHomepage' ,
} ) ;
const end = process . hrtime ( start ) ;
debugLogs && console . log ( timeDiffString ( label , end ) ) ;
module . exports . resetTriggers ( ) ;
} ,
resetTriggers : async ( ) => {
const label = 'Resetting pph/tph triggers' ;
const start = process . hrtime ( ) ;
const triggeredBoards = await cache . sgetall ( 'triggered' ) ; //boards triggered pph/tph mode
if ( triggeredBoards . length === 0 ) {
return ; //no label is no triggers
}
await cache . del ( 'triggered' ) ;
const triggerModes = await Boards . triggerModes ( triggeredBoards ) ;
const bulkWrites = triggerModes . map ( p => {
return {
'updateOne' : {
'filter' : {
'_id' : p . _id
} ,
'update' : {
'$set' : {
/ * r e s e t = 0 i s " n o c h a n g e " , t h e o p t i o n s g o f r o m 0 - 2 , a n d g e t r e s e t t o 0 o r 1 ,
so if > 0 , we subtract 1 otherwise no change * /
'settings.lockMode' : ( p . lockReset > 0 ? Math . min ( p . lockReset - 1 , p . lockMode ) : p . lockMode ) ,
'settings.captchaMode' : ( p . captchaReset > 0 ? Math . min ( p . captchaReset - 1 , p . captchaMode ) : p . captchaMode ) ,
}
}
}
}
} ) ;
await Boards . db . bulkWrite ( bulkWrites ) ;
const promises = [ ] ;
triggerModes . forEach ( async ( p ) => {
await cache . del ( ` board: ${ p . _id } ` ) ;
if ( p . captchaReset > 0 && p . captchaReset - 1 < p . captchaMode ) {
if ( p . captchaReset - 1 <= 1 ) {
promises . push ( remove ( ` ${ uploadDirectory } /html/ ${ p . _id } /thread/ ` ) ) ;
}
if ( p . captchaReset - 1 === 0 ) {
buildQueue . push ( {
'task' : 'buildBoardMultiple' ,
'options' : {
'board' : p . _id ,
'startpage' : 1 ,
'endpage' : Math . ceil ( p . threadLimit / 10 )
}
} )
buildQueue . push ( {
'task' : 'buildCatalog' ,
'options' : {
'board' : p . _id
}
} ) ;
}
}
} )
await Promise . all ( promises ) ;
const end = process . hrtime ( start ) ;
debugLogs && console . log ( timeDiffString ( label , end ) ) ;
} ,
buildChangePassword : async ( ) => {
const { html } = await render ( 'changepassword.html' , 'changepassword.pug' ) ;
return html ;
} ,
buildRegister : async ( ) => {
const { html } = await render ( 'register.html' , 'register.pug' ) ;
return html ;
} ,
buildBypass : async ( minimal = false ) => {
const { html } = await render ( ` bypass ${ minimal ? '_minimal' : '' } .html ` , 'bypass.pug' , {
minimal ,
} ) ;
return html ;
} ,
buildCreate : async ( ) => {
const { html } = await render ( 'create.html' , 'create.pug' ) ;
return html ;
} ,
buildCaptcha : async ( ) => {
const { html } = await render ( 'captcha.html' , 'captcha.pug' ) ;
return html ;
} ,
}
] ) ;
const [ localStats , webringStats ] = totalStats ;
const [ localStats , webringStats , hotThreads ] = totalStats ;
const { html } = await render ( 'index.html' , 'home.pug' , {
localStats ,
webringStats ,