- 添加图形验证码生成和验证功能 - 集成Redis存储和过期管理 - 添加验证码清理功能 - 修复Redis服务方法调用 - 更新响应格式Schema定义 - 完善测试用例覆盖 关联任务:集成验证码服务
101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
/**
|
|
* @file 验证码模块Schema定义
|
|
* @author AI助手
|
|
* @date 2024-12-27
|
|
* @description 验证码生成、验证相关的数据结构定义
|
|
*/
|
|
|
|
import { t, type Static } from 'elysia';
|
|
|
|
/**
|
|
* 生成验证码请求Schema
|
|
*/
|
|
export const GenerateCaptchaSchema = t.Object({
|
|
type: t.Optional(t.Union([
|
|
t.Literal('image'),
|
|
t.Literal('sms'),
|
|
t.Literal('email')
|
|
], {
|
|
description: '验证码类型',
|
|
examples: ['image', 'sms', 'email'],
|
|
default: 'image'
|
|
})),
|
|
width: t.Optional(t.Number({
|
|
minimum: 100,
|
|
maximum: 400,
|
|
description: '验证码图片宽度',
|
|
examples: [200],
|
|
default: 200
|
|
})),
|
|
height: t.Optional(t.Number({
|
|
minimum: 40,
|
|
maximum: 100,
|
|
description: '验证码图片高度',
|
|
examples: [60],
|
|
default: 60
|
|
})),
|
|
length: t.Optional(t.Number({
|
|
minimum: 4,
|
|
maximum: 8,
|
|
description: '验证码长度',
|
|
examples: [4],
|
|
default: 4
|
|
})),
|
|
expireTime: t.Optional(t.Number({
|
|
minimum: 60,
|
|
maximum: 1800,
|
|
description: '验证码过期时间(秒)',
|
|
examples: [300],
|
|
default: 300
|
|
}))
|
|
});
|
|
|
|
/**
|
|
* 验证验证码请求Schema
|
|
*/
|
|
export const VerifyCaptchaSchema = t.Object({
|
|
captchaId: t.String({
|
|
minLength: 1,
|
|
description: '验证码ID',
|
|
examples: ['captcha_1234567890']
|
|
}),
|
|
captchaCode: t.String({
|
|
minLength: 4,
|
|
maxLength: 8,
|
|
description: '用户输入的验证码',
|
|
examples: ['1234']
|
|
}),
|
|
scene: t.Optional(t.String({
|
|
description: '验证场景',
|
|
examples: ['login', 'register', 'reset_password']
|
|
}))
|
|
});
|
|
|
|
/**
|
|
* 验证码数据Schema
|
|
*/
|
|
export const CaptchaDataSchema = t.Object({
|
|
id: t.String({ description: '验证码ID' }),
|
|
code: t.String({ description: '验证码内容' }),
|
|
type: t.String({ description: '验证码类型' }),
|
|
image: t.Optional(t.String({ description: 'Base64图片数据' })),
|
|
expireTime: t.Number({ description: '过期时间戳' }),
|
|
scene: t.Optional(t.String({ description: '验证场景' })),
|
|
createdAt: t.Number({ description: '创建时间戳' })
|
|
});
|
|
|
|
/**
|
|
* 验证码生成响应Schema
|
|
*/
|
|
export const CaptchaGenerateResponseSchema = t.Object({
|
|
id: t.String({ description: '验证码ID' }),
|
|
image: t.String({ description: 'Base64编码的验证码图片' }),
|
|
expireTime: t.Number({ description: '过期时间戳' }),
|
|
type: t.String({ description: '验证码类型' })
|
|
});
|
|
|
|
// 导出TypeScript类型
|
|
export type GenerateCaptchaRequest = Static<typeof GenerateCaptchaSchema>;
|
|
export type VerifyCaptchaRequest = Static<typeof VerifyCaptchaSchema>;
|
|
export type CaptchaData = Static<typeof CaptchaDataSchema>;
|
|
export type CaptchaGenerateResponse = Static<typeof CaptchaGenerateResponseSchema>;
|