37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
|
/*
|
||
|
* Copyright (C) Sapphirecode - All Rights Reserved
|
||
|
* This file is part of Auth-Server-Helper which is released under MIT.
|
||
|
* See file 'LICENSE' for full license details.
|
||
|
* Created by Timo Hocker <timo@scode.ovh>, August 2022
|
||
|
*/
|
||
|
|
||
|
import { debug } from '../debug';
|
||
|
import { redis } from '../Redis';
|
||
|
|
||
|
const logger = debug ('RedisBlacklistStore');
|
||
|
|
||
|
export class RedisBlacklistStore {
|
||
|
public async add (key: string): Promise<void> {
|
||
|
const log = logger.extend ('set');
|
||
|
log ('trying to add key %s to redis blacklist', key);
|
||
|
if (!redis.is_active) {
|
||
|
log ('redis is inactive, skipping');
|
||
|
return;
|
||
|
}
|
||
|
await redis.redis.sadd ('blacklist', key);
|
||
|
log ('saved key');
|
||
|
}
|
||
|
|
||
|
public async get (key: string): Promise<boolean> {
|
||
|
const log = logger.extend ('get');
|
||
|
log ('trying to find key %s in redis blacklist', key);
|
||
|
if (!redis.is_active) {
|
||
|
log ('redis is inactive, skipping');
|
||
|
return false;
|
||
|
}
|
||
|
const res = await redis.redis.sismember ('blacklist', key) === 1;
|
||
|
log ('found key %s', res);
|
||
|
return res;
|
||
|
}
|
||
|
}
|