优化captchaSession
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
/**
|
||||
* @file captchaSession.ts
|
||||
* @version 1.0.0
|
||||
* @description 旋转图像验证服务
|
||||
*/
|
||||
import Logger from '../Logger';
|
||||
import RedisConnection from '../RedisConnection';
|
||||
type CaptchaSessionDataJSON = {
|
||||
rotateDeg: number,
|
||||
tryCount: number,
|
||||
isPassed: boolean
|
||||
}
|
||||
|
||||
class _captchaSession {
|
||||
private logger = new Logger('Service][captchaSession');
|
||||
private AllowMaxTryCount: number = 5;
|
||||
private AllowMaxAngleDiff: number = 8;
|
||||
private ExpriedTimeSec: number = 60;
|
||||
private RedisCommonKey: string = 'Service:captchaSession:';
|
||||
private readonly logger = new Logger('Service][captchaSession');
|
||||
private readonly AllowMaxTryCount: number = 5;
|
||||
private readonly AllowMaxAngleDiff: number = 8;
|
||||
private readonly ExpriedTimeSec: number = 60;
|
||||
private readonly RedisCommonKey: string = 'Service:captchaSession:';
|
||||
|
||||
constructor() {
|
||||
this.logger.info('旋转图像验证服务已启动');
|
||||
}
|
||||
|
||||
private async get(session: string) {
|
||||
private async get(session: string): Promise<CaptchaSessionDataJSON | undefined> {
|
||||
try {
|
||||
const result = await RedisConnection.get(this.RedisCommonKey + session);
|
||||
if (result === null)
|
||||
@@ -24,7 +34,7 @@ class _captchaSession {
|
||||
}
|
||||
}
|
||||
|
||||
private async remove(session: string) {
|
||||
private async remove(session: string): Promise<void> {
|
||||
try {
|
||||
await RedisConnection.del(this.RedisCommonKey + session);
|
||||
} catch (error) {
|
||||
@@ -39,7 +49,7 @@ class _captchaSession {
|
||||
* @returns true存储成功 false存储失败
|
||||
*/
|
||||
public async add(session: string, rotateDeg: number): Promise<boolean> {
|
||||
const result = {
|
||||
const result: CaptchaSessionDataJSON = {
|
||||
rotateDeg: rotateDeg,
|
||||
tryCount: 0,
|
||||
isPassed: false
|
||||
|
||||
Reference in New Issue
Block a user