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.
 
 
 
 
 

62 lines
1.1 KiB

'use strict';
const Mongo = require(__dirname+'/db.js')
, db = Mongo.client.db('jschan')
, captcha = db.collection('captcha')
, ratelimit = db.collection('ratelimit')
module.exports = {
captcha,
ratelimit,
findOne: (id) => {
return captcha.findOne({ '_id': id });
},
insertOne: (text) => {
return captcha.insertOne({
'text': text,
'expireAt': new Date()
});
},
findOneAndDelete: (id, text) => {
return captcha.findOneAndDelete({
'_id': id,
'text': text
});
},
resetQuota: (ip) => {
return ratelimit.deleteOne({ '_id': ip });
},
incrmentQuota: (ip) => {
return ratelimit.findOneAndUpdate(
{
'_id': ip
},
{
'$inc': {
'sequence_value': 1
},
'$setOnInsert': {
'expireAt': new Date()
}
},
{
'upsert': true
}
).then(r => { return r.value ? r.value.sequence_value : 0 });
},
deleteAll: () => {
return Promise.all([
captcha.deleteMany({}),
ratelimit.deleteMany({})
]);
},
}