mirror of https://gitgud.io/fatchan/jschan.git
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.
39 lines
735 B
39 lines
735 B
'use strict';
|
|
|
|
const Mongo = require(__dirname+'/db.js')
|
|
, config = require(__dirname+'/../lib/misc/config.js')
|
|
, db = Mongo.db.collection('bypass');
|
|
|
|
module.exports = {
|
|
|
|
db,
|
|
|
|
checkBypass: (id, anonymizer=false) => {
|
|
const { blockBypass } = config.get;
|
|
return db.findOneAndUpdate({
|
|
'_id': id,
|
|
'anonymizer': anonymizer,
|
|
'uses': {
|
|
'$lte': blockBypass.expireAfterUses
|
|
}
|
|
}, {
|
|
'$inc': {
|
|
'uses': 1,
|
|
}
|
|
}).then(r => r.value);
|
|
},
|
|
|
|
getBypass: (anonymizer=false) => {
|
|
const { blockBypass } = config.get;
|
|
return db.insertOne({
|
|
'uses': 0,
|
|
'anonymizer': anonymizer,
|
|
'expireAt': new Date(Date.now() + blockBypass.expireAfterTime)
|
|
});
|
|
},
|
|
|
|
deleteAll: () => {
|
|
return db.deleteMany({});
|
|
},
|
|
|
|
};
|
|
|