jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
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.

76 lines
993 B

'use strict';
const Mongo = require(__dirname+'/db.js')
, db = Mongo.client.db('jschan').collection('poststats');
module.exports = {
updateOne: (board, ip) => {
return db.updateOne({
'board': board,
'hour': new Date().getHours()
}, {
'$inc': {
'pph': 1
},
'$addToSet': {
'ips': ip
}
}, {
'upsert': true
});
},
updateBoards: () => {
return db.aggregate([
{
'$group': {
'_id': '$board',
'ips': {
'$sum': {
'$size': '$ips'
}
},
'pph': {
'$sum': '$pph'
}
}
}, {
'$merge': {
'into': 'boards'
}
}
]).toArray();
},
resetIps: () => {
return db.updateMany({
'hour': new Date().getHours()
}, {
'$set': {
'ips': []
}
});
},
resetPph: () => {
return db.updateMany({}, {
'$set': {
'pph': 0
}
});
},
deleteBoard: (board) => {
return db.deleteMany({
'board': board
});
},
deleteAll: () => {
return db.deleteMany({});
},
}