diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 14c6add92..c913af3c3 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -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", diff --git a/packages/hydrooj/src/model/blacklist.ts b/packages/hydrooj/src/model/blacklist.ts index fe368869d..8ae2461c7 100644 --- a/packages/hydrooj/src/model/blacklist.ts +++ b/packages/hydrooj/src/model/blacklist.ts @@ -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 }); } }