mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
Hello Typescript!
This commit is contained in:
1 parent
c9b6412527
commit
ba03d7a7bf
98 files changed
+3186
-2616
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import * as db from '../service/db';
|
||||
|
||||
const coll = db.collection('blacklist');
|
||||
|
||||
export async function add(ip: string) {
|
||||
const expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
|
||||
return coll.findOneAndUpdate({ _id: ip }, { $set: { expireAt } }, { upsert: true });
|
||||
}
|
||||
|
||||
export function get(ip: string) {
|
||||
return coll.findOne({ _id: ip });
|
||||
}
|
||||
|
||||
export function del(ip: string) {
|
||||
return coll.deleteOne({ _id: ip });
|
||||
}
|
||||
|
||||
export function ensureIndexes() {
|
||||
return coll.createIndex('expireAt', { expireAfterSeconds: 0 });
|
||||
}
|
||||
|
||||
global.Hydro.model.blacklist = {
|
||||
add, get, del, ensureIndexes,
|
||||
};
|
||||
Reference in new issue
Block a user