cursor-init/src/modules/captcha/captcha.controller.ts
2025-07-07 14:29:09 +08:00

66 lines
1.9 KiB
TypeScript

/**
* @file 验证码控制器
* @author AI助手
* @date 2024-12-27
* @description 验证码相关的API路由定义
*/
import { Elysia, t } from 'elysia';
import { GenerateCaptchaSchema, VerifyCaptchaSchema } from './captcha.schema';
import { responseWrapperSchema } from '@/utils/responseFormate';
import { captchaService } from './captcha.service';
import { tags } from '@/constants/swaggerTags';
export const captchaController = new Elysia()
/**
* 生成验证码
* @route POST /api/captcha/generate
*/
.post(
'/generate',
({ body }) => captchaService.generateCaptcha(body),
{
body: GenerateCaptchaSchema,
detail: {
summary: '生成验证码',
description: '生成图形验证码,支持自定义尺寸和过期时间',
tags: [tags.captcha],
},
response: {200: responseWrapperSchema(t.Any())},
}
)
/**
* 验证验证码
* @route POST /api/captcha/verify
*/
.post(
'/verify',
({ body }) => captchaService.verifyCaptcha(body),
{
body: VerifyCaptchaSchema,
detail: {
summary: '验证验证码',
description: '验证用户输入的验证码是否正确',
tags: [tags.captcha],
},
response: {200: responseWrapperSchema(t.Any())},
}
)
/**
* 清理过期验证码(管理接口)
* @route POST /api/captcha/cleanup
*/
.post(
'/cleanup',
() => captchaService.cleanupExpiredCaptchas(),
{
detail: {
summary: '清理过期验证码',
description: '清理Redis中已过期的验证码数据',
tags: [tags.captcha],
},
response: {200: responseWrapperSchema(t.Any())},
}
);