mirror of https://gitgud.io/fatchan/jschan.git
parent
c7cd5eebbc
commit
848cc07d9f
6 changed files with 55 additions and 45 deletions
@ -0,0 +1,37 @@ |
||||
'use strict'; |
||||
|
||||
const Mongo = require(__dirname+'/db.js') |
||||
, db = Mongo.client.db('jschan').collection('ratelimit'); |
||||
|
||||
module.exports = { |
||||
|
||||
db, |
||||
|
||||
resetQuota: (ip) => { |
||||
return db.deleteOne({ '_id': ip }); |
||||
}, |
||||
|
||||
incrmentQuota: (ip, amount) => { |
||||
return db.findOneAndUpdate( |
||||
{ |
||||
'_id': ip |
||||
}, |
||||
{ |
||||
'$inc': { |
||||
'sequence_value': amount |
||||
}, |
||||
'$setOnInsert': { |
||||
'expireAt': new Date() |
||||
} |
||||
}, |
||||
{ |
||||
'upsert': true |
||||
} |
||||
).then(r => { return r.value ? r.value.sequence_value : 0 }); |
||||
}, |
||||
|
||||
deleteAll: () => { |
||||
return ratelimit.deleteMany({}); |
||||
}, |
||||
|
||||
} |
Loading…
Reference in new issue