core: security: blacklist: allow no_expire

This commit is contained in:
undefined committed 2021-04-21 13:14:15 +08:00
1 parent 9b3ea0182b
commit 61597151a8
2 files changed
+10 -5

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.23.11",
"version": "2.23.12",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+9 -4
View File
@@ -1,3 +1,4 @@
import moment from 'moment';
import { ArgMethod } from '../utils';
import db from '../service/db';
import * as bus from '../service/bus';
@@ -6,8 +7,12 @@ const coll = db.collection('blacklist');
class BlackListModel {
@ArgMethod
static async add(id: string) {
const expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
static async add(id: string, expire?: Date | number) {
let expireAt;
if (expire === 0) expireAt = moment().add(1000, 'years').toDate();
if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate();
else if (expire instanceof Date) expireAt = expire;
else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
const res = await coll.findOneAndUpdate(
{ _id: id },
{ $set: { expireAt } },
@@ -22,8 +27,8 @@ class BlackListModel {
}
@ArgMethod
static async del(ip: string) {
return await coll.deleteOne({ _id: ip });
static async del(id: string) {
return await coll.deleteOne({ _id: id });
}
}