You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
620 B
TypeScript
25 lines
620 B
TypeScript
4 years ago
|
import * as db from '../service/db';
|
||
5 years ago
|
|
||
|
const coll = db.collection('blacklist');
|
||
5 years ago
|
|
||
4 years ago
|
export async function add(ip: string) {
|
||
5 years ago
|
const expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
|
||
5 years ago
|
return coll.findOneAndUpdate({ _id: ip }, { $set: { expireAt } }, { upsert: true });
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
export function get(ip: string) {
|
||
5 years ago
|
return coll.findOne({ _id: ip });
|
||
|
}
|
||
5 years ago
|
|
||
4 years ago
|
export function del(ip: string) {
|
||
5 years ago
|
return coll.deleteOne({ _id: ip });
|
||
|
}
|
||
|
|
||
4 years ago
|
export function ensureIndexes() {
|
||
5 years ago
|
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
|
||
|
}
|
||
|
|
||
4 years ago
|
global.Hydro.model.blacklist = {
|
||
4 years ago
|
add, get, del, ensureIndexes,
|
||
5 years ago
|
};
|