Files
Hydro/hydro/model/blacklist.js
T
2020-05-10 13:18:53 +08:00

25 lines
541 B
JavaScript

const db = require('../service/db.js');
const coll = db.collection('blacklist');
async function add(ip) {
const expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
return coll.findOneAndUpdate({ _id: ip }, { $set: { expireAt } }, { upsert: true });
}
function get(ip) {
return coll.findOne({ _id: ip });
}
function del(ip) {
return coll.deleteOne({ _id: ip });
}
function index() {
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
}
module.exports = {
add, get, del, index,
};